We would ❤️ for you to contribute to Appwrite and help make it better! As a contributor, here are the guidelines we would like you to follow:
Help us keep Appwrite open and inclusive. Please read and follow our Code of Conduct.
Install using composer:
composer require appwrite/php-runtimes<?php
require_once '../vendor/autoload.php';
use Appwrite\Runtimes\Runtimes;
$runtimes = new Runtime();
// returns all supported cloud function runtimes
Runtimes::getAll();After the Docker image is created, this must be added to the main class of this library.
References to this must be added to the constructor of src/Runtimes/Runtimes.php.
Example:
$dotnet = new Runtime('dotnet', '.NET');
$dotnet->addVersion('5.0', 'mcr.microsoft.com/dotnet/runtime:5.0-alpine', 'appwrite/env-dotnet-5.0:1.0.0', [System::X86, System::ARM]);
$runtimes[] = $dotnet;The following checklist aims to ensure that a function runtime gets added successfully
- Implement the runtime in open-runtimes/open-runtimes (you can find the tutorial here)
- Prepare the Readme for your new runtime. Make sure to mention the following details
- Docker base image name + version
- HTTP server library name
- Any extra steps needed to get dependencies running (for e.g.,
package.json) - Copy the rest of the Readme from another existing runtime
- Write the runtime
- Initialize a web server
- Use a library that supports
async/await, also smaller/simpler libraries are preferred as this is a primitive HTTP server - Set Port 3000
- Bind IP 0.0.0.0
- On each POST Request
- Check that the
x-internal-challenge headermatches theINTERNAL_RUNTIME_KEYenvironment variable - Decode the executor's JSON POST request
- Make sure to have the right default values for Request body fields (example)
- env: empty object
- headers: empty object
- payload: empty string
- Check that the
- Use a library that supports
- Create Request Class
- Fields
- env
- payload
- headers
- Fields
- Create Response Class
- Functions
- send(string data, int statusCode)
- json(object data, int statusCode)
- When returning a response, the
Content-Typeheader for thesend()function istext/plainand for thejsonfunction isapplication/json
- Functions
- Execute the function
- Add
try catchblock for error handling- Check if the file is missing
- Check if the method is missing
- Any other language-specific errors that may occur
- Add
- Initialize a web server
- Write the
build.shscript - Write the
start.shscript - Write the Dockerfile
- Add the Docker image you want to base your runtime off
- Create the folders you'll use
- Copy your source code and set working directory
- Add execute permissions for any scripts
-
build.sh -
start.sh
-
- Use
RUNcommands for necessary dependencies (if needed) - Expose port 3000
- Add a
CMDcommand forstart.sh
- Update
./build.shby adding Docker build command for the new runtime - Add test
- Create a PHP file named by the language
- Create a new folder in
./testsby the name of your runtime - Inside the folder, create a function (example)
- Decode the payload as JSON
- Set a string variable called
idto the value of theidkey in the payload or to1if it doesn't exist - Fetch
https://jsonplaceholder.typicode.com/todos/$idwith an HTTP Client installed from your language's package manager using theidvariable - return
res.json - The test must use an external dependency (either for the HTTP Client or the JSON serializer) in order to prove that the runtime can fetch dependencies
- Add runtime to Travis CI
- Edit the
.travis.ymlfile and add your runtime to theenvsection
- Edit the
- Run the test locally
- Raise a PR
- Prepare the Readme for your new runtime. Make sure to mention the following details
- Add the runtime to appwrite/runtimes
- Add runtime support to the CLI in appwrite/sdk-generator
- Ignored files
- Entrypoint
- Create a function starter in appwrite/functions-starter (ensure that the file structure is same as the entrypoint in the CLI)