Skip to content

Serverless runtimes executor for container based environments ⚡️

License

Notifications You must be signed in to change notification settings

open-runtimes/executor

 
 

Repository files navigation

Open Runtimes Executor 🤖

open-runtimes-box-bg-cover


Discord Build Status Twitter Account Docker Pulls

Executor for Open Runtimes, a runtime environments for serverless cloud computing for multiple coding languages.

Executor is responsible for providing HTTP API for creating and executing Open Runtimes. Executor is stateless and can be scaled horizontally when a load balancer is introduced in front of it. You could use any load balancer but we highly recommend using Open Runtimes Proxy for it's ease of setup with Open Runtimes Executor.

Features

  • Flexibility - Configuring custom image lets you use any runtime for your functions.
  • Performance - Coroutine-style HTTP servers allows asynchronous operations without blocking. We. Run. Fast! ⚡
  • Open Source - Released under the MIT license, free to use and extend.

Getting Started

  1. Pull Open Runtimes Executor image:
docker pull openruntimes/executor
  1. Create docker-compose.yml file:
version: '3'
services:
  openruntimes-executor:
    container_name: openruntimes-executor
    hostname: executor
    stop_signal: SIGINT
    image: openruntimes/executor
    networks:
      openruntimes-runtimes:
    ports:
      - 9900:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - openruntimes-builds:/storage/builds:rw
      - openruntimes-functions:/storage/functions:rw
      - /tmp:/tmp:rw
      - ./functions:/storage/functions:rw
    environment:
      - OPR_EXECUTOR_ENV
      - OPR_EXECUTOR_RUNTIMES
      - OPR_EXECUTOR_CONNECTION_STORAGE
      - OPR_EXECUTOR_INACTIVE_TRESHOLD
      - OPR_EXECUTOR_MAINTENANCE_INTERVAL
      - OPR_EXECUTOR_NETWORK
      - OPR_EXECUTOR_SECRET
      - OPR_EXECUTOR_LOGGING_PROVIDER
      - OPR_EXECUTOR_LOGGING_CONFIG
      - OPR_EXECUTOR_DOCKER_HUB_USERNAME
      - OPR_EXECUTOR_DOCKER_HUB_PASSWORD
      - OPR_EXECUTOR_RUNTIME_VERSIONS

networks:
  openruntimes-runtimes:
    name: openruntimes-runtimes

volumes:
  openruntimes-builds:
  openruntimes-functions:

Notice we added bind to local ./functions directory. That is only nessessary for this getting started, since we will be executing our custom function.

  1. Create .env file:
OPR_EXECUTOR_ENV=development
OPR_EXECUTOR_RUNTIMES=php-8.0
OPR_EXECUTOR_CONNECTION_STORAGE=file://localhost
OPR_EXECUTOR_INACTIVE_TRESHOLD=60
OPR_EXECUTOR_MAINTENANCE_INTERVAL=60
OPR_EXECUTOR_NETWORK=openruntimes-runtimes
OPR_EXECUTOR_SECRET=executor-secret-key
OPR_EXECUTOR_LOGGING_PROVIDER=
OPR_EXECUTOR_LOGGING_CONFIG=
OPR_EXECUTOR_DOCKER_HUB_USERNAME=
OPR_EXECUTOR_DOCKER_HUB_PASSWORD=
OPR_EXECUTOR_RUNTIME_VERSIONS=v3

OPR_EXECUTOR_CONNECTION_STORAGE takes a DSN string that represents a connection to your storage device. If you would like to use your local filesystem, you can use file://localhost. If using S3 or any other provider for storage, use a DSN of the following format s3://access_key:access_secret@host:port/bucket_name?region=us-east-1

For backwards compatibility, executor also supports OPR_EXECUTOR_STORAGE_* variables as replacement for OPR_EXECUTOR_CONNECTION_STORAGE, as seen in Appwrite repository.

  1. Start Docker container:
docker compose up -d
  1. Prepare a function we will ask executor to run:
mkdir -p functions && cd functions && mkdir -p php-function && cd php-function
printf "<?\nreturn function(\$req, \$res) {\n    \$res->json([ 'n' => \mt_rand() / \mt_getrandmax() ]);\n};" > index.php
tar -czf ../my-function.tar.gz .
cd .. && rm -r php-function

This created my-function.tar.gz that includes index.php with a simple Open Runtimes script.

  1. Send a HTTP request to executor server:
curl -H "authorization: Bearer executor-secret-key" -H "Content-Type: application/json" -X POST http://localhost:9900/v1/runtimes/my-function/execution -d '{"image":"openruntimes/php:v2-8.0","source":"/storage/functions/my-function.tar.gz","entrypoint":"index.php"}'
  1. Stop Docker containers:
docker compose down

Endpoints

TODO: Document each endpoint + CURL examples

Environment variables

TODO: Document each variable

Contributing

All code contributions - including those of people having commit access - must go through a pull request and be approved by a core developer before being merged. This is to ensure a proper review of all the code.

We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.

Security

For security issues, kindly email us at security@appwrite.io instead of posting a public issue on GitHub.

Follow Us

Join our growing community around the world! See our official Blog. Follow us on Twitter, Facebook Page, Facebook Group , Dev Community or join our live Discord server for more help, ideas, and discussions.

License

This repository is available under the MIT License.