Premier déploiement de l'app SaaS (apps/api + apps/web) — distinct de la landing déjà sur rubis.arthurbarre.fr. Architecture : - Image unique (Dockerfile.app, multi-stage) : AdonisJS sert l'API ET le SPA static via @adonisjs/static + wildcard fallback pour TanStack Router - Workers BullMQ tournent dans le même process Node (cf. start/queue.ts) - Redis 7 dans le namespace rubis (PVC local-path 1Gi) - Migrations en init-container avant le serveur (idempotent) Infra : - K3s namespace rubis (déjà existant) — ajout deploy/svc rubis-app + redis - NodePort 30110 → Traefik → app.rubis.arthurbarre.fr (TLS Let's Encrypt) - Postgres : base rubis_prod + user rubis créés sur 10.10.10.3 - MinIO : bucket rubis-prod-invoices créé via mc - Secrets K3s posés via kubectl create secret (APP_KEY généré, DB pwd généré, MinIO root creds réutilisées, Resend/Mistral keys) - DNS OVH A record app.rubis créé (id 5413305619) - CI Gitea : .gitea/workflows/deploy-app.yml séparé du workflow landing, filtres sur paths apps/**, packages/**, Dockerfile.app, k3s/app/** Code app : - Static middleware @adonisjs/static configuré - Wildcard route SPA fallback en fin de routes.ts - Fix erreurs strict TS qui bloquaient le build vite (unused vars, Client missing contactFirstName/LastName dans MSW) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
91 lines
3.1 KiB
YAML
91 lines
3.1 KiB
YAML
name: Build & Deploy App
|
|
|
|
# Workflow pour l'app SaaS (apps/api AdonisJS + apps/web React) déployée
|
|
# sur app.rubis.arthurbarre.fr. Image distincte de la landing.
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'apps/**'
|
|
- 'packages/**'
|
|
- 'pnpm-lock.yaml'
|
|
- 'pnpm-workspace.yaml'
|
|
- 'package.json'
|
|
- 'turbo.json'
|
|
- 'Dockerfile.app'
|
|
- 'k3s/app/**'
|
|
- '.gitea/workflows/deploy-app.yml'
|
|
|
|
env:
|
|
REGISTRY: git.arthurbarre.fr
|
|
IMAGE: ordinarthur/rubis-app
|
|
NAMESPACE: rubis
|
|
DEPLOYMENT: rubis-app
|
|
CONTAINER: app
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ordinarthur
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push app image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: Dockerfile.app
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
|
|
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ github.sha }}
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE }}:cache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE }}:cache,mode=max
|
|
|
|
- name: Install kubectl
|
|
run: |
|
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
chmod +x kubectl
|
|
mv kubectl /usr/local/bin/
|
|
|
|
- name: Deploy to K3s
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
|
|
kubectl apply -f k3s/namespace.yml
|
|
|
|
# Idempotent : on (re)pose le pull secret du registry Gitea + le
|
|
# secret applicatif n'est PAS recréé ici (créé manuellement au
|
|
# premier deploy via kubectl, contient des creds qui ne
|
|
# transitent jamais par le CI).
|
|
kubectl -n $NAMESPACE create secret docker-registry gitea-registry \
|
|
--docker-server=$REGISTRY \
|
|
--docker-username=ordinarthur \
|
|
--docker-password=${{ secrets.REGISTRY_PASSWORD }} \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Apply Redis + app manifests (idempotent)
|
|
kubectl apply -f k3s/app/
|
|
|
|
# Pin l'image avec le sha du commit pour rolling update propre.
|
|
# Le init-container migrate utilise la même image et tourne avant
|
|
# le serveur — migrations idempotentes via ace migration:run.
|
|
kubectl -n $NAMESPACE set image deployment/$DEPLOYMENT \
|
|
$CONTAINER=$REGISTRY/$IMAGE:${{ github.sha }}
|
|
|
|
# Patch aussi le init container (même image)
|
|
kubectl -n $NAMESPACE patch deployment $DEPLOYMENT \
|
|
--type='json' \
|
|
-p="[{\"op\":\"replace\",\"path\":\"/spec/template/spec/initContainers/0/image\",\"value\":\"$REGISTRY/$IMAGE:${{ github.sha }}\"}]"
|
|
|
|
kubectl -n $NAMESPACE rollout status deployment/$DEPLOYMENT --timeout=300s
|