From 5facfdc212e6076922b45d7da74298aa301f61c4 Mon Sep 17 00:00:00 2001 From: Ankur Mhatre Date: Tue, 1 Dec 2026 23:55:59 +0530 Subject: [PATCH] Add gitea-actions: Spring Boot 4.2.0 CI with surefire/failsafe, Testcontainers, CycloneDX SBOM and Jib Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ic4b69H5rTewUKPyhGS8r --- README.md | 1 + gitea-actions/.gitea/workflows/ci.yaml | 74 +++++++++ gitea-actions/.gitignore | 1 + gitea-actions/README.md | 52 ++++++ gitea-actions/output/01-versions.txt | 20 +++ .../output/02-cold-vs-warm-cache.txt | 6 + gitea-actions/output/03-build-test.txt | 33 ++++ gitea-actions/output/04-sbom.txt | 30 ++++ .../output/05-image-local-registry.txt | 31 ++++ gitea-actions/output/06-gitea-registries.txt | 22 +++ gitea-actions/output/07-workflow-lint.txt | 21 +++ gitea-actions/pom.xml | 151 ++++++++++++++++++ gitea-actions/scripts/01-versions.sh | 15 ++ .../scripts/02-cold-vs-warm-cache.sh | 20 +++ gitea-actions/scripts/03-build-test.sh | 15 ++ gitea-actions/scripts/04-sbom.sh | 33 ++++ .../scripts/05-image-local-registry.sh | 22 +++ gitea-actions/scripts/06-gitea-registries.sh | 31 ++++ gitea-actions/scripts/07-workflow-lint.sh | 21 +++ gitea-actions/scripts/lib.sh | 14 ++ gitea-actions/scripts/run-all.sh | 12 ++ .../main/java/com/ankurm/ci/Application.java | 12 ++ .../java/com/ankurm/ci/PriorityRules.java | 22 +++ .../src/main/java/com/ankurm/ci/Ticket.java | 5 + .../java/com/ankurm/ci/TicketController.java | 33 ++++ .../java/com/ankurm/ci/TicketRepository.java | 30 ++++ .../src/main/resources/application.properties | 3 + gitea-actions/src/main/resources/schema.sql | 5 + .../java/com/ankurm/ci/PriorityRulesTest.java | 25 +++ .../test/java/com/ankurm/ci/TicketApiIT.java | 51 ++++++ 30 files changed, 811 insertions(+) create mode 100644 gitea-actions/.gitea/workflows/ci.yaml create mode 100644 gitea-actions/.gitignore create mode 100644 gitea-actions/README.md create mode 100644 gitea-actions/output/01-versions.txt create mode 100644 gitea-actions/output/02-cold-vs-warm-cache.txt create mode 100644 gitea-actions/output/03-build-test.txt create mode 100644 gitea-actions/output/04-sbom.txt create mode 100644 gitea-actions/output/05-image-local-registry.txt create mode 100644 gitea-actions/output/06-gitea-registries.txt create mode 100644 gitea-actions/output/07-workflow-lint.txt create mode 100644 gitea-actions/pom.xml create mode 100755 gitea-actions/scripts/01-versions.sh create mode 100755 gitea-actions/scripts/02-cold-vs-warm-cache.sh create mode 100755 gitea-actions/scripts/03-build-test.sh create mode 100755 gitea-actions/scripts/04-sbom.sh create mode 100755 gitea-actions/scripts/05-image-local-registry.sh create mode 100755 gitea-actions/scripts/06-gitea-registries.sh create mode 100755 gitea-actions/scripts/07-workflow-lint.sh create mode 100755 gitea-actions/scripts/lib.sh create mode 100755 gitea-actions/scripts/run-all.sh create mode 100644 gitea-actions/src/main/java/com/ankurm/ci/Application.java create mode 100644 gitea-actions/src/main/java/com/ankurm/ci/PriorityRules.java create mode 100644 gitea-actions/src/main/java/com/ankurm/ci/Ticket.java create mode 100644 gitea-actions/src/main/java/com/ankurm/ci/TicketController.java create mode 100644 gitea-actions/src/main/java/com/ankurm/ci/TicketRepository.java create mode 100644 gitea-actions/src/main/resources/application.properties create mode 100644 gitea-actions/src/main/resources/schema.sql create mode 100644 gitea-actions/src/test/java/com/ankurm/ci/PriorityRulesTest.java create mode 100644 gitea-actions/src/test/java/com/ankurm/ci/TicketApiIT.java diff --git a/README.md b/README.md index f54ca08..a258bdb 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ Runnable companion projects for build, release and DevOps posts on [ankurm.com]( | [vuln-scan](vuln-scan/) | Dependency Vulnerability Scanning for Java: OWASP Dependency-Check vs Trivy vs OSV-Scanner | The same project scanned by Dependency-Check 13.0.0, Trivy 0.76.2 and OSV-Scanner 2.7.1: false positives, suppression with expiry, CI gating, SBOM-based scanning | | [jbang](jbang/) | JBang: Run Java Like a Script in 2026 (Dependencies, Templates, Spring Boot and Native Images) | JBang 0.132.1 on JDK 25: `//DEPS`, compact source files, `//SOURCES`, a single-file Spring Boot 4.2 app, templates and aliases, remote scripts and `jbang trust`, `--native` with GraalVM | | [jib](jib/) | Jib for Spring Boot: Container Images Without a Dockerfile (vs Buildpacks) | Spring Boot 4.2.0 built into an image with Jib 3.5.2 and with Buildpacks: layers, reproducible digests, registry push, failure modes, memory behaviour | +| [gitea-actions](gitea-actions/) | Gitea Actions CI for Spring Boot: Build, Test, SBOM and Image Push | Spring Boot 4.2.0 pipeline: surefire/failsafe split, Testcontainers, Maven cache, CycloneDX SBOM, Jib push, and what breaks when Gitea runs under a URL sub-path | MIT licensed. diff --git a/gitea-actions/.gitea/workflows/ci.yaml b/gitea-actions/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..63f0278 --- /dev/null +++ b/gitea-actions/.gitea/workflows/ci.yaml @@ -0,0 +1,74 @@ +# Gitea Actions pipeline for the gitea-actions-demo service. +# +# IMPORTANT: Gitea only looks for workflows in /.gitea/workflows/. +# This file sits inside a module of a shared repository, so Gitea will NOT run it here. +# Copy it to the root of your own project (and drop the working-directory lines). +# It was NOT executed by a Gitea runner while writing the post; every command in it was +# executed by scripts/*.sh instead. See the post for what that does and does not prove. +name: ci + +on: + push: + branches: [main] + tags: ['v*'] + pull_request: + +concurrency: + group: ci-${{ gitea.ref }} + cancel-in-progress: true + +defaults: + run: + working-directory: gitea-actions + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '25' + cache: maven # caches ~/.m2/repository, keyed on pom.xml + + # Unit tests (surefire), jar, SBOM, then integration tests (failsafe + Testcontainers). + - name: Build, test, SBOM + run: mvn -B -ntp verify + + # GITEA_TOKEN cannot publish packages, so a personal access token with + # write:package lives in a repository secret named PACKAGES_TOKEN. + - name: Publish SBOM to the generic package registry + if: gitea.event_name == 'push' + env: + PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }} + run: | + VERSION="$(mvn -q -ntp help:evaluate -Dexpression=project.version -DforceStdout)" + curl --fail --user "${{ gitea.repository_owner }}:${PACKAGES_TOKEN}" \ + --upload-file target/classes/META-INF/sbom/application.cdx.json \ + "${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/gitea-actions-demo-sbom/${VERSION}-${{ gitea.run_number }}/application.cdx.json" + + image: + needs: build + if: gitea.event_name == 'push' && startsWith(gitea.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '25' + cache: maven + + # Jib builds and pushes the image straight to the registry: no Docker daemon needed. + # vars.IMAGE_NAME is e.g. registry.example.com/owner/gitea-actions-demo + - name: Build and push image with Jib + env: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + run: > + mvn -B -ntp -DskipTests jib:build + -Dimage.name=${{ vars.IMAGE_NAME }} + -Djib.to.auth.username="$REGISTRY_USER" + -Djib.to.auth.password="$REGISTRY_PASSWORD" diff --git a/gitea-actions/.gitignore b/gitea-actions/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/gitea-actions/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/gitea-actions/README.md b/gitea-actions/README.md new file mode 100644 index 0000000..284d674 --- /dev/null +++ b/gitea-actions/README.md @@ -0,0 +1,52 @@ +# gitea-actions + +Companion module for the ankurm.com post **Gitea Actions CI for Spring Boot: Build, Test, SBOM and Image Push**. +All the explanation lives in the post; this module holds the code and the captured output the post quotes. + +| Piece | Version | +|---|---| +| Spring Boot | 4.2.0 | +| JDK | Temurin 25.0.5.1+2 | +| Maven | 3.9.11 | +| Jib | 3.5.2 | +| cyclonedx-maven-plugin | 2.9.3 (managed by the Spring Boot parent) | +| Testcontainers PostgreSQL | `postgres:17-alpine` | +| Gitea server checked | 1.27.3 | + +## Quickstart + +```bash +export JAVA_HOME=/path/to/jdk-25 # a JDK 25 +mvn -B -ntp verify # unit tests, jar, SBOM, integration tests (needs Docker) +mvn -B -ntp -DskipTests -Plate-sbom package # the SBOM mistake the post explains +./scripts/run-all.sh # regenerates output/ (06 needs GITEA_TOKEN) +``` + +## What is here + +| Path | What it is | +|---|---| +| `src/main`, `src/test` | A tiny ticket service: `PriorityRulesTest` (unit, surefire), `TicketApiIT` (PostgreSQL via Testcontainers, failsafe) | +| `.gitea/workflows/ci.yaml` | The pipeline. Inert here (Gitea reads only the repository root). Copy it to the root of your project | +| `scripts/` | One script per scenario the post shows | +| `output/` | Real captured output of those scripts | + +## Output index + +| File | Shows | +|---|---| +| `output/01-versions.txt` | Toolchain and pinned versions | +| `output/02-cold-vs-warm-cache.txt` | Maven downloads with an empty and a populated local repository | +| `output/03-build-test.txt` | The pipeline's build command, then the same command with Docker unreachable | +| `output/04-sbom.txt` | SBOM contents, and the `-Plate-sbom` mistake | +| `output/05-image-local-registry.txt` | Jib push to a throwaway `registry:2` and read-back | +| `output/06-gitea-registries.txt` | Docker push to Gitea under a URL sub-path (fails), generic package upload (works) | +| `output/07-workflow-lint.txt` | Static checks of the workflow | + +## Honest limits + +- The workflow file was **not** executed by a Gitea runner. Each command in it was executed by the scripts above, in the same order, on a machine with Docker. That proves the commands, not Gitea's handling of the YAML. +- `06-gitea-registries.sh` needs a personal access token in `GITEA_TOKEN`. The token is never written to a file. +- Timings in `02` depend on the network; the download counts do not. + +MIT licensed. diff --git a/gitea-actions/output/01-versions.txt b/gitea-actions/output/01-versions.txt new file mode 100644 index 0000000..9397490 --- /dev/null +++ b/gitea-actions/output/01-versions.txt @@ -0,0 +1,20 @@ + +=== Toolchain === +openjdk version "25.0.5.1" 2026-11-17 LTS +OpenJDK Runtime Environment Temurin-25.0.5.1+2 (build 25.0.5.1+2-LTS) +OpenJDK 64-Bit Server VM Temurin-25.0.5.1+2 (build 25.0.5.1+2-LTS, mixed mode, sharing) +Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b) +Java version: 25.0.5.1, vendor: Eclipse Adoptium, runtime: /tmp/tools/jdk-25.0.5.1+2 +Docker engine 29.9.3 + +=== Versions pinned by the module === +4.2.0 +25 +3.5.2 + +=== Images used === +postgres:17-alpine +eclipse-temurin:25-jre + +=== Gitea server this was checked against === +{"version":"1.27.3"} diff --git a/gitea-actions/output/02-cold-vs-warm-cache.txt b/gitea-actions/output/02-cold-vs-warm-cache.txt new file mode 100644 index 0000000..7339715 --- /dev/null +++ b/gitea-actions/output/02-cold-vs-warm-cache.txt @@ -0,0 +1,6 @@ + +=== mvn verify -DskipITs, local repository = /tmp/m2-cold-demo === +cold (empty local repository) downloads: 599 seconds: 44 +warm (repository restored) downloads: 0 seconds: 11 +local repository size after the run: 110M +(seconds depend on the network; the download counts are the point) diff --git a/gitea-actions/output/03-build-test.txt b/gitea-actions/output/03-build-test.txt new file mode 100644 index 0000000..5e45a98 --- /dev/null +++ b/gitea-actions/output/03-build-test.txt @@ -0,0 +1,33 @@ + +=== mvn -B -ntp verify (key lines) === +[INFO] --- clean:3.5.0:clean (default-clean) --- +[INFO] --- cyclonedx:2.9.3:makeAggregateBom (default) --- +[INFO] --- resources:3.5.0:resources (default-resources) --- +[INFO] --- compiler:3.16.0:compile (default-compile) --- +[INFO] --- resources:3.5.0:testResources (default-testResources) --- +[INFO] --- compiler:3.16.0:testCompile (default-testCompile) --- +[INFO] --- surefire:3.6.1:test (default-test) --- +[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 -- in +[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 +[INFO] --- jar:3.5.1:jar (default-jar) --- +[INFO] --- spring-boot:4.2.0:repackage (repackage) --- +[INFO] Replacing main artifact /tmp/dd/gitea-actions/target/gitea-actions-demo-1.0.0.jar with repackaged archive, adding nested dependencies in BOOT-INF/. +[INFO] --- failsafe:3.6.1:integration-test (default) --- +[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- in +[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 +[INFO] --- failsafe:3.6.1:verify (default) --- +[INFO] BUILD SUCCESS + +=== target/ after the build === +gitea-actions-demo-1.0.0.jar +gitea-actions-demo-1.0.0.jar.original + +=== Same command where Docker is really unreachable (docker.sock masked in a private mount namespace) === +[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 -- in +[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 +23:57:14.999 [main] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -- Could not find a valid Docker environment. Please check configuration. Attempted configurations were: +[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 <<< FAILURE! -- in +java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration +[ERROR] TicketApiIT.initializationError ? IllegalState Could not find a valid Docker environment. Please see logs and check configuration +[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0 +[INFO] BUILD FAILURE diff --git a/gitea-actions/output/04-sbom.txt b/gitea-actions/output/04-sbom.txt new file mode 100644 index 0000000..6ec92d3 --- /dev/null +++ b/gitea-actions/output/04-sbom.txt @@ -0,0 +1,30 @@ + +=== mvn -DskipTests package (default: Spring Boot parent wiring) === +[INFO] --- cyclonedx:2.9.3:makeAggregateBom (default) --- +[INFO] CycloneDX: Creating BOM version 1.6 with 59 component(s) +[INFO] CycloneDX: Writing and validating BOM (JSON): target/classes/META-INF/sbom/application.cdx.json +[INFO] --- jar:3.5.1:jar (default-jar) --- +[INFO] --- spring-boot:4.2.0:repackage (repackage) --- +jar contains: META-INF/sbom/application.cdx.json + +=== Inside target/classes/META-INF/sbom/application.cdx.json === +bomFormat : CycloneDX +specVersion : 1.6 +subject : com.ankurm.ci:gitea-actions-demo:1.0.0 (application) +components : 59 +by scope : {'required': 59} +all have purl : True +all have hash : True +spring-boot : pkg:maven/org.springframework.boot/spring-boot@4.2.0?type=jar +postgresql : pkg:maven/org.postgresql/postgresql@42.7.14?type=jar +tomcat-embed-core : pkg:maven/org.apache.tomcat.embed/tomcat-embed-core@11.0.27?type=jar +jackson-databind : pkg:maven/tools.jackson.core/jackson-databind@3.1.8?type=jar +testcontainers : (not in SBOM) +dependency edges: 60 + +=== The mistake: -Plate-sbom (re-declares the execution with phase=package) === +[INFO] --- jar:3.5.1:jar (default-jar) --- +[INFO] --- spring-boot:4.2.0:repackage (repackage) --- +[INFO] --- cyclonedx:2.9.3:makeAggregateBom (default) --- +jar contains: +(empty above = the SBOM is not in the jar) diff --git a/gitea-actions/output/05-image-local-registry.txt b/gitea-actions/output/05-image-local-registry.txt new file mode 100644 index 0000000..56833df --- /dev/null +++ b/gitea-actions/output/05-image-local-registry.txt @@ -0,0 +1,31 @@ + +=== 1. mvn -DskipTests jib:build, base image pulled from Docker Hub (non-deterministic: depends on the rate limit) === +[INFO] Built and pushed image as localhost:5000/gitea-actions-demo, localhost:5000/gitea-actions-demo:1.0.0 +[INFO] BUILD SUCCESS + +=== 2. same, base image read from the runner's local Docker daemon (-Djib.from.image=docker://...) === +[INFO] Container entrypoint set to [java, -cp, @/app/jib-classpath-file, com.ankurm.ci.Application] +[INFO] Built and pushed image as localhost:5000/gitea-actions-demo, localhost:5000/gitea-actions-demo:1.0.0 +[INFO] BUILD SUCCESS + +=== Registry catalog and tags === +{"repositories":["gitea-actions-demo"]} + +{"name":"gitea-actions-demo","tags":["latest","1.0.0"]} + + +=== Layers in the pushed manifest === + 42166579 sha256:517b871c26ea... + 389 sha256:96aae9022e0e... + 18461849 sha256:5050cb6f0906... + 63112449 sha256:dbda3fb9544c... + 32 sha256:4f4fb700ef54... + 2464 sha256:fa06fe8ddd50... + 22267190 sha256:5c4c7fb44e21... + 33240 sha256:79d4cb011a48... + 3760 sha256:97981627ec22... + 824 sha256:11c50fd61d93... +layers: 10 + +=== Image config (user, ports, entrypoint) === +user=1000 ports=map[8080/tcp:{}] entrypoint=[java -cp @/app/jib-classpath-file com.ankurm.ci.Application] diff --git a/gitea-actions/output/06-gitea-registries.txt b/gitea-actions/output/06-gitea-registries.txt new file mode 100644 index 0000000..6840751 --- /dev/null +++ b/gitea-actions/output/06-gitea-registries.txt @@ -0,0 +1,22 @@ + +=== 1. Where does the container registry answer? === +https://ankurm.com/v2/ -> HTTP 404 +https://ankurm.com/git.app/v2/ -> HTTP 200 + +=== 2. docker login and docker push the way every tutorial writes it === +$ docker login ankurm.com +Error response from daemon: login attempt to https://ankurm.com/v2/ failed with status: 404 Not Found +$ docker push ankurm.com/asmhatre/gitea-actions-probe:1 +unknown: unexpected status from POST request to https://ankurm.com/v2/asmhatre/gitea-actions-probe/blobs/uploads/: 404 Not Found + +=== 3. The generic package registry works under the sub-path: upload the SBOM === +$ curl --upload-file target/classes/META-INF/sbom/application.cdx.json https://ankurm.com/git.app/api/packages/asmhatre/generic/gitea-actions-demo-sbom/1.0.0-demo/application.cdx.json +PUT first time -> HTTP 201 +PUT second time -> HTTP 409 (a file name can be published once per version) +downloaded back: CycloneDX 1.6 59 components +DELETE version -> HTTP 204 + +=== 4. Bad file name === +PUT file with a space in its name -> HTTP 201 +DELETE version (cleanup) -> HTTP 204 +packages left named gitea-actions-demo-sbom: 0 diff --git a/gitea-actions/output/07-workflow-lint.txt b/gitea-actions/output/07-workflow-lint.txt new file mode 100644 index 0000000..764cf8d --- /dev/null +++ b/gitea-actions/output/07-workflow-lint.txt @@ -0,0 +1,21 @@ + +=== Parse .gitea/workflows/ci.yaml === +name : ci +triggers : ['push', 'pull_request'] +job build : runs-on=ubuntu-latest needs=- steps=4 + - actions/checkout@v4 + - actions/setup-java@v4 + - Build, test, SBOM + - Publish SBOM to the generic package registry +job image : runs-on=ubuntu-latest needs=build steps=3 + - actions/checkout@v4 + - actions/setup-java@v4 + - Build and push image with Jib + +=== Secrets are only ever referenced through env:, never inside a run: line === +ok: no secret interpolated into a shell command + +=== Secret names obey Gitea's rules (no GITHUB_/GITEA_ prefix) === +secrets.PACKAGES_TOKEN +secrets.REGISTRY_PASSWORD +secrets.REGISTRY_USER diff --git a/gitea-actions/pom.xml b/gitea-actions/pom.xml new file mode 100644 index 0000000..4493f49 --- /dev/null +++ b/gitea-actions/pom.xml @@ -0,0 +1,151 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 4.2.0 + + + + com.ankurm.ci + gitea-actions-demo + 1.0.0 + gitea-actions-demo: a small Spring Boot service with a CI pipeline + + + 25 + 3.5.2 + + localhost:5000/gitea-actions-demo + + + + + org.springframework.boot + spring-boot-starter-webmvc + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.postgresql + postgresql + runtime + + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + + + org.springframework.boot + spring-boot-testcontainers + test + + + org.testcontainers + testcontainers-postgresql + test + + + org.testcontainers + testcontainers-junit-jupiter + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + org.cyclonedx + cyclonedx-maven-plugin + + + + + com.google.cloud.tools + jib-maven-plugin + ${jib.version} + + + eclipse-temurin:25-jre + + + ${image.name} + + ${project.version} + + + + + 8080 + + 1000 + + gitea-actions-demo + https://ankurm.com/git.app/asmhatre/java-devops-demo + + + true + + + + + + + + + late-sbom + + + + org.cyclonedx + cyclonedx-maven-plugin + + + package + + makeAggregateBom + + + + + + + + + diff --git a/gitea-actions/scripts/01-versions.sh b/gitea-actions/scripts/01-versions.sh new file mode 100755 index 0000000..757fd38 --- /dev/null +++ b/gitea-actions/scripts/01-versions.sh @@ -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 '4\.2\.0|||' 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" diff --git a/gitea-actions/scripts/02-cold-vs-warm-cache.sh b/gitea-actions/scripts/02-cold-vs-warm-cache.sh new file mode 100755 index 0000000..09cd7ed --- /dev/null +++ b/gitea-actions/scripts/02-cold-vs-warm-cache.sh @@ -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" diff --git a/gitea-actions/scripts/03-build-test.sh b/gitea-actions/scripts/03-build-test.sh new file mode 100755 index 0000000..10ef9f4 --- /dev/null +++ b/gitea-actions/scripts/03-build-test.sh @@ -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 /; 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 /' | cut -c1-200 | awk '!seen[$0]++' +} 2>&1 | tee "$OUT/03-build-test.txt" diff --git a/gitea-actions/scripts/04-sbom.sh b/gitea-actions/scripts/04-sbom.sh new file mode 100755 index 0000000..e0bc19d --- /dev/null +++ b/gitea-actions/scripts/04-sbom.sh @@ -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" diff --git a/gitea-actions/scripts/05-image-local-registry.sh b/gitea-actions/scripts/05-image-local-registry.sh new file mode 100755 index 0000000..4fee5aa --- /dev/null +++ b/gitea-actions/scripts/05-image-local-registry.sh @@ -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 diff --git a/gitea-actions/scripts/06-gitea-registries.sh b/gitea-actions/scripts/06-gitea-registries.sh new file mode 100755 index 0000000..7d964fe --- /dev/null +++ b/gitea-actions/scripts/06-gitea-registries.sh @@ -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 diff --git a/gitea-actions/scripts/07-workflow-lint.sh b/gitea-actions/scripts/07-workflow-lint.sh new file mode 100755 index 0000000..349260a --- /dev/null +++ b/gitea-actions/scripts/07-workflow-lint.sh @@ -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" diff --git a/gitea-actions/scripts/lib.sh b/gitea-actions/scripts/lib.sh new file mode 100755 index 0000000..0f617a9 --- /dev/null +++ b/gitea-actions/scripts/lib.sh @@ -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' "$*"; } diff --git a/gitea-actions/scripts/run-all.sh b/gitea-actions/scripts/run-all.sh new file mode 100755 index 0000000..d39596c --- /dev/null +++ b/gitea-actions/scripts/run-all.sh @@ -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 diff --git a/gitea-actions/src/main/java/com/ankurm/ci/Application.java b/gitea-actions/src/main/java/com/ankurm/ci/Application.java new file mode 100644 index 0000000..0baebaf --- /dev/null +++ b/gitea-actions/src/main/java/com/ankurm/ci/Application.java @@ -0,0 +1,12 @@ +package com.ankurm.ci; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** Entry point. The service itself is deliberately tiny: the pipeline is the subject, not the app. */ +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/gitea-actions/src/main/java/com/ankurm/ci/PriorityRules.java b/gitea-actions/src/main/java/com/ankurm/ci/PriorityRules.java new file mode 100644 index 0000000..6837095 --- /dev/null +++ b/gitea-actions/src/main/java/com/ankurm/ci/PriorityRules.java @@ -0,0 +1,22 @@ +package com.ankurm.ci; + +/** + * Pure logic with no framework and no database: the kind of code a fast, Docker-free + * unit test (surefire) should cover. + */ +public final class PriorityRules { + + private PriorityRules() { + } + + public static String priorityFor(String title) { + String t = title == null ? "" : title.toLowerCase(); + if (t.contains("outage") || t.contains("down") || t.contains("data loss")) { + return "HIGH"; + } + if (t.contains("error") || t.contains("slow")) { + return "MEDIUM"; + } + return "LOW"; + } +} diff --git a/gitea-actions/src/main/java/com/ankurm/ci/Ticket.java b/gitea-actions/src/main/java/com/ankurm/ci/Ticket.java new file mode 100644 index 0000000..7153949 --- /dev/null +++ b/gitea-actions/src/main/java/com/ankurm/ci/Ticket.java @@ -0,0 +1,5 @@ +package com.ankurm.ci; + +/** A support ticket. {@code priority} is derived, see {@link PriorityRules}. */ +public record Ticket(Long id, String title, String priority) { +} diff --git a/gitea-actions/src/main/java/com/ankurm/ci/TicketController.java b/gitea-actions/src/main/java/com/ankurm/ci/TicketController.java new file mode 100644 index 0000000..d40a334 --- /dev/null +++ b/gitea-actions/src/main/java/com/ankurm/ci/TicketController.java @@ -0,0 +1,33 @@ +package com.ankurm.ci; + +import java.util.List; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TicketController { + + public record NewTicket(String title) { + } + + private final TicketRepository repository; + + public TicketController(TicketRepository repository) { + this.repository = repository; + } + + @GetMapping("/tickets") + public List list() { + return repository.findAll(); + } + + @PostMapping("/tickets") + @ResponseStatus(HttpStatus.CREATED) + public Ticket create(@RequestBody NewTicket body) { + return repository.save(body.title()); + } +} diff --git a/gitea-actions/src/main/java/com/ankurm/ci/TicketRepository.java b/gitea-actions/src/main/java/com/ankurm/ci/TicketRepository.java new file mode 100644 index 0000000..37fdf24 --- /dev/null +++ b/gitea-actions/src/main/java/com/ankurm/ci/TicketRepository.java @@ -0,0 +1,30 @@ +package com.ankurm.ci; + +import java.util.List; +import org.springframework.jdbc.core.simple.JdbcClient; +import org.springframework.stereotype.Repository; + +/** Talks to PostgreSQL. Its test needs a real database, so it runs in failsafe with Testcontainers. */ +@Repository +public class TicketRepository { + + private final JdbcClient jdbc; + + public TicketRepository(JdbcClient jdbc) { + this.jdbc = jdbc; + } + + public Ticket save(String title) { + String priority = PriorityRules.priorityFor(title); + Long id = jdbc.sql("insert into ticket(title, priority) values (:t, :p) returning id") + .param("t", title).param("p", priority) + .query(Long.class).single(); + return new Ticket(id, title, priority); + } + + public List findAll() { + return jdbc.sql("select id, title, priority from ticket order by id") + .query((rs, n) -> new Ticket(rs.getLong("id"), rs.getString("title"), rs.getString("priority"))) + .list(); + } +} diff --git a/gitea-actions/src/main/resources/application.properties b/gitea-actions/src/main/resources/application.properties new file mode 100644 index 0000000..ed4f449 --- /dev/null +++ b/gitea-actions/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.application.name=gitea-actions-demo +spring.sql.init.mode=always +management.endpoints.web.exposure.include=health,info,sbom diff --git a/gitea-actions/src/main/resources/schema.sql b/gitea-actions/src/main/resources/schema.sql new file mode 100644 index 0000000..2fe9375 --- /dev/null +++ b/gitea-actions/src/main/resources/schema.sql @@ -0,0 +1,5 @@ +create table if not exists ticket ( + id bigserial primary key, + title text not null, + priority text not null +); diff --git a/gitea-actions/src/test/java/com/ankurm/ci/PriorityRulesTest.java b/gitea-actions/src/test/java/com/ankurm/ci/PriorityRulesTest.java new file mode 100644 index 0000000..ba9d269 --- /dev/null +++ b/gitea-actions/src/test/java/com/ankurm/ci/PriorityRulesTest.java @@ -0,0 +1,25 @@ +package com.ankurm.ci; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +/** Unit test: runs in surefire, needs no Docker, finishes in milliseconds. */ +class PriorityRulesTest { + + @Test + void outageIsHigh() { + assertThat(PriorityRules.priorityFor("Payment outage in Mumbai")).isEqualTo("HIGH"); + } + + @Test + void slowIsMedium() { + assertThat(PriorityRules.priorityFor("Dashboard is slow")).isEqualTo("MEDIUM"); + } + + @Test + void everythingElseIsLow() { + assertThat(PriorityRules.priorityFor("Please add dark mode")).isEqualTo("LOW"); + assertThat(PriorityRules.priorityFor(null)).isEqualTo("LOW"); + } +} diff --git a/gitea-actions/src/test/java/com/ankurm/ci/TicketApiIT.java b/gitea-actions/src/test/java/com/ankurm/ci/TicketApiIT.java new file mode 100644 index 0000000..15d8ac1 --- /dev/null +++ b/gitea-actions/src/test/java/com/ankurm/ci/TicketApiIT.java @@ -0,0 +1,51 @@ +package com.ankurm.ci; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClient; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.postgresql.PostgreSQLContainer; + +/** + * Integration test: a real PostgreSQL in a real container. Named *IT so failsafe runs it in the + * {@code integration-test} phase, after the unit tests and after the jar exists. + */ +@Testcontainers +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class TicketApiIT { + + @Container + @ServiceConnection + static PostgreSQLContainer postgres = new PostgreSQLContainer("postgres:17-alpine"); + + @LocalServerPort + int port; + + @Test + void createsAndListsTickets() { + RestClient http = RestClient.create("http://localhost:" + port); + + ResponseEntity created = http.post().uri("/tickets") + .body(new TicketController.NewTicket("Checkout outage")) + .retrieve().toEntity(Ticket.class); + assertThat(created.getStatusCode().value()).isEqualTo(201); + assertThat(created.getBody().priority()).isEqualTo("HIGH"); + + Ticket[] all = http.get().uri("/tickets").retrieve().body(Ticket[].class); + assertThat(all).extracting(Ticket::title).contains("Checkout outage"); + } + + /** The SBOM generated at build time is inside the jar/classpath and served by the actuator. */ + @Test + void servesTheSbom() { + RestClient http = RestClient.create("http://localhost:" + port); + String bom = http.get().uri("/actuator/sbom/application").retrieve().body(String.class); + assertThat(bom).contains("\"bomFormat\"").contains("CycloneDX").contains("spring-boot"); + } +}