23 Commits
Author SHA1 Message Date
renovate-bot 979335fe31 Merge pull request 'Update trivy to v0.76.2' (#9) from renovate/trivy into main
tag / tag (push) Successful in 4s
2026-11-05 14:00:01 +01:00
renovate-bot 6ee8b2da6a Merge pull request 'Update Node.js to ed67041' (#8) from renovate/ci-actions into main
tag / tag (push) Successful in 5s
2026-11-05 13:58:49 +01:00
renovate-bot 26468ba73d Update trivy to v0.76.2
pr-check / docker (pull_request) Successful in 16s
pr-check / binary (pull_request) Successful in 56s
2026-11-05 12:55:58 +00:00
renovate-bot b90b98bafb Update Node.js to 5adad64
pr-check / docker (pull_request) Successful in 12s
pr-check / binary (pull_request) Successful in 58s
2026-11-05 12:55:52 +00:00
tth 7c8359099c Merge pull request 'portainer-deploy: wait for the Swarm rollout before the smoke check (v12)' (#7) from agent/dart/portainer-wait-rollout into main
tag / tag (push) Skipped
2026-11-03 01:55:02 +01:00
tthandClaude Opus 5.5 94d0ba6b78 portainer-deploy: wait for the Swarm rollout before the smoke check (v12)
pr-check / docker (pull_request) Successful in 10s
pr-check / binary (pull_request) Successful in 1m14s
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
renovate-bot 52fab24049 Merge pull request 'Update Node.js to e4db4c9' (#6) from renovate/ci-actions into main
tag / tag (push) Successful in 5s
2026-10-29 01:52:40 +01:00
renovate-bot 1d363f0eac Update Node.js to e4db4c9
pr-check / docker (pull_request) Successful in 11s
pr-check / binary (pull_request) Successful in 58s
2026-10-29 00:51:27 +00:00
renovate-bot dfe768f871 Merge pull request 'Update Node.js to 9481667' (#5) from renovate/ci-actions into main
tag / tag (push) Successful in 4s
2026-10-28 07:57:13 +01:00
renovate-bot fc400e752d Update Node.js to 9481667
pr-check / docker (pull_request) Successful in 9s
pr-check / binary (pull_request) Successful in 54s
2026-10-28 06:56:14 +00:00
renovate-bot 78d295d616 Merge pull request 'Update Node.js to v26' (#4) from renovate/major-ci-actions into main
tag / tag (push) Successful in 5s
2026-10-28 01:59:12 +01:00
renovate-bot 55b6b50672 Update Node.js to v26
pr-check / docker (pull_request) Successful in 11s
pr-check / binary (pull_request) Successful in 1m0s
2026-10-28 00:58:02 +00:00
tthandClaude Opus 5.5 e82c65a3c4 dtrack-sbom: never fail the job when Dependency-Track is unreachable (v8)
tag / tag (push) Skipped
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
renovate-bot ade9877f07 Merge pull request 'Update trivy to v0.76.1' (#1) from renovate/trivy into main
tag / tag (push) Successful in 4s
2026-10-26 17:40:45 +01:00
renovate-bot 371eedc0ef Update trivy to v0.76.1
pr-check / docker (pull_request) Successful in 11s
pr-check / binary (pull_request) Successful in 42s
2026-10-26 16:39:59 +00:00
renovate-bot 2656687937 Merge pull request 'Update actions/checkout action to v7' (#2) from renovate/major-ci-actions into main
tag / tag (push) Successful in 4s
2026-10-26 16:46:57 +01:00
renovate-bot 6a93557620 Update actions/checkout action to v7
pr-check / docker (pull_request) Successful in 11s
pr-check / binary (pull_request) Successful in 56s
2026-10-26 15:45:53 +00:00
tthandClaude Opus 5.5 632d2d7465 Renovate-maintained tool pins: checksum script, PR check, auto tag
tag / tag (push) Skipped
Trivy and gitleaks were pinned (version + tarball SHA-256 + image
digest) with nothing to bump them. Renovate (tth/renovate) now does;
.gitea/update-checksums.sh recomputes the SHA-256s after a bump and
checks them against the release checksums file; pr-check.yml runs the
PR's actions with the Trivy container and with the pinned binary
(checksum verified); tag.yml cuts the next vN after renovate-bot's merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 15:18:29 +01:00
tthandClaude Opus 5.5 380988c194 portainer-deploy: content-addressed Swarm configs from repo files (v5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:24:36 +01:00
tthandClaude Opus 5.5 a3c4ae5edf portainer-deploy: update a Swarm stack from the repo's compose file (v4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:20:28 +01:00
tthandClaude Opus 5.5 67a711fe3c gitleaks: fetch the parent of a single scanned commit in shallow checkouts (v3)
A dispatch or cron run has no before-sha, so one commit is scanned; in a
depth-1 checkout it has no parent and gitleaks diffed it as a root commit,
reporting the whole tree (corescope: 3 upstream files).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:34:32 +01:00
tthandClaude Opus 5.5 9591a27e59 README: dot-free version tags (runner mangles v1.2), v2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:09:45 +01:00
tthandClaude Opus 5.5 95abc7822e gitleaks action; trivy-gate scanners input, misconfigurations reported (never blocking)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:03:37 +01:00
8 changed files with 658 additions and 8 deletions

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Recompute the pinned SHA-256 of the Trivy and gitleaks release tarballs
# after a version bump. Renovate runs it as a postUpgradeTask (tth/renovate
# config.json), so a bump PR carries matching checksums; by hand:
# bash .gitea/update-checksums.sh
#
# Each tarball is downloaded and hashed here, and the hash must ALSO match
# the release's own checksums file - the pin is what we verified at bump
# time, the action then refuses any other bytes.
set -euo pipefail
cd "$(dirname "$0")/.."
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
# pin <action.yml> <version var> <repo> <name prefix> <arch suffix> <sha var>...
pin() {
local file=$1 vvar=$2 repo=$3 prefix=$4
shift 4
local ver
ver=$(sed -n "s/^ *$vvar: *\"\([0-9.]*\)\".*/\1/p" "$file")
[ -n "$ver" ] || {
echo "no $vvar in $file" >&2
exit 1
}
local base="https://github.com/$repo/releases/download/v$ver"
curl -fsSL --retry 3 -o "$work/sums" "$base/${prefix}_${ver}_checksums.txt"
while [ "$#" -gt 0 ]; do
local arch=$1 svar=$2
shift 2
local tgz="${prefix}_${ver}_${arch}.tar.gz"
curl -fsSL --retry 3 -o "$work/$tgz" "$base/$tgz"
local got want
got=$(sha256sum "$work/$tgz" | cut -d' ' -f1)
want=$(awk -v f="$tgz" '$2 == f {print $1}' "$work/sums")
[ "$got" = "$want" ] || {
echo "$tgz: downloaded $got, release says ${want:-nothing}" >&2
exit 1
}
sed -i "s/^\( *$svar: *\)[0-9a-f]\{64\}/\1$got/" "$file"
echo "$tgz $got"
done
}
pin trivy-gate/action.yml TRIVY_VERSION aquasecurity/trivy trivy \
Linux-64bit TRIVY_SHA256_AMD64 Linux-ARM64 TRIVY_SHA256_ARM64
pin gitleaks/action.yml GITLEAKS_VERSION gitleaks/gitleaks gitleaks \
linux_x64 GITLEAKS_SHA256_X64 linux_arm64 GITLEAKS_SHA256_ARM64
+58
View File
@@ -0,0 +1,58 @@
# PR check (Renovate bumps of Trivy / gitleaks, and any other PR): the
# actions of THIS branch must actually run. Both runtimes of trivy-gate:
# the Trivy container (docker job) and the pinned binary with its checksum
# check (container job without Docker) - a bump with a wrong checksum fails
# here, not in every pipeline that uses the next tag. Required by branch
# protection, so a green PR automerges and tag.yml cuts the next vN.
name: pr-check
on:
pull_request:
concurrency:
group: pr-check-${{ github.head_ref }}
cancel-in-progress: true
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: trivy-gate, Trivy container, image scan
id: image
uses: ./trivy-gate
with:
image: alpine:3.22@sha256:2e0b81d60597f449baa56dc25d355367869d2dca4cd57e866f1e2b52af3eb55f
runtime: docker
mode: warn
- name: The report is real
run: |
set -euo pipefail
jq -e '.Results | length > 0' "${{ steps.image.outputs.report }}" >/dev/null
echo "blocking=${{ steps.image.outputs.blocking }}"
- name: gitleaks
uses: ./gitleaks
with:
mode: block
binary:
runs-on: ubuntu-latest
# No Docker CLI here, so trivy-gate falls back to the pinned binary.
container:
image: node:26-trixie-slim@sha256:5adad64f9a1fca2d51972caa65983634c8a774eb300d72b20f7f2a0f60368072
steps:
- name: Tools the actions expect
run: apt-get update -qq && apt-get install -y -qq --no-install-recommends ca-certificates curl git jq >/dev/null
- uses: actions/checkout@v7
- name: trivy-gate, pinned binary, fs scan
id: fs
uses: ./trivy-gate
with:
scan-type: fs
runtime: binary
mode: warn
- name: The report is real
run: jq -e 'has("Results") or has("ArtifactName")' "${{ steps.fs.outputs.report }}" >/dev/null
- name: gitleaks, pinned binary
uses: ./gitleaks
with:
mode: block
+31
View File
@@ -0,0 +1,31 @@
# Cut the next major tag (vN) when a Renovate bump of a pinned tool lands on
# main, so the pipelines get it through their own Renovate PR ("update
# ci-actions to vN"). Only renovate-bot's merges: hand-made changes keep
# being tagged by hand, with the README note.
name: tag
on:
push:
branches: [main]
jobs:
tag:
if: github.actor == 'renovate-bot'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Next vN on HEAD
run: |
set -euo pipefail
git fetch -q --tags
if git tag --points-at HEAD | grep -qE '^v[0-9]+$'; then
echo "HEAD already tagged: $(git tag --points-at HEAD | tr '\n' ' ')"; exit 0
fi
last=$(git tag -l 'v[0-9]*' | grep -E '^v[0-9]+$' | sed 's/^v//' | sort -n | tail -1)
next="v$((${last:-0} + 1))"
git tag "$next" HEAD
git push origin "refs/tags/$next"
echo "tagged $next on $(git rev-parse --short HEAD): $(git log -1 --format=%s)"
+99 -1
View File
@@ -32,7 +32,7 @@ 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@v1.1
- uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v2
with:
scan-type: fs
```
@@ -70,3 +70,101 @@ Dependency-Track. Never fails the job.
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.
+6 -2
View File
@@ -32,7 +32,7 @@ inputs:
default: "5"
trivy-image:
description: Trivy container image, pinned by digest.
default: aquasec/trivy:0.75.0@sha256:af6acf9a6b85dfe389a1941505c0ce9efef52a4719635e1a962f022a3d855daa
default: aquasec/trivy:0.76.2@sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb
runs:
using: composite
@@ -49,7 +49,11 @@ runs:
MIN: ${{ inputs.min-components }}
TRIVY: ${{ inputs.trivy-image }}
run: |
set -uo pipefail
# The runner starts composite bash steps with -e; this script handles
# every failure itself (warn, exit 0), so -e only turns an unguarded
# command into a failed job - e.g. the cat of a resp.json curl never
# wrote when Dependency-Track was unreachable.
set +e -uo pipefail
warn() { echo "::warning::SBOM $PROJECT/$VERSION: $*"; exit 0; }
[ -n "$REPORT" ] && [ -f "$REPORT" ] || warn "no report (gate skipped?)"
[ -n "$DT_KEY" ] || warn "no API key"
+133
View File
@@ -0,0 +1,133 @@
name: gitleaks
description: >
Scan the commits a push brings for secrets with gitleaks. Only the
first-parent line is scanned, so a merge of upstream into a fork reports
our commits, not the upstream history. Findings are always redacted.
inputs:
mode:
description: "block = fail the step on findings, warn = report only."
default: block
log-opts:
description: >
git log range/options passed to gitleaks. Empty = the commits of this
push (before..sha) on the first-parent line, else the last commit.
default: ""
config:
description: >
gitleaks config in the repo (allowlists); used when it exists. Without
one, the default rules apply with test files allowlisted (fixtures
carry fake keys by design and the noise would bury a real one).
default: .gitleaks.toml
skip:
description: Emergency bypass (workflow_dispatch input); logged loudly.
default: "false"
outputs:
findings:
description: Number of findings.
value: ${{ steps.scan.outputs.findings }}
runs:
using: composite
steps:
- id: scan
shell: bash
env:
MODE: ${{ inputs.mode }}
LOG_OPTS: ${{ inputs.log-opts }}
CONFIG: ${{ inputs.config }}
SKIP: ${{ inputs.skip }}
BEFORE: ${{ github.event.before }}
SHA: ${{ github.sha }}
GITLEAKS_VERSION: "8.30.1"
GITLEAKS_SHA256_X64: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
GITLEAKS_SHA256_ARM64: e4a487ee7ccd7d3a7f7ec08657610aa3606637dab924210b3aee62570fb4b080
run: |
set -euo pipefail
if [ "$SKIP" = "true" ]; then
echo "::warning::GITLEAKS SKIPPED (manual bypass)"; echo "findings=0" >>"$GITHUB_OUTPUT"; exit 0
fi
case "$MODE" in block|warn) ;; *) echo "::error::mode must be block or warn"; exit 1 ;; esac
work="${RUNNER_TEMP:-/tmp}/gitleaks"; mkdir -p "$work"
if ! command -v jq >/dev/null; then
(apt-get update -qq && apt-get install -y -qq jq) >/dev/null 2>&1 || { echo "::error::jq is required"; exit 1; }
fi
git config --global --add safe.directory "$PWD" 2>/dev/null || true
# Release binary, verified by SHA-256 (no Docker needed: the repo is
# local to the job, wherever the job runs).
bin="$work/gitleaks"
if [ ! -x "$bin" ]; then
case "$(uname -m)" in
x86_64) arch=x64; sum="$GITLEAKS_SHA256_X64" ;;
aarch64|arm64) arch=arm64; sum="$GITLEAKS_SHA256_ARM64" ;;
*) echo "::error::no pinned gitleaks binary for $(uname -m)"; exit 1 ;;
esac
curl -fsSL -o "$work/gl.tgz" \
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_${arch}.tar.gz"
echo "$sum $work/gl.tgz" | sha256sum -c --quiet
tar -xzf "$work/gl.tgz" -C "$work" gitleaks
fi
opts="$LOG_OPTS"
if [ -z "$opts" ]; then
zero=0000000000000000000000000000000000000000
if [ -n "$BEFORE" ] && [ "$BEFORE" != "$zero" ]; then
# Checkouts are often shallow: deepen until the old head is there.
for _ in 1 2 3 4 5 6; do
git cat-file -e "$BEFORE^{commit}" 2>/dev/null && break
git fetch -q --deepen=100 origin 2>/dev/null || break
done
if git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
opts="--first-parent --diff-merges=off $BEFORE..$SHA"
fi
fi
if [ -z "$opts" ]; then
# One commit (dispatch/cron). In a depth-1 checkout it has no
# parent and would be diffed as a root commit, i.e. the whole
# tree (upstream files of a fork included): fetch its parent.
head="${SHA:-HEAD}"
git rev-parse -q --verify "$head^" >/dev/null 2>&1 || git fetch -q --deepen=1 origin 2>/dev/null || true
opts="--diff-merges=off -1 $head"
fi
fi
if [ -n "$CONFIG" ] && [ -f "$CONFIG" ]; then
cfg=(--config "$CONFIG")
else
cat >"$work/default.toml" <<'TOML'
[extend]
useDefault = true
[[allowlists]]
description = "test files and fixtures"
paths = [
'(^|/)(tests?|__tests__|testdata|fixtures?|e2e)/',
'_test\.(go|dart|py)$',
'(^|/)test_[^/]*\.py$',
'\.(test|spec)\.(ts|js|mjs|tsx)$',
'(^|/)test-[^/]*\.js$',
]
TOML
cfg=(--config "$work/default.toml")
fi
echo "gitleaks over: git log $opts"
rc=0
"$bin" git --no-banner --redact --log-level warn "${cfg[@]}" --log-opts "$opts" \
--report-format json --report-path "$work/report.json" . || rc=$?
[ "$rc" -le 1 ] || { echo "::error::gitleaks failed (exit $rc)"; exit 1; }
n=$(jq length "$work/report.json" 2>/dev/null || echo 0)
echo "findings=$n" >>"$GITHUB_OUTPUT"
if [ "$n" -gt 0 ]; then
jq -r '.[] | [.RuleID, .File, (.StartLine|tostring), .Commit[0:10]] | @tsv' "$work/report.json" \
| { printf 'RULE\tFILE\tLINE\tCOMMIT\n'; cat; } \
| { if command -v column >/dev/null; then column -t -s $'\t'; else cat; fi; }
if [ "$MODE" = block ]; then
echo "::error::gitleaks: $n secrets in the pushed commits - rotate them, then allowlist or rewrite"
exit 1
fi
echo "::warning::gitleaks (warn mode): $n secrets in the pushed commits would block"
else
echo "gitleaks: no secrets in the pushed commits"
fi
+263
View File
@@ -0,0 +1,263 @@
name: portainer-deploy
description: >
Update a Portainer Swarm stack from a compose file in the repository. The
compose file 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 only the given variables are overwritten. Images are re-pulled.
Config files from the repo can be shipped as content-addressed Swarm
configs. Waits until Swarm has finished rolling out the services the
deploy changed (a paused or rolled-back update fails the step), then
optionally until a URL answers with the expected status.
inputs:
url:
description: Portainer base URL.
required: true
token:
description: Portainer API key (X-API-Key).
required: true
stack-id:
description: >
Portainer stack id. Empty = skip the deploy with a notice (a repo that
has no stack yet).
default: ""
compose-file:
description: Compose file in the checkout to deploy.
required: true
endpoint-id:
description: Portainer environment (endpoint) id.
default: "1"
vars:
description: >
Stack variables to set, one NAME=value per line (e.g. IMAGE_TAG=sha-1234abcd).
Every other stack variable is kept as it is.
default: ""
configs:
description: >
Files shipped as Swarm configs, one VAR=path per line. Each file becomes
a config named <config-prefix><var>-<sha256[:12] of the content>
(created when missing) and the stack variable VAR is set to that name,
so the compose file references it as
`{external: true, name: "${VAR}"}`. A changed file = a new config =
the service is updated; older versions of the same VAR are removed once
no service uses them.
default: ""
config-prefix:
description: Prefix of the config names (e.g. the stack name and an underscore).
default: ""
prune:
description: Remove services that are no longer in the compose file.
default: "false"
wait-rollout:
description: >
Wait until every service this deploy changed has finished its Swarm
update; fail when the update is paused or rolled back. "false" = return
right after the stack update (the old behaviour).
default: "true"
rollout-timeout:
description: Seconds to wait for the rollout (image pulls included).
default: "600"
smoke-url:
description: >
URL polled after the rollout until it answers smoke-status. Empty = no
check.
default: ""
smoke-status:
description: Expected HTTP status of smoke-url.
default: "200"
smoke-timeout:
description: Seconds to wait for smoke-url.
default: "180"
runs:
using: composite
steps:
- shell: bash
env:
PORTAINER_URL: ${{ inputs.url }}
PORTAINER_TOKEN: ${{ inputs.token }}
STACK_ID: ${{ inputs.stack-id }}
COMPOSE_FILE: ${{ inputs.compose-file }}
ENDPOINT_ID: ${{ inputs.endpoint-id }}
SET_VARS: ${{ inputs.vars }}
CONFIGS: ${{ inputs.configs }}
CONFIG_PREFIX: ${{ inputs.config-prefix }}
PRUNE: ${{ inputs.prune }}
WAIT_ROLLOUT: ${{ inputs.wait-rollout }}
ROLLOUT_TIMEOUT: ${{ inputs.rollout-timeout }}
SMOKE_URL: ${{ inputs.smoke-url }}
SMOKE_STATUS: ${{ inputs.smoke-status }}
SMOKE_TIMEOUT: ${{ inputs.smoke-timeout }}
run: |
set -euo pipefail
if [ -z "$STACK_ID" ]; then
echo "::notice::portainer-deploy: no stack id, deploy skipped"
exit 0
fi
# The stack env carries the secrets: it only ever lives in this
# process's memory, between the GET and the PUT, never in the log.
python3 - <<'PY'
import base64, hashlib, json, os, ssl, sys, time, urllib.error, urllib.parse, urllib.request
E = os.environ
base = E["PORTAINER_URL"].rstrip("/")
token = E["PORTAINER_TOKEN"]
stack_id, endpoint = E["STACK_ID"], E.get("ENDPOINT_ID") or "1"
if not base or not token:
sys.exit("::error::portainer-deploy: url and token are required")
def api(method, path, body=None, ok=(200,)):
req = urllib.request.Request(base + path, method=method,
headers={"X-API-Key": token, "Content-Type": "application/json"},
data=None if body is None else json.dumps(body).encode())
try:
with urllib.request.urlopen(req, timeout=120) as r:
status, raw = r.status, r.read()
except urllib.error.HTTPError as e:
status, raw = e.code, e.read()
if status not in ok:
raise RuntimeError(f"{method} {path.split('?')[0]} -> HTTP {status}: {raw[:300].decode(errors='replace')}")
return status, (json.loads(raw) if raw.strip() else None)
def lines(name):
out = {}
for line in E.get(name, "").splitlines():
line = line.strip()
if not line:
continue
key, sep, value = line.partition("=")
if not sep or not key.strip():
sys.exit(f"::error::portainer-deploy: bad {name.lower()} line (want NAME=value): {key!r}")
out[key.strip()] = value.strip() if name == "CONFIGS" else value
return out
try:
sets = lines("SET_VARS")
docker = f"/api/endpoints/{endpoint}/docker"
# Content-addressed configs: the name changes with the content, so
# a changed file rolls the services that mount it.
prefix = E.get("CONFIG_PREFIX", "")
stale = []
for var, path in lines("CONFIGS").items():
with open(path, "rb") as f:
data = f.read()
stem = f"{prefix}{var.lower()}"
name = f"{stem}-{hashlib.sha256(data).hexdigest()[:12]}"
flt = urllib.parse.quote(json.dumps({"label": [f"portainer-deploy.config={stem}"]}))
_, existing = api("GET", f"{docker}/configs?filters={flt}")
names = {c["Spec"]["Name"]: c["ID"] for c in existing or []}
if name in names:
print(f"config {name} ({path}) unchanged")
else:
api("POST", f"{docker}/configs/create", {
"Name": name,
"Data": base64.b64encode(data).decode(),
"Labels": {"portainer-deploy.config": stem},
}, ok=(200, 201))
print(f"config {name} created from {path}")
stale += [(n, i) for n, i in names.items() if n != name]
sets[var] = name
_, stack = api("GET", f"/api/stacks/{stack_id}")
# Rollout: remember each service's last update start before the
# PUT; afterwards only the services whose update start changed are
# this deploy's. Comparing with the previous value, not with the
# clock, keeps runner/Swarm clock skew out of it. Without this the
# smoke check below answered from the OLD task (birdnet-go
# 2026-11-03: green CI, then 1 min of 503) and a paused update
# went unnoticed (revaj-crm-stage 2026-11-02).
wait = E.get("WAIT_ROLLOUT", "true").lower() == "true"
sflt = urllib.parse.quote(json.dumps(
{"label": [f"com.docker.stack.namespace={stack.get('Name', '')}"]}))
def services():
_, out = api("GET", f"{docker}/services?filters={sflt}")
return {s["ID"]: s for s in out or []}
before = {i: (s.get("UpdateStatus") or {}).get("StartedAt")
for i, s in services().items()} if wait else {}
env = [e for e in (stack.get("Env") or []) if e.get("name") not in sets]
kept = len(env)
env += [{"name": k, "value": v} for k, v in sets.items()]
with open(E["COMPOSE_FILE"]) as f:
compose = f.read()
api("PUT", f"/api/stacks/{stack_id}?endpointId={endpoint}", {
"stackFileContent": compose,
"env": env,
"prune": E.get("PRUNE", "false").lower() == "true",
"pullImage": True,
})
shown = ", ".join(f"{k}={v}" for k, v in sets.items()) or "nothing"
print(f"stack {stack.get('Name', stack_id)} updated from {E['COMPOSE_FILE']}: {shown}; {kept} other variable(s) kept")
if wait:
rollout_timeout = float(E.get("ROLLOUT_TIMEOUT") or 600)
start = time.time()
deadline, grace, shown_at = start + rollout_timeout, start + 20, 0.0
while True:
pending, failed, done = [], [], []
for i, s in services().items():
u = s.get("UpdateStatus") or {}
if not u or (i in before and u.get("StartedAt") == before[i]):
continue # untouched by this deploy, or newly created
name, state = s["Spec"]["Name"], u.get("State", "")
if state == "completed":
done.append(name)
elif state == "updating":
pending.append(name)
else: # paused, rollback_started / _paused / _completed
failed.append(f"{name}: {state} ({u.get('Message', '')})")
if failed:
raise RuntimeError("rollout failed - " + "; ".join(failed))
if pending:
if time.time() >= deadline:
raise RuntimeError(f"rollout not finished after {rollout_timeout:.0f} s: {', '.join(pending)}")
if time.time() - shown_at >= 30:
print(f"rollout: waiting for {', '.join(pending)}", flush=True)
shown_at = time.time()
elif done:
print(f"rollout: completed in {time.time() - start:.0f} s: {', '.join(done)}")
break
elif time.time() >= grace:
# The PUT can return before Swarm registers the update
# (birdnet-go: PUT logged 00:29:25.908, update started
# 25.929), hence the grace. Nothing after it = same
# image digest and configs, Swarm had nothing to update.
print("rollout: no service was updated by this deploy")
break
time.sleep(5)
# Older versions go once nothing mounts them; Docker refuses to
# delete a config in use (the previous task may still be draining),
# the next deploy retries.
for name, cid in stale:
try:
api("DELETE", f"{docker}/configs/{cid}", ok=(200, 204))
print(f"config {name} removed (superseded)")
except RuntimeError:
print(f"config {name} still in use, kept for the next deploy")
except (RuntimeError, OSError) as exc:
sys.exit(f"::error::portainer-deploy: {exc}")
url = E.get("SMOKE_URL", "")
if url:
want, deadline = E.get("SMOKE_STATUS", "200"), time.time() + float(E.get("SMOKE_TIMEOUT") or 180)
ctx = ssl.create_default_context()
ctx.check_hostname, ctx.verify_mode = False, ssl.CERT_NONE
while True:
try:
with urllib.request.urlopen(url, timeout=10, context=ctx) as r:
got = str(r.status)
except urllib.error.HTTPError as e:
got = str(e.code)
except (urllib.error.URLError, OSError):
got = "000"
if got == want:
print(f"smoke: {url} answered {got}")
break
if time.time() >= deadline:
sys.exit(f"::error::smoke: {url} answered {got}, expected {want}")
time.sleep(10)
PY
+21 -5
View File
@@ -15,6 +15,11 @@ inputs:
scan-ref:
description: Directory for scan-type fs (git-tracked files plus untracked lockfiles).
default: .
scanners:
description: >
Trivy scanners. vuln and secret findings block (per mode); misconfig
(Dockerfile, compose, k8s, ...) is only reported, never blocks.
default: vuln,secret
runtime:
description: >
auto = Trivy container when a Docker daemon is reachable, else the
@@ -45,7 +50,7 @@ inputs:
default: "false"
trivy-image:
description: Trivy container image, pinned by digest.
default: aquasec/trivy:0.75.0@sha256:af6acf9a6b85dfe389a1941505c0ce9efef52a4719635e1a962f022a3d855daa
default: aquasec/trivy:0.76.2@sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb
cache-volume:
description: >
Docker named volume for the vulnerability DB. A named volume, not a
@@ -71,9 +76,10 @@ runs:
SCAN_TYPE: ${{ inputs.scan-type }}
SCAN_REF: ${{ inputs.scan-ref }}
RUNTIME: ${{ inputs.runtime }}
TRIVY_VERSION: "0.75.0"
TRIVY_SHA256_AMD64: c6e65abddb348e25f10549df887045629cf28cc72453cd1c63acb717316b3f3f
TRIVY_SHA256_ARM64: a1ee9f6ffb7d112b64ff726a2a0717c21175c1114361391f4a132956751a13b3
SCANNERS: ${{ inputs.scanners }}
TRIVY_VERSION: "0.76.2"
TRIVY_SHA256_AMD64: bc0fc726e017b8927a62b2d3531d7a84ee01769daf5c99ed866dced54089fdbf
TRIVY_SHA256_ARM64: ab9d51f86e6a5fb936f605faff6b593ac51bc378fff4d3e8b9d58358b9c367c3
TRIVY_USERNAME: ${{ inputs.username }}
TRIVY_PASSWORD: ${{ inputs.password }}
PLATFORM: ${{ inputs.platform }}
@@ -108,7 +114,7 @@ runs:
|| { echo "::error::jq is required"; exit 1; }
fi
common="--skip-java-db-update --scanners vuln,secret --list-all-pkgs --format json --quiet"
common="--skip-java-db-update --scanners $SCANNERS --list-all-pkgs --format json --quiet"
ignore_args=""
if [ -n "$IGNOREFILE" ] && [ -f "$IGNOREFILE" ]; then
echo "ignore file: $IGNOREFILE ($(grep -c -- '- id:' "$IGNOREFILE" || true) entries)"
@@ -196,6 +202,16 @@ runs:
{ printf 'SECRET\tRULE\tTITLE\tFILE\tLINE\n'; cat "$work/secrets.tsv"; } | table
fi
# Misconfigurations: reported, never blocking.
jq -r --argjson sev "$sev_json" '[.Results[]? | .Target as $t | .Misconfigurations[]?
| select(.Status == "FAIL" and (.Severity as $x | $sev | index($x)))
| [.Severity, .ID, .Title, $t]] | unique | .[] | @tsv' "$report" >"$work/misconf.tsv"
nm=$(wc -l <"$work/misconf.tsv")
if [ "$nm" -gt 0 ]; then
echo "::warning::Trivy config: $nm $SEVERITY misconfigurations in $target (not blocking)"
{ printf 'SEVERITY\tID\tTITLE\tFILE\n'; cat "$work/misconf.tsv"; } | table
fi
blocking=$((nv + ns))
echo "report=$report" >>"$GITHUB_OUTPUT"
echo "blocking=$blocking" >>"$GITHUB_OUTPUT"