From ec729d604fa210b19ece7f126644438db9391575 Mon Sep 17 00:00:00 2001 From: Boris Waaub Date: Tue, 24 Nov 2026 15:58:17 +0100 Subject: [PATCH] Ajoute les workflows Gitea Actions et l'image du front MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .gitea/workflows/test-build.yaml : construction des images et jobs de tests (back-end : ruff, migrations, pytest ; front : lint, types, tests, build) sur les pull requests - .gitea/workflows/build-and-release.yaml : publication des images sur Harbor à chaque tag - frontend/Dockerfile, nginx.conf, .dockerignore : image du front (nginx sans privilèges sur le port 8080, relais de /api, /admin et /static vers le back-end du pod) Co-Authored-By: Claude Sonnet 5.5 --- .gitea/workflows/build-and-release.yaml | 36 ++++++++ .gitea/workflows/test-build.yaml | 111 ++++++++++++++++++++++++ frontend/.dockerignore | 4 + frontend/Dockerfile | 17 ++++ frontend/nginx.conf | 29 +++++++ 5 files changed, 197 insertions(+) create mode 100644 .gitea/workflows/build-and-release.yaml create mode 100644 .gitea/workflows/test-build.yaml create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile create mode 100644 frontend/nginx.conf diff --git a/.gitea/workflows/build-and-release.yaml b/.gitea/workflows/build-and-release.yaml new file mode 100644 index 0000000..6e59c2b --- /dev/null +++ b/.gitea/workflows/build-and-release.yaml @@ -0,0 +1,36 @@ +name: Build and release +run-name: Build and release ${{ github.ref_name }} (by ${{ gitea.actor }}) +on: + push: + tags: + - "*" + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: https://gitea.com/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Log in to Docker Registry + uses: https://gitea.com/docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + registry: h3m6q87t.gra7.container-registry.ovh.net + username: ${{ vars.OVH_REGISTRY_USERNAME }} + password: ${{ secrets.OVH_REGISTRY_PASSWORD }} + - name: Set up Docker Buildx + uses: https://gitea.com/docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 + - name: Build and push backend + uses: https://gitea.com/docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: backend + pull: true + push: true + tags: h3m6q87t.gra7.container-registry.ovh.net/prism/backend:${{ github.ref_name }} + + - name: Build and push frontend + uses: https://gitea.com/docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: frontend + pull: true + push: true + tags: h3m6q87t.gra7.container-registry.ovh.net/prism/frontend:${{ github.ref_name }} diff --git a/.gitea/workflows/test-build.yaml b/.gitea/workflows/test-build.yaml new file mode 100644 index 0000000..fa57646 --- /dev/null +++ b/.gitea/workflows/test-build.yaml @@ -0,0 +1,111 @@ +name: Test build +run-name: Build ${{ github.ref_name }} (by ${{ gitea.actor }}) +on: + pull_request: + types: + - auto_merge_enabled + - opened + - synchronize + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: https://gitea.com/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Log in to Docker Registry + uses: https://gitea.com/docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + registry: h3m6q87t.gra7.container-registry.ovh.net + username: ${{ vars.OVH_REGISTRY_USERNAME }} + password: ${{ secrets.OVH_REGISTRY_PASSWORD }} + - name: Set up Docker Buildx + uses: https://gitea.com/docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4 + - name: Build backend + uses: https://gitea.com/docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: backend + pull: true + push: false + + - name: Build frontend + uses: https://gitea.com/docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7 + with: + context: frontend + pull: true + push: false + + backend-tests: + name: Back-end (qualité et tests) + runs-on: ubuntu-latest + services: + # Base des tests, joignable sous le nom « db ». + db: + image: postgres:17 + env: + POSTGRES_DB: prism + POSTGRES_USER: prism + POSTGRES_PASSWORD: prism + options: >- + --health-cmd "pg_isready -U prism -d prism" + --health-interval 5s + --health-timeout 5s + --health-retries 10 + env: + SECRET_KEY: ci-uniquement-pas-un-secret + DEBUG: "true" + ALLOWED_HOSTS: localhost + CSRF_TRUSTED_ORIGINS: http://localhost + DATABASE_URL: postgres://prism:prism@db:5432/prism + defaults: + run: + working-directory: backend + steps: + - name: Checkout + uses: https://gitea.com/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Set up Python + uses: https://gitea.com/actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: "3.12" + - name: Install uv + run: python -m pip install "uv~=0.9" + - name: Install dependencies + run: uv sync --locked + - name: Wait for PostgreSQL + run: >- + uv run python -c "import socket,time,sys; + [(sys.exit(0) if socket.socket().connect_ex(('db',5432))==0 else time.sleep(1)) for _ in range(30)]" + - name: Ruff (lint) + run: uv run ruff check . + - name: Ruff (format) + run: uv run ruff format --check . + - name: Check migrations are up to date + run: uv run python manage.py makemigrations --check --dry-run + - name: Tests + run: uv run pytest + + frontend-tests: + name: Front-end (qualité, tests et build) + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + steps: + - name: Checkout + uses: https://gitea.com/actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - name: Set up Node + uses: https://gitea.com/actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + - name: Install dependencies + run: npm ci + - name: Lint + run: | + npx oxlint . + npx eslint . + - name: Type check + run: npm run type-check + - name: Tests + run: npm run test:unit -- --run + - name: Build + run: npm run build-only diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..86338e1 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,4 @@ +node_modules +dist +.eslintcache +Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..d1d1cf7 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,17 @@ +FROM node:24-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +RUN npm run build-only + +# Sert le front et relaie /api, /admin et /static vers le back-end du même pod (port 8000). +FROM nginxinc/nginx-unprivileged:1.27-alpine + +COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /app/dist /usr/share/nginx/html + +EXPOSE 8080 diff --git a/frontend/nginx.conf b/frontend/nginx.conf new file mode 100644 index 0000000..ac3b2b2 --- /dev/null +++ b/frontend/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 8080; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # Le back-end tourne dans le même pod que ce conteneur. + location ~ ^/(api|admin|static)/ { + proxy_pass http://127.0.0.1:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; + proxy_read_timeout 60s; + } + + # Fichiers versionnés par Vite : cache long. + location /assets/ { + try_files $uri =404; + add_header Cache-Control "public, max-age=31536000, immutable"; + } + + # Application monopage : toute autre route retombe sur index.html. + location / { + try_files $uri /index.html; + add_header Cache-Control "no-cache"; + } +}