The workflow file had never been executed anywhere. It was linted, and its
steps were run by hand through scripts/ci-gates.sh, but nothing had ever taken
the YAML and played it start to finish. nektos/act (0.2.89, sha256
48ae218af96725f7635a66de2b87e1e346893b02add0f16b92f560296b2151fc) does that in a
Docker container, so the file itself got executed.
It found a defect on the first run. The lint job called `shellcheck` expecting
the copy baked into ubuntu-latest - 0.9.0-1, per the runner image's own package
list. Local shellcheck is 0.11.0 and says nothing about
scripts/geo-db-bump.sh:42; 0.9.0 flags it (SC2015: `A && B || C` is not
if-then-else). So the gate's verdict depended on which tool version the image
happened to ship, and the first push to a real runner would have gone red on a
pattern that is legal, just ambiguous.
Two changes, both version-independent:
- geo-db-bump.sh: the guard is now an explicit `if [ -z "$newest" ] || [
"$newest" = unknown ]`. Verified with the version that found it: shellcheck
0.9.0 in a Linux container now exits 0 over scripts/*.sh, and 0.11.0 on the
host exits 0. The script's behaviour is unchanged: DRY_RUN with a current pin
exits 0 ("nothing to do"), and an edition the vendor does not serve exits 2
("REFUSED - the freshness check could not name a newer release").
- ci.yml: shellcheck is pinned to 0.11.0 with a checksum per architecture, the
same way actionlint already is, and the step prints the version so the log
says which version did the linting.
Executed end to end in act on catthehacker/ubuntu:act-latest, arm64:
lint - Job succeeded (checkout, actionlint 1.7.12 sha256 OK, shellcheck
0.11.0 sha256 OK, 0 findings over scripts/*.sh)
source - Job succeeded (setup-dotnet, restore, build, unit, integration
34/34, smoke 19/19)
image - Job succeeded (docker build -> openwaf:ci 261 MB, compose smoke
43 passed / 0 failed)
This is not GitHub: it is a local Actions-compatible runner, so it proves the
file executes and the pinned tools resolve, not that a GitHub-hosted run is
green. The console job is the remaining one and is reported separately.
80 lines
3.2 KiB
Bash
Executable File
80 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Move the geo database pin to the newest release the vendor serves.
|
|
#
|
|
# The pin (Dockerfile ARG DBIP_VERSION) used to be moved by hand, once a month,
|
|
# by whoever remembered. This is the half that makes the freshness check
|
|
# actionable instead of just noisy: it rewrites the ARG and prints the two
|
|
# commands that actually make the new database land.
|
|
#
|
|
# scripts/geo-db-bump.sh # rewrite the pin, print the follow-ups
|
|
# DRY_RUN=1 scripts/geo-db-bump.sh # say what it would change, change nothing
|
|
#
|
|
# It refuses rather than guessing. If the vendor could not be reached, or the
|
|
# newest release could not be determined, nothing is written: a pin moved on the
|
|
# strength of a check that did not run is worse than a pin left alone.
|
|
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
DOCKERFILE=${DOCKERFILE:-Dockerfile}
|
|
DRY_RUN=${DRY_RUN:-0}
|
|
|
|
# `state=$?` on the next line would read the exit status of the assignment, and
|
|
# under set -e a non-zero command substitution ends the script before it gets
|
|
# there — the behind case would exit with the check's code instead of bumping.
|
|
state=0
|
|
line=$(MACHINE=1 ./scripts/geo-db-freshness.sh) || state=$?
|
|
echo "geo bump: freshness says: $line (exit $state)"
|
|
|
|
case "$state" in
|
|
0)
|
|
echo 'geo bump: nothing to do — the pin is already the newest release.'
|
|
exit 0 ;;
|
|
1) : ;; # behind: the case this script exists for
|
|
*)
|
|
echo 'geo bump: REFUSED — the freshness check could not name a newer release.' >&2
|
|
echo ' Nothing was written. Fix the check (network, or the pin) and re-run.' >&2
|
|
exit 2 ;;
|
|
esac
|
|
|
|
newest=$(printf '%s' "$line" | awk '{print $2}')
|
|
pin=$(printf '%s' "$line" | awk '{print $1}')
|
|
if [ -z "$newest" ] || [ "$newest" = unknown ]; then
|
|
echo 'geo bump: REFUSED — no release to bump to.' >&2; exit 2;
|
|
fi
|
|
|
|
if [ "$DRY_RUN" = 1 ]; then
|
|
echo "geo bump: DRY_RUN — would rewrite ARG DBIP_VERSION=$pin to $newest in $DOCKERFILE"
|
|
exit 0
|
|
fi
|
|
|
|
before=$(grep -n "^ARG DBIP_VERSION=" "$DOCKERFILE")
|
|
tmp=$(mktemp)
|
|
awk -v v="$newest" 'BEGIN{done=0} /^ARG DBIP_VERSION=/{ if(!done){sub(/^ARG DBIP_VERSION=.*/,"ARG DBIP_VERSION=" v); done=1} } {print}' "$DOCKERFILE" > "$tmp"
|
|
mv "$tmp" "$DOCKERFILE"
|
|
|
|
echo "geo bump: $DOCKERFILE"
|
|
echo " before: $before"
|
|
echo " after: $(grep -n '^ARG DBIP_VERSION=' "$DOCKERFILE")"
|
|
|
|
# The part that is easy to forget and costs an afternoon: the compose file mounts
|
|
# a named volume at /app/geoip, and Docker seeds a named volume from the image
|
|
# only when the volume is first created. Rebuilding does not replace the
|
|
# database an existing deployment runs on.
|
|
project=$(basename "$PWD")
|
|
if command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
|
|
project=$(docker compose config --name 2>/dev/null || printf '%s' "$project")
|
|
fi
|
|
|
|
cat <<END
|
|
|
|
geo bump: the pin moved. To make the new database actually run:
|
|
|
|
docker build -t openwaf:ci .
|
|
docker volume rm ${project}_openwaf-geoip # the volume is seeded once
|
|
./scripts/compose-smoke.sh # 28 assertions, incl. the geo ones
|
|
|
|
/healthz reports geoBuiltAt — that is how you confirm which database the
|
|
running container actually loaded, rather than which one the Dockerfile asked for.
|
|
END
|