# 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/solvway/co-lite-`, where `` is `api-gateway`, `mobile-api`, `service-auth`, `service-system`, `service-counter`, `service-member`, `service-log`, `service-email` or `admin-portal`. Tags are `` and `latest`. - The repo moves from `ngqile` to the `solvway` org before anything is deployed, so the images take the `solvway` names from the start. - CI uses the secret names Tastefully uses (`PACKAGE_USER`, `PACKAGE_RW_KEY`), so after the transfer it can pick up the org's secrets and runners. - Until the transfer, pushes are not expected to work. The build and the image check are proven locally instead. 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 ``. The handover shows how to make the hash (`htpasswd -bnBC 10 "" '' | 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 - [CI cannot push before the repo moves to `solvway`] → Expected. Deployment starts only after the transfer. Until then, the build and image check are proven locally, and the first `main` run after the transfer is the first push. - [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. - [No email provider is configured] → New staff are emailed a temporary password and forgot-password sends email, so until a provider is configured only the first administrator can sign in. Stated in the handover; it needs a decision before go-live. ## Migration Plan Merge. After the repo moves to `solvway`, confirm the `PACKAGE_USER` and `PACKAGE_RW_KEY` secrets and a runner are available to it. The next 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.