From bfed80a03b896932de9d064d6dc0f83c5ee5ec9f Mon Sep 17 00:00:00 2001 From: ngqile Date: Mon, 30 Nov 2026 09:33:42 +0800 Subject: [PATCH] docs(openspec): propose add-release-ci-packaging Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../add-release-ci-packaging/.openspec.yaml | 2 + .../add-release-ci-packaging/design.md | 60 +++++++++++++++++++ .../add-release-ci-packaging/proposal.md | 43 +++++++++++++ .../specs/release-packaging/spec.md | 60 +++++++++++++++++++ .../changes/add-release-ci-packaging/tasks.md | 48 +++++++++++++++ 5 files changed, 213 insertions(+) create mode 100644 openspec/changes/add-release-ci-packaging/.openspec.yaml create mode 100644 openspec/changes/add-release-ci-packaging/design.md create mode 100644 openspec/changes/add-release-ci-packaging/proposal.md create mode 100644 openspec/changes/add-release-ci-packaging/specs/release-packaging/spec.md create mode 100644 openspec/changes/add-release-ci-packaging/tasks.md diff --git a/openspec/changes/add-release-ci-packaging/.openspec.yaml b/openspec/changes/add-release-ci-packaging/.openspec.yaml new file mode 100644 index 0000000..4a154df --- /dev/null +++ b/openspec/changes/add-release-ci-packaging/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-30 diff --git a/openspec/changes/add-release-ci-packaging/design.md b/openspec/changes/add-release-ci-packaging/design.md new file mode 100644 index 0000000..12a0308 --- /dev/null +++ b/openspec/changes/add-release-ci-packaging/design.md @@ -0,0 +1,60 @@ +# 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-`, 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 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 ``. 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 + +- [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. diff --git a/openspec/changes/add-release-ci-packaging/proposal.md b/openspec/changes/add-release-ci-packaging/proposal.md new file mode 100644 index 0000000..5acd8d4 --- /dev/null +++ b/openspec/changes/add-release-ci-packaging/proposal.md @@ -0,0 +1,43 @@ +# Proposal + +## Why + +Co-Lite goes live on 2027-01-15 on the team's Kubernetes cluster. Phase 1 runs end to end only on a developer machine today: nothing builds or publishes images, and there is no database package or deployment handover. Another person deploys to the cluster, so this change delivers what they need to do it. It is change 5 of the phase 1 design (`docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md`, Deployment), cut down to CI, images and handover. + +## What Changes + +- **CI** (`.gitea/workflows/ci.yml`): on every push to `main`, build and test every module, then build and push nine images to `gitea.containerverse.dev`: + - the eight Java services: `api-gateway`, `mobile-api`, `service-auth`, `service-system`, `service-counter`, `service-member`, `service-log`, `service-email`; + - the admin portal. + + Each image is tagged with the commit SHA and `latest`. A failing test or build pushes nothing. There is no rollout step. +- **Dockerfiles**: the existing ones are checked and fixed for production. Images carry no secrets or environment-specific config; everything comes from environment variables or mounted files at runtime. +- **Production database package** in this change's `sql/` folder, for the DBA. It reuses `local/seed/00` to `02`, plus a production copy of `03-colite.sql` without the dev admin, plus a first-admin template: the DBA puts in a bcrypt hash they generate, and that admin must change the password at first sign-in. +- **Deployment handover** (`docs/deployment.md`), covering: + - for each image: port, health probes and every environment variable; + - Kubernetes Secret templates with base64 placeholders; + - the mounted files (gateway `appkeys.json`, Google Pub/Sub key); + - the Pub/Sub topics to create; + - the Traefik host `co-lite.containerverse.dev`, routed to the admin portal; + - the order to set things up. + +Not in this change: +- Kubernetes manifests and the rollout (done by the deployer). +- SMTP: forgot-password emails will not send until it is configured later. +- The customer portal image: phase 1 does not use it. + +## Capabilities + +### New Capabilities +- `release-packaging`: how releases are built, tested and published as images, and what the production database package must and must not contain. + +### Modified Capabilities +None. + +## Impact + +- New `.gitea/workflows/ci.yml`. It needs repo Actions secrets `PACKAGE_USER` and `PACKAGE_RW_KEY` (registry login), and an Actions runner that serves `ngqile/co-lite`. +- Dockerfiles of the nine modules (fixes only where production needs them). +- New `docs/deployment.md`. +- New SQL under `openspec/changes/add-release-ci-packaging/sql/`. +- No application code, API or schema change. diff --git a/openspec/changes/add-release-ci-packaging/specs/release-packaging/spec.md b/openspec/changes/add-release-ci-packaging/specs/release-packaging/spec.md new file mode 100644 index 0000000..c37ca55 --- /dev/null +++ b/openspec/changes/add-release-ci-packaging/specs/release-packaging/spec.md @@ -0,0 +1,60 @@ +## Purpose + +Releases are built, tested and published as container images that someone else can deploy, and the production database can be created from a package that holds no development credentials. + +## ADDED Requirements + +### Requirement: Images published from main + +Every push to `main` SHALL build the eight backend services and the admin portal, run their tests, and push one image per module to `gitea.containerverse.dev`, tagged with the commit SHA and with `latest`. + +#### Scenario: Green push publishes all images + +- **GIVEN** a push to `main` whose build and tests pass +- **WHEN** CI finishes +- **THEN** the registry holds the nine images tagged with that commit's SHA +- **AND** `latest` points at the same images + +#### Scenario: Red test publishes nothing + +- **GIVEN** a push to `main` with a failing test in any module +- **WHEN** CI runs +- **THEN** the run fails +- **AND** no image is pushed for that commit + +#### Scenario: Other branches do not publish + +- **WHEN** a commit is pushed to a branch other than `main` +- **THEN** no image is pushed + +### Requirement: Images carry no secrets or environment config + +Images SHALL contain no secrets, keys, passwords or environment-specific hosts. Every service MUST read its database, Redis, gateway, Pub/Sub, JWT and API-key settings from environment variables or mounted files at runtime. + +#### Scenario: Image layers hold no key material + +- **WHEN** a published image's files are inspected +- **THEN** there is no `.env` file, `appkeys.json`, Pub/Sub service-account key or private key in it + +#### Scenario: One image runs in any environment + +- **GIVEN** the same image tag +- **WHEN** it is started with a different set of environment variables and mounted files +- **THEN** it connects to the database, Redis and other services those settings name + +### Requirement: Production database package has no development login + +The production database package SHALL create the five schemas, their tables, the reference data, the Co-Lite company, the new lead tables and the back-office modules. It MUST NOT create any user with a known password. The first administrator MUST be created from a password hash the operator supplies, and MUST be forced to change the password at first sign-in. + +#### Scenario: Package applied to an empty server + +- **GIVEN** an empty MySQL 8 server +- **WHEN** the DBA runs the package files in the documented order +- **THEN** every service starts against it +- **AND** no `admin` user with the development password exists + +#### Scenario: First administrator signs in + +- **GIVEN** the first-admin template applied with an operator-generated bcrypt hash +- **WHEN** that administrator signs in to the admin portal +- **THEN** they are sent to change their password before any other screen diff --git a/openspec/changes/add-release-ci-packaging/tasks.md b/openspec/changes/add-release-ci-packaging/tasks.md new file mode 100644 index 0000000..00ad45e --- /dev/null +++ b/openspec/changes/add-release-ci-packaging/tasks.md @@ -0,0 +1,48 @@ +# Tasks + +Design: `design.md`. All tasks run serially: each touches a build file, CI or SQL. + +## 1. Images and database package + +- [ ] 1.1 Make the images production-safe (design decisions 4 and 5). + - Add a `.dockerignore` to each of the nine modules that lacks one. + - Check each Dockerfile for baked-in config or secrets. + - Write `local/image-check.sh `. It fails when an image holds `appkeys.json`, `.env`, `*.pem`, `*.p12` or a Google service-account JSON. + + Tests first: build one image with a planted `appkeys.json` in its module folder and show the check fails (red). Add the `.dockerignore` and show it passes (green). Then build all nine images locally, and run the check on each. + - Scope: `solvway-*/Dockerfile`, `solvway-*/.dockerignore`, `local/image-check.sh` + - Verify: all nine `docker build` commands succeed, and `local/image-check.sh` passes on each image. + +- [ ] 1.2 Write the production database package (design decision 6): `sql/00` to `04` with source headers. + + Prove it: load `00` to `04` into a throwaway MySQL 8 container (not the dev database). For `04`, use a hash of a throwaway password. Point the local stack at it, then show: + - the services start; + - no `admin` row has the dev password hash; + - signing in as the new admin is sent to the password change. + - Diff the package against `local/seed/` and record the only differences: the dev admin rows removed and file `04` added. + - Scope: `openspec/changes/add-release-ci-packaging/sql/**` + - Verify: the throwaway-database check above. + +## 2. CI + +- [ ] 2.1 Add `.gitea/workflows/ci.yml` (design decisions 1 to 3 and 5). + - The workflow runs on push to `main` only. + - It runs Maven `verify` with `-T 1C`, then builds all nine images, runs `local/image-check.sh` on each, and pushes after every image has built, tagged with the SHA and `latest`. + - It logs in to the registry with `PACKAGE_USER` and `PACKAGE_RW_KEY`. + + Before merge: lint the workflow with `actionlint`, or a YAML parse if `actionlint` is unavailable. Dry-run the build-and-check part of the job locally with the same commands, without the push. + - Scope: `.gitea/workflows/**` + - Verify: the local dry-run builds and checks all nine images. After merge, the first `main` run is green and the registry shows the nine SHA tags. + +## 3. Handover + +- [ ] 3.1 Write `docs/deployment.md` (design decision 7). + - Cross-check every environment variable against each module's `application.yml`, the portal's `process.env` uses and the gateway's `appkeys.json` path, so none is missing or extra. + - Secret templates use placeholders only, never real values. + - Scope: `docs/deployment.md` + - Verify: a script lists the variables each module reads and finds each one in the document. + +## Workflow follow-up + +- Whole-branch review, push, PR to main and merge, then confirm the first CI run and the registry tags, then archive on its own branch. +- The user adds the `PACKAGE_USER` and `PACKAGE_RW_KEY` repo secrets, and confirms a runner serves `ngqile/co-lite`.