|
| 1 | +#### |
| 2 | +# Read-only static calm-hub image. |
| 3 | +# |
| 4 | +# Produces a calm-hub container with a pre-seeded NitriteDB database baked in |
| 5 | +# as a read-only second layer. No external database is required at runtime. |
| 6 | +# Mutating HTTP verbs (POST, PUT, DELETE, PATCH) are rejected with HTTP 405. |
| 7 | +# |
| 8 | +# Build is two stages: |
| 9 | +# |
| 10 | +# Stage 1 (seed) — always linux/amd64; boots the app in writable standalone |
| 11 | +# mode, runs init-nitrite.sh to populate the NitriteDB, then |
| 12 | +# shuts the app down gracefully so the MVStore file is fully |
| 13 | +# flushed. The resulting calmSchemas.db is architecture- |
| 14 | +# neutral (pure-Java H2 MVStore format). |
| 15 | +# |
| 16 | +# Stage 2 (final) — target platform (linux/amd64, linux/arm64, …); copies the |
| 17 | +# app artefacts and the seeded .db from Stage 1, then sets |
| 18 | +# the read-only env-vars so the app opens the file with |
| 19 | +# readOnly(true) and the HTTP filter rejects mutations. |
| 20 | +# |
| 21 | +# Prerequisites (handled by the CI workflow before `docker build` is called): |
| 22 | +# • calm-hub Maven build complete: mvn package -DskipITs |
| 23 | +# → target/quarkus-app/ is populated |
| 24 | +# • calm/ schema content staged: target/readonly-seed/calm/ |
| 25 | +# • controls content staged: target/readonly-seed/controls/ |
| 26 | +# |
| 27 | +# Build (from calm-hub/ directory): |
| 28 | +# docker build -f src/main/docker/Dockerfile.readonly-static \ |
| 29 | +# -t calm-hub:latest-read-only-static . |
| 30 | +#### |
| 31 | + |
| 32 | + |
| 33 | +# ── Stage 1: Seed ───────────────────────────────────────────────────────────── |
| 34 | +# Force amd64 so the JVM seeding process runs natively on GitHub Actions runners |
| 35 | +# (x86_64). The resulting .db file is architecture-neutral and is safe to embed |
| 36 | +# in the arm64 final image. |
| 37 | +FROM --platform=linux/amd64 registry.access.redhat.com/ubi8/openjdk-21 AS seed |
| 38 | + |
| 39 | +USER root |
| 40 | + |
| 41 | +# Install seeding tools (curl for readiness polling + REST calls; jq for JSON) |
| 42 | +RUN microdnf install -y curl jq && microdnf clean all |
| 43 | + |
| 44 | +# App artefacts pre-built by Maven (same layout as Dockerfile.jvm) |
| 45 | +COPY --chown=root target/quarkus-app/lib/ /deployments/lib/ |
| 46 | +COPY --chown=root target/quarkus-app/*.jar /deployments/ |
| 47 | +COPY --chown=root target/quarkus-app/app/ /deployments/app/ |
| 48 | +COPY --chown=root target/quarkus-app/quarkus/ /deployments/quarkus/ |
| 49 | + |
| 50 | +# Seeding scripts |
| 51 | +COPY nitrite/seed-readonly.sh /nitrite/seed-readonly.sh |
| 52 | +COPY nitrite/init-nitrite.sh /nitrite/init-nitrite.sh |
| 53 | +RUN chmod +x /nitrite/seed-readonly.sh /nitrite/init-nitrite.sh |
| 54 | + |
| 55 | +# CALM schema content and controls staged by the CI workflow into target/readonly-seed/ |
| 56 | +COPY target/readonly-seed/calm/ /calm/ |
| 57 | +COPY target/readonly-seed/controls/ /controls/ |
| 58 | + |
| 59 | +# Boot calm-hub (writable standalone), seed all content, stop gracefully. |
| 60 | +# The resulting database file lands at /data/calmSchemas.db. |
| 61 | +RUN DATA_DIR=/data \ |
| 62 | + CALM_SCHEMA_BASE_PATH=/calm \ |
| 63 | + CALM_CONTROLS_BASE_PATH=/controls \ |
| 64 | + bash /nitrite/seed-readonly.sh |
| 65 | + |
| 66 | + |
| 67 | +# ── Stage 2: Final read-only image ──────────────────────────────────────────── |
| 68 | +FROM registry.access.redhat.com/ubi8/openjdk-21 |
| 69 | + |
| 70 | +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' |
| 71 | + |
| 72 | +# App artefacts (from seed stage; built once, reused across both platforms) |
| 73 | +COPY --chown=185 --from=seed /deployments/lib/ /deployments/lib/ |
| 74 | +COPY --chown=185 --from=seed /deployments/*.jar /deployments/ |
| 75 | +COPY --chown=185 --from=seed /deployments/app/ /deployments/app/ |
| 76 | +COPY --chown=185 --from=seed /deployments/quarkus/ /deployments/quarkus/ |
| 77 | + |
| 78 | +# Bake the seeded database as a read-only file owned by the runtime user |
| 79 | +RUN mkdir -p /deployments/data |
| 80 | +COPY --chown=185 --from=seed /data/calmSchemas.db /deployments/data/calmSchemas.db |
| 81 | +RUN chmod 0444 /deployments/data/calmSchemas.db |
| 82 | + |
| 83 | +EXPOSE 8080 |
| 84 | +USER 185 |
| 85 | + |
| 86 | +ENV AB_JOLOKIA_OFF="" |
| 87 | +ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" |
| 88 | +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" |
| 89 | + |
| 90 | +# Activate the standalone profile: sets calm.database.mode=standalone and |
| 91 | +# suppresses MongoDB health-check / dev-services. |
| 92 | +ENV QUARKUS_PROFILE=standalone |
| 93 | + |
| 94 | +# Use a fixed data path (avoids ${user.home} ambiguity for UBI container UID 185) |
| 95 | +ENV CALM_STANDALONE_DATA_DIRECTORY=/deployments/data |
| 96 | + |
| 97 | +# Read-only mode: opens NitriteDB with readOnly(true) and rejects mutating HTTP verbs |
| 98 | +ENV CALM_READONLY=true |
0 commit comments