Files
ci-actions/README.md
T
tthandClaude Opus 5.5 94d0ba6b78
pr-check / docker (pull_request) Successful in 10s
pr-check / binary (pull_request) Successful in 1m14s
portainer-deploy: wait for the Swarm rollout before the smoke check (v12)
The smoke URL answered from the old task right after the stack PUT, so CI
went green before anything was deployed (birdnet-go 2026-11-03: green, then
1 min of 503) and a paused update stayed unnoticed (revaj-crm-stage
2026-11-02, new image exited 1 twice, CI green). Now the step waits until
every service whose UpdateStatus.StartedAt changed is completed and fails
on paused / rollback_*; untouched services are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 01:40:24 +01:00

171 lines
6.1 KiB
Markdown

# ci-actions
Shared composite actions for Gitea Actions.
## trivy-gate
Scans a pushed image with Trivy (vulnerabilities + secrets) and fails when it
finds a **fixable** vulnerability of the given severities (default
`HIGH,CRITICAL`) or an embedded secret. Vulnerabilities without a fix are
reported but never block - otherwise a deploy could be stuck forever.
Intended order in a pipeline:
1. build and push only the immutable tag (`sha-…`)
2. `trivy-gate` on that tag
3. move the floating tag (`latest`, `stable-<arch>`) and deploy
```yaml
- id: trivy
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v1
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ steps.build.outputs.sha }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
platform: linux/arm64 # single-platform non-amd64 images only
mode: block # or warn
skip: ${{ inputs.skip_trivy || 'false' }}
```
Source trees (apps that ship no image, e.g. an APK): `scan-type: fs` scans
the git-tracked files plus lockfiles generated in the job (also gitignored
ones like Flutter's `pubspec.lock`), so run it after the dependency fetch:
```yaml
- uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v2
with:
scan-type: fs
```
Jobs without a Docker daemon (a `container:` image such as Flutter) fall
back to the pinned Trivy release binary, verified by SHA-256 (`runtime:
auto`); `jq` is installed with apt when missing.
Accepted risks go to `.trivyignore.yaml` in the calling repo, each with a
statement and an expiry, so they come back on their own:
```yaml
vulnerabilities:
- id: CVE-2026-12345
statement: not reachable, the affected feature is disabled
expired_at: 2026-12-31
```
The vulnerability DB lives in the Docker named volume `trivy-cache` on the
runner host (refreshed under an exclusive lock, scans read it read-only under
a shared lock, so parallel matrix jobs are fine).
## dtrack-sbom
Converts the `trivy-gate` report to CycloneDX and uploads it to
Dependency-Track. Never fails the job.
```yaml
- uses: https://git.rfa.cz/tth-pub/ci-actions/dtrack-sbom@v1
with:
report: ${{ steps.trivy.outputs.report }}
url: ${{ vars.DTRACK_URL }}
api-key: ${{ secrets.DTRACK_API_KEY }}
ca-pem: ${{ vars.RFA_CA_PEM }}
project: my-image
version: latest
```
## trivy-gate: misconfigurations
`scanners: misconfig` with `scan-type: fs` checks Dockerfiles, compose and
other IaC in the tree. These findings are reported (HIGH/CRITICAL by
default) and never block.
```yaml
- uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v2
with:
scan-type: fs
scanners: misconfig
mode: warn
```
## gitleaks
Scans the commits of the push (`before..sha`, first-parent line, merge diffs
off, so merging upstream into a fork does not report upstream history) for
secrets, with redacted output. Without a `.gitleaks.toml` in the repo the
default rules apply with test files and fixtures allowlisted. The release
binary is verified by SHA-256.
```yaml
- uses: https://git.rfa.cz/tth-pub/ci-actions/gitleaks@v2
with:
mode: block # or warn
```
## Versions
`v1` image gate + SBOM; `v2` fs scans, binary runtime, misconfig, gitleaks;
`v3` gitleaks fetches the parent of a single commit in a depth-1 checkout
(dispatch/cron runs scanned the whole tree as a root commit before).
`v8` dtrack-sbom really never fails the job: the runner's `bash -e` turned
an unreachable Dependency-Track into a failed build instead of a warning.
`v12` portainer-deploy waits for the Swarm rollout before the smoke check
and fails on a paused or rolled-back update: the smoke URL used to answer
from the old task, so a new image that never started still gave a green
deploy.
Pinned tools (Trivy binary + image, gitleaks) are bumped by Renovate
(tth/renovate). Its post-upgrade task `.gitea/update-checksums.sh`
recomputes the tarball SHA-256 pins (downloaded and checked against the
release's checksums file); `.gitea/workflows/pr-check.yml` runs the actions
of the PR branch with both Trivy runtimes; after the merge `tag.yml` cuts
the next `vN`, which the pipelines then pick up through their own Renovate
PR. Hand-made changes are tagged by hand as before.
## portainer-deploy
Updates a Portainer Swarm stack from a compose file in the repository - the
last step of the build → `trivy-gate` → move `latest` → deploy pipeline. The
compose file in git is the single source of truth: Portainer's stored
compose is replaced on every deploy. The stack's env vars (where the secrets
live) are kept and never logged; only `vars` are overwritten. Images are
re-pulled (`pullImage`). The step then waits until every service the deploy
changed has finished its Swarm update (`wait-rollout`, `rollout-timeout`,
default 600 s incl. image pulls) and fails when the update is paused or
rolled back; only then is `smoke-url` checked. Services the deploy did not
touch are ignored, even when an older update of theirs is still paused.
```yaml
- uses: https://git.rfa.cz/tth-pub/ci-actions/portainer-deploy@v5
with:
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
stack-id: ${{ secrets.PORTAINER_STACK_ID }} # empty = skip with a notice
compose-file: docker-compose.swarm.yml
vars: |
IMAGE_TAG=sha-${{ steps.build.outputs.sha }}
smoke-url: https://app.example.org/health # optional
smoke-status: "200"
smoke-timeout: "180"
rollout-timeout: "600" # optional; wait-rollout: "false" = old behaviour
```
Config files from the repo can ride along as Swarm configs. Each becomes a
config named after its content hash, created when missing; the stack
variable points at it, so a changed file rolls the services that mount it,
and superseded versions are removed once nothing uses them:
```yaml
configs: |
CFG_NGINX=deploy/nginx.conf
config-prefix: myapp_
```
```yaml
# compose
configs:
nginx_conf: {external: true, name: "${CFG_NGINX}"}
```
Pin images in the compose file to the variable (`image: …:${IMAGE_TAG}`), so
the deployed version is the commit that passed the gate, not whatever
`latest` points at when Swarm pulls.