| Filename | Latest commit message | Latest commit date |
|---|---|---|
Each keyscan probe is an unauthenticated connection. OpenSSH PerSourcePenalties (noauth) counts them against the runner's shared source IP, so a few parallel deploys got the runner dropped for 15s+. |
||
| .forgejo/workflows | ||
| README.md | ||
ci-workflows
Reusable Forgejo Actions workflows for deploying Docker Compose apps via SSH.
Note: This repo must be public — Forgejo requires public repos for cross-repo reusable workflows.
Workflows
detect-changes.yml
Finds which apps have changed since the last deployment by diffing against a git tag. Returns a JSON array of app directory names.
Usage:
jobs:
detect-changes:
uses: HomeLab/ci-workflows/.forgejo/workflows/detect-changes.yml@main
with:
deploy-tag: deployed
app: ${{ inputs.app || '' }}
Inputs:
| Input | Required | Default | Description |
|---|---|---|---|
deploy-tag |
yes | — | Git tag marking last successful deployment |
app |
no | "" |
App name for manual dispatch (skips git diff detection) |
app-dir |
no | "." |
Subdirectory containing apps. Use . for repo root |
ignore-file |
no | ".deploy-ignore" |
Deploy-ignore filename, relative to app-dir |
Outputs:
| Output | Description |
|---|---|
apps |
JSON array of app names to deploy (e.g. ["my-app","other-app"]). Returns ["__none__"] if no changes detected |
How detection works:
- If
appinput is set (manual dispatch), skips detection and returns that app directly - Otherwise, diffs
deploy-tag..HEADto find changed files - Groups changes by top-level directory under
app-dir - Filters to directories containing a
compose.yml - Excludes any apps listed in the ignore file
Deploy-ignore file format:
# Comments and blank lines are ignored
app-to-skip
another-app-to-skip
deploy.yml
Deploys a single Docker Compose app to a remote host via SSH. Handles GPG decryption of secrets, rsync file sync, directory creation, and docker compose up.
Usage:
jobs:
deploy:
needs: [detect-changes]
if: needs.detect-changes.outputs.apps != '["__none__"]'
strategy:
matrix:
app: ${{ fromJSON(needs.detect-changes.outputs.apps) }}
max-parallel: 1
fail-fast: false
uses: HomeLab/ci-workflows/.forgejo/workflows/deploy.yml@main
with:
app: ${{ matrix.app }}
secrets: inherit
Inputs:
| Input | Required | Default | Description |
|---|---|---|---|
app |
yes | — | App directory name to deploy |
app-dir |
no | "." |
Subdirectory containing apps. Use . for repo root |
Secrets:
| Secret | Required | Description |
|---|---|---|
DOCKER_HOST |
yes | SSH URI for Docker host (e.g. ssh://user@host:22) |
SSH_PRIVATE_KEY |
yes | Ed25519 SSH private key for the deploy user |
GPG_PRIVATE_KEY |
no | GPG private key for decrypting .secret files |
GPG_PASSPHRASE |
no | GPG key passphrase |
What it does (in order):
- Validates secrets and app directory
- Installs tools (docker, docker compose, yq, rsync, ssh — and gnupg if GPG secrets provided)
- Sets up SSH connection to the Docker host
- Decrypts
*.secretfiles → strips the.secretextension (e.g..env.secret→.env) - Runs rsync sync entries from
deploy.yml(if present) - Creates remote directories from
deploy.ymlensure_dirs(if present) - Builds images with
docker compose build --pull --build-arg CACHEBUST=<timestamp>(ifbuild: trueindeploy.yml) — theCACHEBUSTarg ensures layers afterARG CACHEBUSTin the Dockerfile are never cached (useful forgit clonesteps that should always fetch the latest code) - Runs
docker compose up -d --remove-orphans(with--force-recreateif configured) - Restarts any services listed in
deploy.ymlrestart_servicesviadocker compose restart(if present) — useful for services that need a kick after a sibling's config files have synced
Per-app deploy.yml
Each app can optionally include a deploy.yml file (not the workflow — this lives in the app directory) to configure sync, directories, and recreate behavior:
# Sync local files/dirs to the remote host before deploying
sync:
- src: ./config/
dest: /appdata/my-app/config/
delete: true # optional, removes remote files not in src
exclude: # optional
- "*.tmp"
sudo: false # optional, default false — run remote rsync as root
# (--rsync-path="sudo rsync"). Needed when dest contains
# files a container has since written as root (e.g. a
# config dir a service rewrites at startup), which would
# otherwise fail with "Permission denied" / "Operation
# not permitted". Requires passwordless sudo for the SSH
# deploy user on the target host.
# Ensure directories exist on the remote host
ensure_dirs:
- path: /appdata/my-app/data
owner: "1000:1000" # optional, runs chown
recursive: false # optional, default false
# Build images from Dockerfile before deploying (pulls base images fresh)
# Also passes --build-arg CACHEBUST=<timestamp> to bust Docker layer cache
build: false
# Force recreate containers even if config unchanged
force_recreate: false
# Restart specific compose services after `docker compose up`
# (e.g. to pick up newly-synced config files)
restart_services:
- my-service
- another-service
Full caller workflow example
A typical consuming repo needs a thin caller workflow at .forgejo/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
paths:
- "my-app-*/**"
- ".forgejo/workflows/deploy.yml"
workflow_dispatch:
inputs:
app:
description: "App directory name to deploy"
type: string
required: true
concurrency:
group: deploy
cancel-in-progress: false
permissions:
contents: write
jobs:
detect-changes:
name: Detect changes
uses: HomeLab/ci-workflows/.forgejo/workflows/detect-changes.yml@main
with:
deploy-tag: deployed
app: ${{ inputs.app || '' }}
deploy:
name: Deploy ${{ matrix.app }}
needs: [detect-changes]
if: needs.detect-changes.outputs.apps != '["__none__"]'
strategy:
matrix:
app: ${{ fromJSON(needs.detect-changes.outputs.apps) }}
max-parallel: 1
fail-fast: false
uses: HomeLab/ci-workflows/.forgejo/workflows/deploy.yml@main
with:
app: ${{ matrix.app }}
secrets: inherit
mark-deployed:
name: Mark as deployed
needs: [detect-changes, deploy]
if: success() && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: Public-Mirrors/actions_checkout@v6.0.2
- run: |
git tag -f deployed
git push -f origin deployed
Required repo setup
- Add secrets in the consuming repo's Forgejo settings:
DOCKER_HOST— e.g.ssh://user@host:22SSH_PRIVATE_KEY— Ed25519 private keyGPG_PRIVATE_KEYandGPG_PASSPHRASE— only if using.secretfiles
- Each app directory must contain a
compose.yml - Use
secrets: inheritto pass all secrets to the reusable workflow, or pass them explicitly