Files
co-lite/openspec/changes/add-release-ci-packaging/design.md
T

5.6 KiB

Design

Context

  • Java services: each Dockerfile copies target/*.jar onto gitea.containerverse.dev/solvway/docker-java-21. The Spring profile comes from the BUILD_PROFILE build argument (local in docker-compose, default otherwise). All runtime config is already read from environment variables:
    • MySQL: MYSQLHOST, MYSQLPORT, MYSQLUSER, MYSQLPWD;
    • Redis: REDISHOST;
    • Pub/Sub: GCP_PROJECT, GCP_CREDENTIAL_FILE;
    • mobile-api: APIGATEWAYURL, APIKEY, AUTH_API_KEYS, JWT_SECRET, CUSTOMER_PORTAL_BASE_URL;
    • service-auth: AES_SECRET_KEY, USER_AUTH_API_SECRET;
    • service-system: JUMIO_*;
    • service-email: mail and SMS provider keys.
  • Gateway: it reads its client keys from a mounted /deployments/appkeys/appkeys.json, and routes to the services by their names (service-auth, service-system and so on, on port 80). Every Java service has Actuator with probes enabled.
  • Admin portal: a multi-stage Next.js Dockerfile. Its test and lint stage gates the image. It reads MOBILE_API_BASE_URL, MOBILE_API_KEY and SESSION_* at runtime, and uses no NEXT_PUBLIC_* variables, so one image fits every environment.
  • Tastefully's CI (~/Projects/tastefully/.gitea/workflows/ci.yml) shows the house pattern: a Maven container from the registry, Docker over tcp://docker:2375, and a registry login from the PACKAGE_USER and PACKAGE_RW_KEY secrets.

Goals / Non-Goals

Goals: a repeatable image build and push from main; a database package and a handover document someone else can deploy from.

Non-Goals:

  • Kubernetes manifests, the rollout, and SonarQube.
  • Change detection that builds only changed modules. Nine images is small, and a full build keeps the tags consistent.

Decisions

  1. One workflow, one job, build all on every push to main. The job runs:

    • mvn -T 1C -B verify over the eight service modules and their dependencies;
    • then docker build and docker push for each Java service, followed by the portal.

    The portal's own Dockerfile runs its tests, lint and build.

    • Alternative: Tastefully's selective scripts (shouldIBuild.sh and others). Rejected because they bring scripts and SonarQube steps this repo does not have, and they make tags uneven across images.
    • Alternative: also build on pull requests. Rejected for now; it can be added later without changing the images.
  2. Tests gate the push. Tastefully builds with -Dmaven.test.skip=true; Co-Lite runs verify, so a red test stops the run before any push. Every image is pushed only after all builds succeed: build all first, push all after.

  3. Image names: gitea.containerverse.dev/ngqile/co-lite-<module>, where <module> is api-gateway, mobile-api, service-auth, service-system, service-counter, service-member, service-log, service-email or admin-portal. Tags are <git sha> and latest. The owner segment follows the repository owner. If the repo moves to the solvway org, it is the one line to change.

  4. Profile at runtime. Images are built with the default profile. The entrypoint already honours a BUILD_PROFILE environment variable, so the deployer can override it without a rebuild. The handover says to leave it unset.

  5. Image hygiene. Each module gets a .dockerignore where it lacks one, so .env, appkeys.json, key files and local/ never enter the build context. A CI step lists every image's files and fails if appkeys.json, .env, *.pem, *.p12 or a service-account JSON is present.

  6. Database package (sql/):

    • Files: 00-schemas.sql, 01-schema.sql and 02-reference.sql, the same content as local/seed/; 03-colite.sql, which is the local 03 without the dev admin and its role row; and 04-first-admin.sql.
    • The local seed files stay the source. The package is written by hand in the order listed, with a header comment in each file naming its source.
    • 04-first-admin.sql inserts user admin as super admin of company 1, with login = 'N' (forced password change) and a placeholder <BCRYPT_HASH>. The handover shows how to make the hash (htpasswd -bnBC 10 "" '<password>' | tr -d ':\n'), so the password never passes through this repository.
  7. Handover document docs/deployment.md, containing:

    • an image table: port 80 for the services, 3000 for the portal, plus the probe paths (/actuator/health/liveness and /readiness for the services);
    • every environment variable per image, marked as secret or plain;
    • a Secret template per image with base64 placeholders;
    • the mounted files;
    • the Pub/Sub topics and subscriptions from local/pubsub/topics.txt;
    • the Traefik host co-lite.containerverse.dev, routed to the admin portal, with mobile-api and the gateway kept internal;
    • the order to set things up.

Risks / Trade-offs

  • [No runner serves ngqile/co-lite] → The first run shows it. The fix is enabling a runner for the repo, or moving the repo under solvway, which also changes decision 3's owner segment.
  • [The base image solvway/docker-java-21 needs a registry login to pull] → CI logs in before building.
  • [The production SQL drifts from local/seed/] → Header comments name the source file, and task 1.2 diffs the package against the seed.
  • [Forgot-password does not work without SMTP] → Stated in the handover. Admins sign in with the first-admin flow, and other users get passwords from an admin through the existing user screens.

Migration Plan

Merge, then add the two Actions secrets. The first push to main publishes the images. The DBA applies the package, and the deployer follows docs/deployment.md. Rollback means deploying the previous SHA tag.