Add gitea-actions: Spring Boot 4.2.0 CI with surefire/failsafe, Testcontainers, CycloneDX SBOM and Jib

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b69H5rTewUKPyhGS8r
This commit is contained in:
2026-12-01 23:59:28 +05:30
co-authored by Claude Sonnet 5.5
parent bb12eaca0a
commit 5facfdc212
30 changed files with 811 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
source "$(dirname "$0")/lib.sh"
{
banner "Toolchain"
java -version 2>&1 | grep -v '^Picked up'
"${MVN[@]}" -v 2>&1 | grep -E '^Apache Maven|^Java version' || true
echo "Docker engine $(docker version --format '{{.Server.Version}}')"
banner "Versions pinned by the module"
grep -E '<version>4\.2\.0|<java.version>|<jib.version>|<cyclonedx.version>' pom.xml | sed 's/^ *//'
banner "Images used"
grep -o 'postgres:[0-9a-z.-]*' src/test/java/com/ankurm/ci/TicketApiIT.java
grep -o 'eclipse-temurin:[0-9a-z.-]*' pom.xml
banner "Gitea server this was checked against"
curl -s https://ankurm.com/git.app/api/v1/version; echo
} 2>&1 | tee "$OUT/01-versions.txt"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# What a Maven cache is worth: the same build against an empty and a populated local repository.
source "$(dirname "$0")/lib.sh"
REPO="${COLD_REPO:-/tmp/m2-cold-demo}"
rm -rf "$REPO"
run() { # label
local start end n
start=$(date +%s)
mvn -B -Dmaven.repo.local="$REPO" -DskipITs verify > /tmp/cache-run.log 2>&1 || { tail -20 /tmp/cache-run.log; exit 1; }
end=$(date +%s)
n=$(grep -c 'Downloaded from' /tmp/cache-run.log || true)
printf '%-34s downloads: %-5s seconds: %s\n' "$1" "$n" "$((end-start))"
}
{
banner "mvn verify -DskipITs, local repository = $REPO"
run "cold (empty local repository)"
run "warm (repository restored)"
printf 'local repository size after the run: %s\n' "$(du -sh "$REPO" | cut -f1)"
echo "(seconds depend on the network; the download counts are the point)"
} 2>&1 | tee "$OUT/02-cold-vs-warm-cache.txt"
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# The command the pipeline runs, and what it produces. Then the same command with no Docker.
source "$(dirname "$0")/lib.sh"
{
banner "mvn -B -ntp verify (key lines)"
"${MVN[@]}" clean verify 2>&1 | clean | grep -E '^\[INFO\] --- |Tests run:|BUILD|cyclonedx.*attaching|Replacing main' | sed -E 's/ @ gitea-actions-demo//; s/ in com.ankurm.ci.*/ in <class>/; s/, Time elapsed: [0-9.]+ s//'
banner "target/ after the build"
ls target | grep -E '\.(jar|original)$' | sort
# Why the socket is masked instead of just setting DOCKER_HOST to a bad value: Testcontainers tries the
# DOCKER_HOST strategy first and then falls back to the default /var/run/docker.sock. A first draft of
# this script only set DOCKER_HOST=unix:///nonexistent.sock and the build still passed.
banner "Same command where Docker is really unreachable (docker.sock masked in a private mount namespace)"
unshare -m bash -c 'mount --bind /dev/null /var/run/docker.sock && DOCKER_HOST=unix:///var/run/docker.sock mvn -B -ntp verify' 2>&1 | clean \
| grep -E 'Tests run:|Could not find a valid Docker|BUILD|ERROR\] +(TicketApiIT|Tests run)' | sed -E 's/, Time elapsed: [0-9.]+ s//; s/ in com.ankurm.ci.*/ in <class>/' | cut -c1-200 | awk '!seen[$0]++'
} 2>&1 | tee "$OUT/03-build-test.txt"
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Look inside the CycloneDX SBOM the build produced, and show the one-line mistake that drops it from the jar.
source "$(dirname "$0")/lib.sh"
SBOM=target/classes/META-INF/sbom/application.cdx.json
JAR=target/gitea-actions-demo-1.0.0.jar
{
banner "mvn -DskipTests package (default: Spring Boot parent wiring)"
"${MVN[@]}" -DskipTests clean package 2>&1 | clean | grep -E '^\[INFO\] --- (spring-boot|cyclonedx|jar)|CycloneDX: (Creating|Writing)' | sed -E 's/ @ gitea-actions-demo//; s#/.*/target#target#'
echo "jar contains: $(unzip -l $JAR | awk '/sbom\/application/ {print $4}')"
banner "Inside $SBOM"
python3 - <<'PY'
import json, collections
b = json.load(open("target/classes/META-INF/sbom/application.cdx.json"))
print("bomFormat :", b["bomFormat"])
print("specVersion :", b["specVersion"])
m = b["metadata"]["component"]
print("subject :", m["group"] + ":" + m["name"] + ":" + m["version"], "(" + m["type"] + ")")
c = b["components"]
print("components :", len(c))
print("by scope :", dict(collections.Counter(x.get("scope", "-") for x in c)))
print("all have purl :", all("purl" in x for x in c))
print("all have hash :", all(x.get("hashes") for x in c))
for want in ("spring-boot", "postgresql", "tomcat-embed-core", "jackson-databind", "testcontainers"):
hit = [x for x in c if x["name"] == want]
print(f"{want:18s}:", hit[0]["purl"] if hit else "(not in SBOM)")
print("dependency edges:", len(b.get("dependencies", [])))
PY
banner "The mistake: -Plate-sbom (re-declares the execution with phase=package)"
"${MVN[@]}" -DskipTests -Plate-sbom clean package 2>&1 | clean | grep -E '^\[INFO\] --- (spring-boot|cyclonedx|jar)' | sed -E 's/ @ gitea-actions-demo//'
echo "jar contains: $(unzip -l $JAR | awk '/sbom\/application/ {print $4}' | head -1)"
echo "(empty above = the SBOM is not in the jar)"
"${MVN[@]}" -q -DskipTests clean package >/dev/null 2>&1
} 2>&1 | tee "$OUT/04-sbom.txt"
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Build and push the image with Jib to a throwaway registry:2 container, then read it back.
source "$(dirname "$0")/lib.sh"
docker rm -f ci-demo-registry >/dev/null 2>&1 || true
docker run -d --name ci-demo-registry -p 5000:5000 registry:2 >/dev/null
for i in $(seq 1 30); do curl -sf localhost:5000/v2/ >/dev/null && break; sleep 1; done
{
banner "1. mvn -DskipTests jib:build, base image pulled from Docker Hub (non-deterministic: depends on the rate limit)"
"${MVN[@]}" -DskipTests jib:build 2>&1 | clean | grep -E 'Built and pushed|BUILD|ERROR\] (Failed|GET|\{)' | cut -c1-210 || true
banner "2. same, base image read from the runner's local Docker daemon (-Djib.from.image=docker://...)"
"${MVN[@]}" -DskipTests jib:build -Djib.from.image=docker://eclipse-temurin:25-jre 2>&1 | clean | grep -E 'Built and pushed|Container entrypoint|BUILD|ERROR' | cut -c1-200
banner "Registry catalog and tags"
curl -s localhost:5000/v2/_catalog; echo
curl -s localhost:5000/v2/gitea-actions-demo/tags/list; echo
banner "Layers in the pushed manifest"
curl -s -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' localhost:5000/v2/gitea-actions-demo/manifests/1.0.0 \
| python3 -c "import sys,json; m=json.load(sys.stdin); [print(f'{l[\"size\"]:>10} {l[\"digest\"][:19]}...') for l in m['layers']]; print('layers:', len(m['layers']))"
banner "Image config (user, ports, entrypoint)"
docker pull -q localhost:5000/gitea-actions-demo:1.0.0 >/dev/null
docker inspect localhost:5000/gitea-actions-demo:1.0.0 --format 'user={{.Config.User}} ports={{.Config.ExposedPorts}} entrypoint={{.Config.Entrypoint}}'
} 2>&1 | tee "$OUT/05-image-local-registry.txt"
docker rm -f ci-demo-registry >/dev/null 2>&1 || true
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# What actually happens when the pipeline pushes to a Gitea that lives under a URL sub-path.
# Needs GITEA_TOKEN (a personal access token with write:package). Never printed, never committed.
source "$(dirname "$0")/lib.sh"
: "${GITEA_TOKEN:?export GITEA_TOKEN first}"
BASE="${GITEA_BASE:-https://ankurm.com/git.app}"; HOST="${GITEA_HOST:-ankurm.com}"; OWNER="${GITEA_OWNER:-asmhatre}"
VER="1.0.0-demo"
{
banner "1. Where does the container registry answer?"
printf '%s/v2/ -> HTTP %s\n' "https://$HOST" "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" "https://$HOST/v2/")"
printf '%s/v2/ -> HTTP %s\n' "$BASE" "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" "$BASE/v2/")"
banner "2. docker login and docker push the way every tutorial writes it"
echo "\$ docker login $HOST"
echo "$GITEA_TOKEN" | docker login "$HOST" -u "$OWNER" --password-stdin 2>&1 | grep -v '^$' || true
docker tag postgres:17-alpine "$HOST/$OWNER/gitea-actions-probe:1"
echo "\$ docker push $HOST/$OWNER/gitea-actions-probe:1"
docker push "$HOST/$OWNER/gitea-actions-probe:1" 2>&1 | tail -1 || true
docker rmi "$HOST/$OWNER/gitea-actions-probe:1" >/dev/null 2>&1 || true
banner "3. The generic package registry works under the sub-path: upload the SBOM"
URL="$BASE/api/packages/$OWNER/generic/gitea-actions-demo-sbom/$VER/application.cdx.json"
echo "\$ curl --upload-file target/classes/META-INF/sbom/application.cdx.json $BASE/api/packages/$OWNER/generic/gitea-actions-demo-sbom/$VER/application.cdx.json"
printf 'PUT first time -> HTTP %s\n' "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" --upload-file target/classes/META-INF/sbom/application.cdx.json "$URL")"
printf 'PUT second time -> HTTP %s (a file name can be published once per version)\n' "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" --upload-file target/classes/META-INF/sbom/application.cdx.json "$URL")"
curl -s -u "$OWNER:$GITEA_TOKEN" "$URL" | python3 -c "import sys,json; b=json.load(sys.stdin); print('downloaded back:', b['bomFormat'], b['specVersion'], len(b['components']), 'components')"
printf 'DELETE version -> HTTP %s\n' "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" -X DELETE "$BASE/api/packages/$OWNER/generic/gitea-actions-demo-sbom/$VER")"
banner "4. Bad file name"
printf 'PUT file with a space in its name -> HTTP %s\n' "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" --upload-file target/classes/META-INF/sbom/application.cdx.json "$BASE/api/packages/$OWNER/generic/gitea-actions-demo-sbom/$VER/application%20x.cdx.json")"
printf 'DELETE version (cleanup) -> HTTP %s\n' "$(curl -s -o /dev/null -w '%{http_code}' -u "$OWNER:$GITEA_TOKEN" -X DELETE "$BASE/api/packages/$OWNER/generic/gitea-actions-demo-sbom/$VER")"
printf 'packages left named gitea-actions-demo-sbom: %s\n' "$(curl -s -u "$OWNER:$GITEA_TOKEN" "$BASE/api/v1/packages/$OWNER?q=gitea-actions-demo-sbom" | python3 -c 'import sys,json; print(len(json.load(sys.stdin)))')"
} 2>&1 | sed "s/$GITEA_TOKEN/***/g" | tee "$OUT/06-gitea-registries.txt"
docker logout "$HOST" >/dev/null 2>&1 || true
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Static checks on the workflow. This is NOT a runner: it proves the YAML parses and that every
# command the workflow runs is one the other scripts executed. It cannot prove Gitea accepts it.
source "$(dirname "$0")/lib.sh"
{
banner "Parse .gitea/workflows/ci.yaml"
python3 - <<'PY'
import yaml
w = yaml.safe_load(open(".gitea/workflows/ci.yaml"))
print("name :", w["name"])
print("triggers :", list(w[True].keys()) if True in w else list(w["on"].keys()))
for j, d in w["jobs"].items():
print(f"job {j:6s}: runs-on={d['runs-on']} needs={d.get('needs','-')} steps={len(d['steps'])}")
for s in d["steps"]:
print(" -", s.get("uses") or s.get("name") or "run")
PY
banner "Secrets are only ever referenced through env:, never inside a run: line"
if grep -nE '^\s+(run|-).*\$\{\{ *secrets\.' .gitea/workflows/ci.yaml | grep -v 'env:' | grep -E 'run:|mvn|curl'; then echo "FOUND inline secret"; else echo "ok: no secret interpolated into a shell command"; fi
banner "Secret names obey Gitea's rules (no GITHUB_/GITEA_ prefix)"
grep -oE 'secrets\.[A-Za-z0-9_]+' .gitea/workflows/ci.yaml | sort -u
} 2>&1 | tee "$OUT/07-workflow-lint.txt"
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Shared setup for the scenario scripts. Source it; do not run it.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODULE="$(cd "$HERE/.." && pwd)"
OUT="$MODULE/output"
mkdir -p "$OUT"
cd "$MODULE"
# The post was tested with Temurin 25.0.5.1+2. Set JAVA_HOME to use another JDK 25.
export PATH="${JAVA_HOME:+$JAVA_HOME/bin:}$PATH"
MVN=(mvn -B -ntp)
# Strip JVM-launcher noise and wall-clock lines so reruns diff cleanly.
clean() { grep -v -E '^Picked up|^WARNING:|Finished at:|^\[INFO\] *$|^\[INFO\] Total time' || true; }
banner() { printf '\n=== %s ===\n' "$*"; }
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Regenerates every file in output/. 06 needs GITEA_TOKEN; it is skipped when unset.
set -euo pipefail
cd "$(dirname "$0")"
./01-versions.sh >/dev/null
./02-cold-vs-warm-cache.sh >/dev/null
./03-build-test.sh >/dev/null
./04-sbom.sh >/dev/null
./05-image-local-registry.sh >/dev/null
if [ -n "${GITEA_TOKEN:-}" ]; then ./06-gitea-registries.sh >/dev/null; else echo "skipping 06 (no GITEA_TOKEN)"; fi
./07-workflow-lint.sh >/dev/null
ls -1 ../output