Repository navigation
feat: add k3s/Argo GitOps deployment pipeline #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bf570ac
5fafd85
b5bad77
148053d
ec9353f
cde93d3
6c8578a
e1947c1
490a1e1
e544f7e
ff01770
3670086
2f16165
695e056
7ca1f7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| **/node_modules | ||
| **/.cache | ||
| **/.turbo | ||
| # Prisma/zod-prisma-types generated output (regenerated by `bun run build`). Excluding | ||
| # these avoids a bug where the zod-prisma-types generator fails trying to recursively | ||
| # clean a *pre-existing* output directory ("Error while deleting old data in path ...: | ||
| # The property 'options.recursive' is no longer supported") -- it has no trouble creating | ||
| # these fresh when they don't already exist in the build context. | ||
| src/infrastructure/database/src/zod | ||
| src/infrastructure/database/src/prisma-client | ||
| .git | ||
| **/.svelte-kit | ||
| **/build | ||
| **/dist | ||
| **/test-results | ||
| **/storybook-static | ||
| **/*storybook.log | ||
| **/tsconfig.tsbuildinfo | ||
| .devcontainer | ||
| .vscode | ||
| .claude |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,42 +70,163 @@ jobs: | |
| run: docker compose exec app sudo bun run test | ||
|
|
||
| e2e-prod: | ||
| name: E2E (production build) | ||
| name: E2E (production build, on kind) | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'push' || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) | ||
|
|
||
| # Deploys the actual k8s/db and k8s/app manifests (unmodified, aside from the image | ||
| # tag) into a throwaway kind cluster -- the same thing Argo CD applies in real | ||
| # production -- rather than approximating it with a bare `docker run`. The point is to | ||
| # catch manifest-level bugs here too, not just Dockerfile-level ones, so "CI passed" is | ||
| # actually predictive of "the real rollout will work". | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }} | ||
|
Comment on lines
75
to
118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🔴 Critical | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: sed -n '1,180p' .github/workflows/ci.ymlRepository: ThunLights/distopia Length of output: 7804 🏁 Script executed: sed -n '175,360p' .github/workflows/ci.yml
printf '\n--- setup action ---\n'
find .github/workflows/setup -maxdepth 2 -type f -print -exec sed -n '1,220p' {} \;Repository: ThunLights/distopia Length of output: 5077 Do not execute fork code from The 🧰 Tools🪛 zizmor (1.29.0)[warning] 1-268: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block (excessive-permissions) [warning] 72-229: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block (excessive-permissions) 🤖 Prompt for AI Agents |
||
| persist-credentials: false | ||
|
|
||
| - name: Generate .env | ||
| run: printenv > .env | ||
| - name: Create kind cluster | ||
| uses: helm/kind-action@v1 | ||
| with: | ||
| cluster_name: distopia-e2e | ||
|
|
||
| - name: Create distopia-db-store | ||
| run: docker volume create distopia-db-store | ||
| # kustomize is already preinstalled on GitHub's ubuntu-latest runner image at | ||
| # /usr/local/bin/kustomize -- no separate install step needed (and the official | ||
| # install script refuses to run if it finds a binary already there). | ||
|
|
||
| # kind's built-in dynamic provisioner is the StorageClass "standard" (backed by | ||
| # rancher.io/local-path, the same provisioner k3s's "local-path" uses) -- alias it so | ||
| # k8s/db/cluster.yaml's storageClassName: local-path applies completely unmodified, | ||
| # same as it would against the real k3s cluster. | ||
| - name: Alias kind's storage class as local-path | ||
| run: | | ||
| kubectl apply -f - <<'EOF' | ||
| apiVersion: storage.k8s.io/v1 | ||
| kind: StorageClass | ||
| metadata: | ||
| name: local-path | ||
| provisioner: rancher.io/local-path | ||
| volumeBindingMode: WaitForFirstConsumer | ||
| reclaimPolicy: Delete | ||
| EOF | ||
|
|
||
| - name: Install CloudNativePG operator | ||
| run: | | ||
| kubectl apply --server-side -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.24/releases/cnpg-1.24.0.yaml | ||
| kubectl -n cnpg-system wait --for=condition=Available deployment/cnpg-controller-manager --timeout=120s | ||
|
|
||
| - name: Create namespace and secrets | ||
| run: | | ||
| kubectl create namespace distopia | ||
| kubectl create secret generic distopia-db-credentials -n distopia \ | ||
| --from-literal=username=distopia \ | ||
| --from-literal=password=distopia-e2e-test | ||
| kubectl create secret generic distopia-env -n distopia \ | ||
| --from-literal=PUBLIC_URL="$PUBLIC_URL" \ | ||
| --from-literal=PUBLIC_OWNER_ID="$PUBLIC_OWNER_ID" \ | ||
| --from-literal=PUBLIC_HOME_SERVER_ID="$PUBLIC_HOME_SERVER_ID" \ | ||
| --from-literal=PUBLIC_STAFF_ROLE_ID="$PUBLIC_STAFF_ROLE_ID" \ | ||
| --from-literal=PUBLIC_HONORARY_MEMBER_ROLE_ID="$PUBLIC_HONORARY_MEMBER_ROLE_ID" \ | ||
| --from-literal=PUBLIC_SPECIAL_BOARD_OF_DIRECTORS_ROLE_ID="$PUBLIC_SPECIAL_BOARD_OF_DIRECTORS_ROLE_ID" \ | ||
| --from-literal=PUBLIC_BOARD_OF_DIRECTORS_ROLE_ID="$PUBLIC_BOARD_OF_DIRECTORS_ROLE_ID" \ | ||
| --from-literal=PUBLIC_SUB_BOARD_OF_DIRECTORS_ROLE_ID="$PUBLIC_SUB_BOARD_OF_DIRECTORS_ROLE_ID" \ | ||
| --from-literal=PUBLIC_BOT_ID="$PUBLIC_BOT_ID" \ | ||
| --from-literal=BOT_TOKEN="$BOT_TOKEN" \ | ||
| --from-literal=BOT_SECRET="$BOT_SECRET" \ | ||
| --from-literal=SENTRY_ORG="$SENTRY_ORG" \ | ||
| --from-literal=SENTRY_PROJECT="$SENTRY_PROJECT" \ | ||
| --from-literal=PUBLIC_SENTRY_DSN="$PUBLIC_SENTRY_DSN" \ | ||
| --from-literal=SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" | ||
|
|
||
| - name: Deploy CloudNativePG cluster (k8s/db, unmodified) | ||
| run: kubectl apply -k k8s/db | ||
|
|
||
| - name: Wait for the database to be ready | ||
| run: | | ||
| timeout 180 bash -c ' | ||
| until kubectl get pods -n distopia -l cnpg.io/cluster=distopia-db 2>/dev/null | grep -qE "1/1 +Running"; do | ||
| sleep 5 | ||
| done | ||
| ' | ||
|
|
||
| - name: Port-forward the database for migrate/build | ||
| run: | | ||
| kubectl port-forward svc/distopia-db-rw 5432:5432 -n distopia & | ||
| echo $! > /tmp/pf-db.pid | ||
| timeout 30 bash -c 'until (exec 3<>/dev/tcp/localhost/5432) 2>/dev/null; do sleep 1; done' | ||
|
|
||
| - uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| bun-version: "1.4.0" | ||
|
|
||
| - name: Apply database migrations | ||
| env: | ||
| DATABASE_URL: postgresql://distopia:distopia-e2e-test@localhost:5432/distopia | ||
| run: | | ||
| bun install --frozen-lockfile | ||
| cd src/infrastructure/database | ||
| bunx prisma migrate deploy | ||
|
|
||
| # Builds the same image k8s/ci/workflowtemplate.yaml's Kaniko step builds, just with | ||
| # `docker build` instead. --network host lets `prisma generate --sql` reach the | ||
| # port-forwarded database above. Build-time-only .env (deleted before the runtime | ||
| # layer, same as the real pipeline) -- BOT_TOKEN/PUBLIC_*/etc. are intentionally not | ||
| # in here, only what `bun run build` itself needs. | ||
| - name: Build production image | ||
| env: | ||
| DATABASE_URL: postgresql://distopia:distopia-e2e-test@localhost:5432/distopia | ||
| run: | | ||
| cat > .env <<EOF | ||
| DATABASE_URL=$DATABASE_URL | ||
| SENTRY_ORG=$SENTRY_ORG | ||
| SENTRY_PROJECT=$SENTRY_PROJECT | ||
| SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN | ||
| PUBLIC_SENTRY_DSN=$PUBLIC_SENTRY_DSN | ||
| EOF | ||
| docker build --network host -f docker/dockerfile.prod -t distopia:e2e . | ||
| rm -f .env | ||
|
|
||
| - name: Stop database port-forward | ||
| if: always() | ||
| run: kill "$(cat /tmp/pf-db.pid)" 2>/dev/null || true | ||
|
|
||
| - name: Load image into kind | ||
| run: kind load docker-image distopia:e2e --name distopia-e2e | ||
|
|
||
| - name: Start production stack | ||
| run: ./production/run.sh | ||
| - name: Deploy app (k8s/app, image tag bumped the same way the real Workflow does) | ||
| run: | | ||
| cd k8s/app | ||
| kustomize edit set image distopia-registry.distopia.svc.cluster.local:5000/distopia=distopia:e2e | ||
| cd ../.. | ||
| kubectl apply -k k8s/app | ||
| kubectl rollout status deployment/distopia-app -n distopia --timeout=180s | ||
|
|
||
| - name: Wait for production server to be ready | ||
| run: timeout 180 bash -c 'until curl -sf http://localhost:3000/ -o /dev/null; do sleep 2; done' | ||
| - name: Port-forward the app | ||
| run: | | ||
| kubectl port-forward svc/distopia-app 3000:3000 -n distopia & | ||
| echo $! > /tmp/pf-app.pid | ||
| timeout 180 bash -c 'until curl -sf http://localhost:3000/ -o /dev/null; do sleep 2; done' | ||
|
|
||
| - name: Run E2E tests against production build | ||
| working-directory: ./docker/ | ||
| run: docker compose exec -T app sudo sh -c "cd src/presentation/web && bun run test:e2e:prod" | ||
| working-directory: ./src/presentation/web | ||
| run: | | ||
| bunx playwright install --with-deps | ||
| bun run test:e2e:prod | ||
|
|
||
| - name: Dump app logs on failure | ||
| - name: Dump cluster diagnostics on failure | ||
| if: failure() | ||
| working-directory: ./docker/ | ||
| run: docker compose -f docker-compose.yml -f docker-compose.prod.yml logs app | ||
| run: | | ||
| kubectl get all -n distopia | ||
| kubectl describe pod -n distopia -l app.kubernetes.io/name=distopia-app | ||
| kubectl logs -n distopia deployment/distopia-app --tail=200 | ||
| kubectl get events -n distopia --sort-by=.lastTimestamp | ||
|
|
||
| - name: Tear down production stack | ||
| - name: Tear down | ||
| if: always() | ||
| working-directory: ./docker/ | ||
| run: docker compose -f docker-compose.yml -f docker-compose.prod.yml down | ||
| run: | | ||
| kill "$(cat /tmp/pf-app.pid)" 2>/dev/null || true | ||
| kind delete cluster --name distopia-e2e | ||
|
|
||
| devcontainer: | ||
| name: Dev Container | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the duplicated
e2e-prodenvironment description. The documentation and Playwright comment both describe direct Docker startup, but the stated workflow deploys the production manifests to a temporary kind cluster..claude/skills/docker.md#L161-L163: describee2e-prodas the kind-based Kubernetes validation workflow.src/presentation/web/playwright.prod.config.ts#L4-L6: update the startup comment to match the kind-based test environment.🧰 Tools
🪛 LanguageTool
[uncategorized] ~161-~161: The official name of this software platform is spelled with a capital “H”.
Context: ...ecrets, and one-time cluster bootstrap.
.github/workflows/ci.yml'se2e-prodjob buil...(GITHUB)
📍 Affects 2 files
.claude/skills/docker.md#L161-L163(this comment)src/presentation/web/playwright.prod.config.ts#L4-L6🤖 Prompt for AI Agents