The function service lets you map code to endpoints without provisioning a fully-fledged dedicated microservice.
You can create several function services within the same DevOps Console project. You have to create the scripts both for local and remote unit testing only for the first function service. The subsequently created ones will share the same scripts.
The following steps will walk you through the setup of the needed scripts.
You can locally start the function service to test and develop the handlers without the need of deploying to the cloud.
To run the function service clone the DevOps Console project and add the run-function-service-local.sh script. Remember to add execution permissions with
chmod +x run-function-service-local.sh
Every function service handler should be bundled with unit tests. The tests should be started locally, before each commit. To achieve continuous testing we provide a Gitlab's pipeline stage to remotely run the unit tests.
To setup the unit testing add the run-function-service-tests.sh script in the configuration root. Remember to add execution permissions with
chmod +x run-function-service-tests.sh
To setup continuous testing you should append the following pipeline stage to the
The setup phase is over.
To deploy a new function service, open the Console add a new microservice choosing the docker image
Then, create a new configuration for this microservice and call it as you wish, (e.g.: my-function-service).
/home/node/app/functions as run-time mount point.
- method: Request method (e.g. POST, GET, PATCH ...)
- path: Endpoint path (e.g. /hello-world)
- name: Friendly name for this function.
- handler: The function executed when the endpoint is reached.
- schema: JSON schema for the request and reply. The format is the one accepted by Fastify.
Libraries already included as dependencies:
Warning! You have to create the function file from the Console, not from the project repository.
Every time you change the function code (either from the Console or the repository) you should 'commit and regenerate'
Now click Commit & deploy, the newly created endpoint will be exposed and testable right away.
FUNCTIONS_FOLDER holds the path to the directory containing the definitions of the functions,
you are free to customize it and mount there any function.
FUNCTIONS_FOLDER is not specified it defaults to
Anyway, you should always create the
FUNCTIONS_FOLDER directory using the "Add configuration" feature on the Console in order to have it correctly mounted on the microservice.
To test the function service locally, clone the Console configuration repository, then run the script in the configuration root named
Add as extra argument the name of the function-service you want to bootstrap (e.g.: ./run-function-service-local.sh config-map-my-function-service).
To set up unit tests of your endpoints, clone the Console configuration repository and create a directory to hold the tests. It must follow the naming convention:
test/config-map- %function-service-name% (e.g.: test/config-map-my-function-service).
In this directory, you can place the unit test files whose name must end with .test.js
To run the tests locate the file in the configuration root named
Running this script will execute the tests for each function-service. You can add an extra argument with the test directory name to run the tests against a single function service (e.g.: ./run-function-service-tests.sh config-map-my-function-service)
You can trigger this pipeline from the CI/CD > Run Pipeline Gitlab's menu setting the variable