Writing jobs
The runtime environment your code runs in, how it gets input, and how it reports success.
How a run works
- Aperture copies the job's deployed files into a fresh, empty working
directory,
/work. Files a run creates are discarded afterwards; nothing is shared between runs. - If the manifest has an
installcommand, it runs in a container for the job's runtime withsh -c "<install>". cmdruns in a new container on the same/work, so anythinginstallproduced (likenode_modules) is there.- If both exit with code
0, the execution issuccess; otherwisefail.
Containers are sandboxed with gVisor and have network access.
Runtimes
driver | Image | Notes |
|---|---|---|
node | node:alpine | Latest Node.js on Alpine Linux. |
python | python:slim | Latest Python on Debian slim. |
go | golang:alpine | Latest Go on Alpine Linux. |
Images aren't pinned, so the language version is whatever the latest image was
when the runner started. You can't choose a version per job yet. Alpine images
use musl and sh (no bash); native modules compiled on macOS or glibc won't
load.
Environment variables
Jobs get all their input through environment variables: no arguments, stdin or files. A run's environment is built from, in order of precedence (later wins):
- Params passed to the run (
aperture-cli run job NAME=value, the API, or the dashboard). Values are strings. Cron runs have no params. - Secrets the manifest declares in
secrets, decrypted from the project. A secret overrides a param with the same name. - Platform variables, prefixed with
APERTURE_. They can't be set or overridden by params or secrets.
Platform variables
Set only on runs started by an inbound trigger:
| Variable | Value |
|---|---|
APERTURE_TRIGGER_ID | The trigger's ID. |
APERTURE_TRIGGER_SOURCE | generic or sns. |
APERTURE_TRIGGER_PAYLOAD | The request body (generic) or the SNS Message (sns), up to 100 KiB. |
APERTURE_TRIGGER_SNS_SUBJECT | SNS only: the message subject, if any. |
APERTURE_TRIGGER_SNS_MESSAGE_ID | SNS only: the message ID. |
APERTURE_TRIGGER_SNS_TOPIC_ARN | SNS only: the topic ARN. |
The execution ID, job name and project ID are not exposed to the job.
Output and exit codes
- Write logs to stdout and stderr. The output is stored when the run ends; see Logs.
- Exit
0for success and non-zero for failure. Throwing an uncaught error in Node or Python exits non-zero. - Don't print secret values: logs are visible to everyone in the team.
Limits
- No timeout: a run can go on indefinitely. Make sure your code exits.
- No CPU or memory limits per job.
installruns on every run with no cache. To speed runs up, bundle your dependencies into the upload (for example with a bundler, or by including a Linux-builtnode_modules).
See Limitations for what's planned.
Examples
Node.js
{
"name": "hello-node",
"driver": "node",
"build": "npm run build",
"install": "npm ci --omit=dev",
"cmd": "node dist/index.js",
"includes": ["dist", "package.json", "package-lock.json"],
"secrets": ["API_TOKEN"],
"params": ["TARGET"]
}import { getApertureParam, getApertureSecret } from '@acruxdynamics/aperture';
const target = getApertureParam('TARGET', 'staging');
const token = getApertureSecret('API_TOKEN');
const res = await fetch(`https://api.example.com/${target}/sync`, {
method: 'POST',
headers: { authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`sync failed: ${res.status}`);
console.log('sync done');The Node SDK is optional; reading process.env works too.
Python
{
"name": "hello-python",
"driver": "python",
"install": "pip install -r requirements.txt",
"cmd": "python main.py",
"includes": ["main.py", "requirements.txt"],
"params": ["TARGET"]
}import os
import sys
target = os.environ.get("TARGET", "staging")
print(f"syncing {target}")
if target not in ("staging", "production"):
sys.exit(f"unknown target: {target}")Go
{
"name": "hello-go",
"driver": "go",
"cmd": "go run .",
"includes": ["go.mod", "go.sum", "main.go"]
}package main
import (
"fmt"
"os"
)
func main() {
name := os.Getenv("WHO")
if name == "" {
name = "world"
}
fmt.Printf("Hello, %s!\n", name)
}go run compiles on every run. To skip that, cross-compile on your machine in
build (GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o app ., with
GOARCH matching the runner host), include app, and set cmd to ./app.