No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Eddy Hintze 2c813d9c13 deploy: replace ssh-keyscan with accept-new to avoid sshd penalties
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+.
2026-10-29 10:00:12 -04:00
.forgejo/workflows deploy: replace ssh-keyscan with accept-new to avoid sshd penalties 2026-10-29 10:00:12 -04:00
README.md Add support for optional sudo in rsync configuration for deployments 2026-07-11 11:18:40 -04:00

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:

  1. If app input is set (manual dispatch), skips detection and returns that app directly
  2. Otherwise, diffs deploy-tag..HEAD to find changed files
  3. Groups changes by top-level directory under app-dir
  4. Filters to directories containing a compose.yml
  5. 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):

  1. Validates secrets and app directory
  2. Installs tools (docker, docker compose, yq, rsync, ssh — and gnupg if GPG secrets provided)
  3. Sets up SSH connection to the Docker host
  4. Decrypts *.secret files → strips the .secret extension (e.g. .env.secret → .env)
  5. Runs rsync sync entries from deploy.yml (if present)
  6. Creates remote directories from deploy.yml ensure_dirs (if present)
  7. Builds images with docker compose build --pull --build-arg CACHEBUST=<timestamp> (if build: true in deploy.yml) — the CACHEBUST arg ensures layers after ARG CACHEBUST in the Dockerfile are never cached (useful for git clone steps that should always fetch the latest code)
  8. Runs docker compose up -d --remove-orphans (with --force-recreate if configured)
  9. Restarts any services listed in deploy.yml restart_services via docker 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

  1. Add secrets in the consuming repo's Forgejo settings:
    • DOCKER_HOST — e.g. ssh://user@host:22
    • SSH_PRIVATE_KEY — Ed25519 private key
    • GPG_PRIVATE_KEY and GPG_PASSPHRASE — only if using .secret files
  2. Each app directory must contain a compose.yml
  3. Use secrets: inherit to pass all secrets to the reusable workflow, or pass them explicitly