chore(local): smoke check and local stack README

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-26 16:32:35 +08:00
1 parent b3fcb2883a
commit d72f48cbc0
5 files changed
+102 -5

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
# Co-Lite local stack
Runs the whole Co-Lite backend on your machine: MySQL, Redis, the Pub/Sub emulator and the eight Java services, with the same service names as Kubernetes. Everything here is dev-only.
## Prerequisites
- JDK 21 and Maven 3.9+
- Docker with Compose v2
- Access to the base image registry: `docker login gitea.containerverse.dev`
- About 6 GB of free RAM
## Start
From the repository root:
```sh
local/up.sh
```
This copies `local/.env.example` to `local/.env` (git-ignored) if it is missing, builds every module with `mvn -T 1C -DskipTests package`, and starts the stack. The services take about a minute to boot after MySQL finishes seeding.
Then check it:
```sh
local/smoke.sh
```
It prints `smoke: OK` when admin login, a service-counter read and a public mobile-api call all succeed.
| What | Where |
|---|---|
| mobile-api | http://localhost:8080 (header `api-key: colite-local-app-key`) |
| api-gateway | http://localhost:8081 (header `api-key: colite-local-gateway-key-000000000000`) |
| MySQL | localhost:3307, user `root`, password `colite-dev` |
| Admin login | `admin` / `colite-dev-admin` |
## Reset
Deletes the database volume; the next start reseeds from `local/seed/`:
```sh
docker compose -f local/docker-compose.yml down -v
local/up.sh
```
## Seed data
`local/seed/` is loaded only when the MySQL volume is empty, in file-name order:
- `00-schemas.sql`: creates the five service schemas.
- `01-schema.sql`: table structure from a Tastefully schema-only dump.
- `02-reference.sql`: allow-listed reference rows (roles, modules, lookups, messages).
- `03-colite.sql`: the Co-Lite company and the dev admin login.
Never put Tastefully customer data (members, users, attendance, orders) in these files.
## Rebuild one service after a change
```sh
mvn -T 1C -B -q -DskipTests -pl solvway-services-counter -am package
docker compose -f local/docker-compose.yml up -d --build service-counter
```
`-am` builds the core library alongside the module; a module cannot be built alone because the `colite-v1` core library is not installed in `~/.m2` by default.
Services reach each other by container name (`service-system`, `api-gateway` and so on), so a service run from an IDE outside Docker cannot join the stack. Run it inside the stack and attach a debugger instead: add `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005` to `JAVA_OPTS` for that service and publish port 5005.
Executable
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# Smoke check for the local stack: exits non-zero and names the failing call if any step fails.
set -u
GW=http://localhost:8081
MOBILE=http://localhost:8080
GW_KEY=colite-local-gateway-key-000000000000
APP_KEY=colite-local-app-key
fail() { echo "FAIL: $1"; exit 1; }
# 1. Admin login: gateway -> service-auth -> service-system -> MySQL
token=$(curl -sf -X POST "$GW/auth/authenticate" -H "api-key: $GW_KEY" -H 'Content-Type: application/json' \
-d '{"username":"admin","password":"colite-dev-admin"}') || fail "POST $GW/auth/authenticate"
[ -n "$token" ] || fail "POST $GW/auth/authenticate returned no token"
echo "auth/authenticate: 200"
# 2. gateway -> service-counter -> MySQL
code=$(curl -s -o /dev/null -w '%{http_code}' "$GW/counter/event/findCurrentEvent" \
-H "api-key: $GW_KEY" -H "Authorization: Bearer $token")
[ "$code" = 200 ] || fail "GET $GW/counter/event/findCurrentEvent returned $code"
echo "counter/event/findCurrentEvent: $code"
# 3. mobile-api -> gateway -> service-system -> MySQL
code=$(curl -s -o /dev/null -w '%{http_code}' "$MOBILE/api/public/messages/en_US" -H "api-key: $APP_KEY")
[ "$code" = 200 ] || fail "GET $MOBILE/api/public/messages/en_US returned $code"
echo "api/public/messages/en_US: $code"
echo "smoke: OK"
@@ -50,7 +50,11 @@ What Tastefully looks like today (commit `8bd93d15`):
- **Location:** `local/seed/`. Decided by the user: runnable dev seed files are a documented exception to the SQL-placement rule (see `CLAUDE.md`), because the change folder moves when the change is archived and would break the compose mount.
- **Source:** the user supplies a schema-only dump and a reference-table data dump, not a full dump. Customer data from Tastefully never enters this repo or the local database.
8. **Smoke check is `local/smoke.sh`.** It runs `curl -fsS` against `http://localhost:8080/api/event/upcomingEvent` (mobile-api → gateway → service-counter → MySQL), prints the status code, and exits non-zero on failure. The task confirms the endpoint is public; if it is not, the task picks another public counter-backed endpoint and records the choice here.
8. **Smoke check is `local/smoke.sh`.** It makes three calls and exits non-zero, naming the failing call, if any of them fails:
1. Admin login: `POST /auth/authenticate` on the gateway (auth → system → MySQL).
2. `GET /counter/event/findCurrentEvent` on the gateway, with the admin token (counter → MySQL).
3. `GET /api/public/messages/en_US` on mobile-api (mobile-api → gateway → system → MySQL).
- The originally planned `GET /api/event/upcomingEvent` returns a hardcoded URL and never reaches a service. mobile-api has no public endpoint backed by counter; its counter calls need a member token. That is why the counter call goes through the gateway directly.
9. **Dropped-service references.** HTTP calls to dropped services are strings; they compile and only fail if called, so they stay. Remove only these:
- gateway routes whose `uri` points at a dropped service (bonus, payment, inventory, stockist, wallet and similar);
@@ -65,13 +65,13 @@ The repository SHALL provide a documented command that deletes local data and re
### Requirement: End-to-end smoke check
The repository SHALL include a smoke check that calls a public mobile-api endpoint through the local stack and confirms a successful response backed by services-counter and MySQL.
The repository SHALL include a smoke check that logs in as the seeded admin through the gateway, reads from services-counter through the gateway, and calls a public mobile-api endpoint, confirming each succeeds against MySQL.
#### Scenario: Smoke check passes on a healthy stack
- **GIVEN** the stack is running and seeded
- **WHEN** the developer runs the smoke check
- **THEN** it exits with status 0 and prints the endpoint's HTTP status 200
- **THEN** it exits with status 0 and prints HTTP status 200 for each call
#### Scenario: Smoke check fails loudly
@@ -24,11 +24,11 @@ Run serially: every group touches build files or shared config.
- [x] 4.1 Ask the user for the dump, giving them this exact command: `mysqldump --no-data --routines --triggers --skip-add-drop-table --databases service-system service-counter service-member service-log service-email > 01-schema.sql`, plus a data dump of an allow-list of reference tables. Build the allow-list from the services-system entities: role, module, system_property, location_hierarchy and the other lookup tables, each checked for personal data before it is listed. Put the files in `local/seed/`. Verify: grep the files for `INSERT INTO \`(member|user|event_attendance|orders)` and it is empty.
- [x] 4.2 Write `03-colite.sql`: one company row and one admin user with the Administrator role, a bcrypt hash of the documented dev password, and the column set matching the dumped `user` table. Verify: after `docker compose down -v && local/up.sh`, `SELECT count(*) FROM \`service-system\`.user` returns 1. The admin can log in through `POST /auth/...` via the gateway (endpoint confirmed from services-auth) and gets a token. Result: `POST /auth/authenticate` through the gateway (`api-key` header) returns a JWT for `admin` / `colite-dev-admin`. A wrong password returns 200 with an empty body, which is existing Tastefully behaviour. MySQL runs with `--log-bin-trust-function-creators=1 --innodb-strict-mode=OFF` to load the dumped schema, and its healthcheck uses TCP so services wait for seeding to finish.
- [ ] 4.3 Write `local/README.md`: prerequisites (JDK 21, Maven, Docker, registry login), build/up, reset (`docker compose -f local/docker-compose.yml down -v`), the dev login, and how to run one service from an IDE (stop its container, run with profile `local` and `.env` exported). Verify: a second developer follows it on a clean clone without help. If no second developer is available, re-run the documented commands verbatim on a fresh clone in a scratch dir.
- [ ] 4.3 Write `local/README.md`: prerequisites (JDK 21, Maven, Docker, registry login), build/up, reset (`docker compose -f local/docker-compose.yml down -v`), the dev login, and how to rebuild one service and attach a debugger inside the stack. (This replaces the planned "run one service from an IDE": services address each other by container name, so a service outside Docker cannot join the stack.) Verify: a second developer follows it on a clean clone without help. If no second developer is available, re-run the documented commands verbatim on a fresh clone in a scratch dir.
## 5. Smoke check
- [ ] 5.1 Add `local/smoke.sh` (design decision 8). Verify on a healthy stack: exit 0 and prints `200`. Then `docker compose stop service-counter`: exit non-zero, with the failing URL printed.
- [x] 5.1 Add `local/smoke.sh` (design decision 8). Verify on a healthy stack: exit 0 and prints `200`. Then `docker compose stop service-counter`: exit non-zero, with the failing URL printed.
- [ ] 5.2 Integration: from a fresh clone in a scratch directory, run `mvn -T 1C verify`, `local/up.sh` and `local/smoke.sh`. Verify: all three succeed and `docker compose ps` shows every service running. Paste the outputs into the PR description.
## Workflow follow-up