Skip to Content
Aperture

Writing jobs

The runtime environment your code runs in, how it gets input, and how it reports success.

How a run works

  1. 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.
  2. If the manifest has an install command, it runs in a container for the job's runtime with sh -c "<install>".
  3. cmd runs in a new container on the same /work, so anything install produced (like node_modules) is there.
  4. If both exit with code 0, the execution is success; otherwise fail.

Containers are sandboxed with gVisor and have network access.

Runtimes

driverImageNotes
nodenode:alpineLatest Node.js on Alpine Linux.
pythonpython:slimLatest Python on Debian slim.
gogolang:alpineLatest 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):

  1. Params passed to the run (aperture-cli run job NAME=value, the API, or the dashboard). Values are strings. Cron runs have no params.
  2. Secrets the manifest declares in secrets, decrypted from the project. A secret overrides a param with the same name.
  3. 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:

VariableValue
APERTURE_TRIGGER_IDThe trigger's ID.
APERTURE_TRIGGER_SOURCEgeneric or sns.
APERTURE_TRIGGER_PAYLOADThe request body (generic) or the SNS Message (sns), up to 100 KiB.
APERTURE_TRIGGER_SNS_SUBJECTSNS only: the message subject, if any.
APERTURE_TRIGGER_SNS_MESSAGE_IDSNS only: the message ID.
APERTURE_TRIGGER_SNS_TOPIC_ARNSNS 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 0 for 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.
  • install runs 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-built node_modules).

See Limitations for what's planned.

Examples

Node.js

job.json
{
  "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"]
}
src/index.ts
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

job.json
{
  "name": "hello-python",
  "driver": "python",
  "install": "pip install -r requirements.txt",
  "cmd": "python main.py",
  "includes": ["main.py", "requirements.txt"],
  "params": ["TARGET"]
}
main.py
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

job.json
{
  "name": "hello-go",
  "driver": "go",
  "cmd": "go run .",
  "includes": ["go.mod", "go.sum", "main.go"]
}
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.

On this page