GitOps Lifecycle Hooks
Run a script from your repository before a Git-synced project deploys.
GitOps lifecycle hooks run a script from your repository before Arcane deploys a project that uses a Git Sync Pull sync. Use a hook to prepare the workspace for Compose, for example by decrypting secrets, generating config files, or checking the workspace.
A lifecycle hook is repo-trusted code. Anyone who can push to the configured repository can change what the hook does on the next sync. Only enable hooks for repositories you control.
Requirements
- Lifecycle hooks must be enabled by an admin.
- The sync must use Pull and target a project. Push syncs and Swarm stack syncs do not run pre-deploy hooks.
- The sync must have Sync Files turned on so the script is copied with the Compose file.
- The user configuring the hook needs
gitops:lifecycle. - The script path must point to a file inside the synced project directory.
- The runner image must contain the script interpreter and tools the script needs.
Enable lifecycle hooks
- Open Environments → your environment → Security → Lifecycle Hooks.
- Turn on Enable Lifecycle Hooks.
- Set a default Runner Image, such as
alpine:latest, that includes the tools your scripts need. Syncs use it unless they set their own. - Set Max Timeout (seconds) to cap per-sync hook runtimes.
0removes the cap. - Save.
Configure a pre-deploy hook on a sync
- Open the environment’s Git Syncs page.
- Create or edit a Pull sync with Target Type set to Project.
- Expand Pre-deploy script.
- Set Script path to a file in the synced directory, e.g.
scripts/pre-deploy.sh. - Turn on Sync Files.
- Set Runner image if this sync needs a different image than the environment default.
- Set Timeout (seconds).
- Leave Network as
noneunless the script needs network access. - Optional: add environment variables and extra mounts.
- Save the sync.
Arcane runs the script before each deploy that follows a sync. If it exits non-zero, times out, or can’t start, the deploy stops.
Script path and runner behavior
Arcane mounts the project workspace into the runner container and runs the script directly. The script’s shebang chooses the interpreter, so commit the script with an executable mode and use an interpreter that exists in the runner image:
#!/bin/sh
set -eu
echo "Preparing project files"Arcane clears the image’s entrypoint so the script path is the command, so images with their own entrypoint still work.
Network mode
The default network mode is none, which blocks network access from the hook container.
Use another mode only when the script needs it:
bridgefor normal outbound network accesshostwhen the script must use the host network- a Docker network name when the script must reach a specific network
Environment variables
Use Environment variables to pass static values into the runner container. Enter one KEY=VALUE line per variable, using the same format as a .env file:
SOPS_AGE_KEY_FILE=/run/secrets/age.key
CONFIG_ENV=productionKeys must use shell-style names, such as CONFIG_ENV or SOPS_AGE_KEY_FILE.
Extra mounts
Use Extra mounts when the hook needs host files that are not in the project workspace. Enter one mount per line in Docker src:tgt[:ro|:rw] form:
/srv/arcane/secrets:/run/secrets:roBoth source and target must be absolute paths. Prefer read-only mounts unless the script must write to the mounted path.
Check the last run
Arcane records the last hook run on the sync:
- run time
- status:
success,failed, ortimeout - truncated combined stdout and stderr
Check this output when a sync doesn’t deploy. Store hook logs elsewhere if you need them long term.