Files
ci-actions/README.md
T
tthandClaude Opus 5.5 e82c65a3c4
tag / tag (push) Skipped
dtrack-sbom: never fail the job when Dependency-Track is unreachable (v8)
The runner starts composite bash steps with -e, while the script handles
every failure itself and only warns. With dtrack.grg down, curl wrote no
resp.json, the unguarded cat of it failed and -e ended the step with
exit 1 before warn() ran - a failed build (meshcore-open run 29) instead
of a warning. set +e restores the behaviour the script was written for.

Checked with the step run under bash -e -o pipefail against an
unreachable URL (was exit 1, now ::warning:: HTTP 000 and exit 0), a
server answering 401 (warning, exit 0) and 200 (uploaded, token shown).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 18:26:35 +01:00

162 lines
5.4 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.
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`).
```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"
```
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.