Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build and run functions locally

The STACKIT Function CLI contains commands that simplify the process of building and running a function locally.

Building STACKIT Functions images is handled using Cloud Native Buildpacks, a CNCF project for automatically detecting source code requirements and building images, without requiring complicated configuration.

Note: both building and running functions, require a running Docker installation, accessible over a Unix domain socket in $DOCKER_HOST (or over the default /var/run/docker.sock socket). Full support for alternative OCI runtimes, especially Podman, will come in later releases.

Build a function

To build a function, run the following command in the project directory created by sfn function create:

cd <path-to-functions-project>
sfn function build

When running the build command for the first time, it will error out because you don’t have an image name configured yet. Configure one with the --image flag:

sfn function build --image <your OCI registry>/<repository>/<image name>

Finally, to see the messages printed by the build process, pass the --verbose flag to the sfn function build command:

sfn function build --verbose

Run a function locally

Once you have built a function, you can run it with the run subcommand:

sfn function run

This will start a Docker container with your function, in a simulation of the STACKIT functions environment.

You can access the running function at http://127.0.0.1:8080 by default, unless you override the port the CLI binds to with the --address flag. Meanwhile, the sfn CLI will forward the log messages from your locally-running function, which you can use for debugging purposes.