Aller au contenu

Deploy architecture — submodule-driven DEV, coordinated promotion to staging & PROD

Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.

This describes how the dowonou-deploy superrepo and its four app submodules build, deploy, and promote across environments.

  1. Build once, deploy many. Each app version is built exactly once. The same immutable image flows DEV → staging → PROD with no rebuild — except the two frontends, which bake env config at build time and are therefore rebuilt per environment (see Frontend exception).
  2. Superrepo is the source of truth. An app never deploys itself directly. On merge it builds, pushes, and bumps the superrepo; the superrepo bump is the deploy trigger.
  3. Per-environment manifests decouple environments. DEV can advance automatically while staging and PROD stay pinned to a reviewed set.
  4. Cluster credentials live only in the superrepo, scoped per environment via GitHub Environments. App repos hold only a DOCR push token and the GitHub App.
  5. Argo-ready. The superrepo deploy job is the only thing a future ArgoCD migration replaces; nothing upstream changes.
Chart key (manifest) Submodule (repo) Default branch DOCR image Type
ged-backend ged_backend (Django) main agbale-ged-backend backend
ged-frontend agbale_frontend (Vue) main agbale-ged-frontend frontend
afcm-backend afcm-backend (PHP) master afcm-backend backend
afcm-frontend afcm-front (Vue) master afcm-frontend frontend

The three names per app (chart key / submodule / image) differ — the manifest records all of them so app CI and Helm agree.

environments/{dev,staging,prod}/versions.yaml is the desired state per env:

registry: registry.digitalocean.com/afcorp
apps:
ged-backend: { submodule: ged_backend, image: agbale-ged-backend, type: backend, sha: 766b592, tag: "766b592" }
...
  • sha — the submodule short SHA = the gitlink this manifest tracks. The canonical pin.
  • tag — the literal image tag the deploy job sets on the chart.
    • backend: tag == sha (immutable, promoted unchanged).
    • frontend: tag == sha-<env> (rebuilt per env; sha is still the pin).
    • An empty tag is skipped by the deploy job (logged) — used to seed an environment that has no version yet (e.g. PROD on day one).

App repo .github/workflows/deploy-dev.yml:

  1. Build the Docker image; tag = short SHA (frontends: sha-dev).
  2. doctl registry login; push the tag to DOCR. Tags are immutable — the workflow refuses to overwrite an existing tag.
  3. Mint a token from the shared GitHub App, clone the superrepo, and in a fetch/reset/retry loop (race-safe against concurrent merges) atomically:
    • advance this app’s gitlink (git update-index --cacheinfo 160000,<sha>,<path>), and
    • set this app’s sha+tag in environments/dev/versions.yaml, then commit and push to main.
  4. The push changes environments/dev/**, which triggers the superrepo deploy.yml to helm-upgrade DEV only.
merge ─► build+push image ─► bump superrepo (dev manifest + gitlink) ─► deploy.yml (DEV) ─► helm upgrade
  • Triggered by push to main under environments/<env>/**. The plan job maps changed paths → environments, so DEV moving never touches staging/PROD.
  • Runs as the matching GitHub Environment (dev / staging / production) so the correct cluster secret and protection rules apply.
  • Pure helm. Reads the target manifest, sets <chartkey>.image.tag per app, and runs deploy/scripts/helm-deploy.sh <env> (the agbale-platform umbrella chart). No build, no app-source checkout. Idempotent (helm upgrade --install).
  • workflow_dispatch remains as a manual redeploy-current-pins escape hatch.

workflow_dispatch(from_env, to_env, apps) opens a PR that copies pins forward:

  • Backends: tag = sha copied as-is — identical image, no rebuild.
  • Frontends: dispatches the app repo’s build-env.yml to build sha-<to_env>, waits for it, then pins that tag.

Merging the PR triggers deploy.yml for the target environment.

  • dev → staging and staging → prod only (no skipping, no backwards).
  • Staging/PROD manifest paths are gated by CODEOWNERS; the production Environment adds required reviewers on the deploy itself (two gates for PROD).

Both Vue Dockerfiles compile VITE_API_URL, VITE_KEYCLOAK_*, VITE_BASE_PATH into the static bundle at build time, with the host derived from the target environment. A “dev” frontend image has dev.dowonou.com baked in and cannot be promoted to PROD unchanged. So frontends are rebuilt per env (deterministically, from the same submodule SHA) and tagged sha-<env>. Backends read config at runtime and are true build-once artifacts.

Future option: refactor the frontends to read a runtime-served /config.js (nginx envsubst at container start) instead of baked VITE_ vars. That would make frontends true build-once artifacts and remove this exception — and is the natural prerequisite for a clean ArgoCD (Phase 2) migration.

  • The image tag is the submodule short SHA (backends) or sha-<env> (frontends) — always traceable to a commit.
  • The set of pins in a manifest is the environment’s release. Roll back by reverting the manifest commit (or re-running deploy.yml on a prior pin).
  • A future superrepo git tag over a validated set of manifests is a coherent, reproducible full-stack version and a one-revert rollback unit.

Access model (summary — full setup in deploy-setup.md)

Section intitulée « Access model (summary — full setup in deploy-setup.md) »
  • App teams: write to their own submodule repo only (PR into protected branches).
  • The cross-repo bump runs as a GitHub App (not a personal PAT), scoped to Contents RW on the app repos + superrepo. It can advance DEV without review; staging/PROD are CODEOWNERS-gated so it cannot land them unreviewed.
  • Cluster creds: superrepo GitHub Environment secrets only. App-triggered pipelines physically cannot reach staging/PROD clusters.

The layout is Argo-shaped: per-env manifests, image-tag pins, no build in the deploy path. Phase 2 replaces only the superrepo deploy.yml helm job with an Argo Application per environment pointed at environments/<env>/. App CI, manifests, and promotion are unchanged.