From 902c919fa9547c2aee698379c12bc7d214e41111 Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 12 Mar 2026 14:55:27 +0100 Subject: [PATCH] update ci cd --- .gitea/workflows/deploy.yml | 69 +++++++------------------------------ docker-compose.prod.yml | 29 ++++++---------- 2 files changed, 24 insertions(+), 74 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 1e7212a..da3a01c 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -3,20 +3,16 @@ name: Laravel CI-CD (Gitea) on: push: branches: [ "main" ] - pull_request: - branches: [ "main" ] jobs: test: name: "Tests Unitaires" runs-on: ubuntu-latest - # On ne met pas le container ici au sommet ! steps: - name: Checkout code - uses: actions/checkout@v4 # Ici, ça tournera sur l'hôte qui a Node + uses: actions/checkout@v4 - - name: Run Tests in PHP container - # On utilise "uses: docker://..." ou on définit le container pour cette étape + - name: Run Tests uses: docker://laravelsail/php84-composer:latest env: APP_ENV: testing @@ -27,8 +23,9 @@ jobs: args: | bash -c "apt-get update && apt-get install -y libicu-dev && \ docker-php-ext-configure intl && docker-php-ext-install intl && \ - composer install --no-interaction --prefer-dist && \ + composer install --no-interaction && \ php artisan test" + build: name: "Build & Push Docker" needs: test @@ -41,64 +38,24 @@ jobs: - name: Login to Gitea Registry uses: actions/docker/login@v2 with: - # Remplacez par l'URL de votre registry Gitea (ex: gitea.votre-domaine.com) registry: ${{ github.server_url }} username: ${{ github.actor }} - password: ${{ secrets.GITEA_TOKEN }} + password: ${{ secrets.TOKEN_GITEA }} - name: Build and Push run: | - IMAGE_NAME="${{ github.repository }}" # Format: user/repo - REGISTRY_URL=$(echo "${{ github.server_url }}" | sed -e 's|https://||') - FULL_IMAGE_NAME="$REGISTRY_URL/$IMAGE_NAME" - - docker build -t "$FULL_IMAGE_NAME:${{ github.sha }}" -t "$FULL_IMAGE_NAME:latest" . - docker push "$FULL_IMAGE_NAME:${{ github.sha }}" - docker push "$FULL_IMAGE_NAME:latest" + # On utilise l'image du serveur Gitea + REGISTRY=$(echo "${{ github.server_url }}" | sed -e 's|https://||') + IMAGE="$REGISTRY/${{ github.repository }}:latest" + docker build -t "$IMAGE" . + docker push "$IMAGE" deploy: - name: "Déploiement Portainer" + name: "Déploiement Simplifié" needs: build if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest - container: - image: alpine:latest steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Tools - run: apk add --no-cache curl jq gettext - - - name: Render Docker Compose - env: - # Mappez ici vos variables pour envsubst - IMAGE_TAG: ${{ github.sha }} - run: envsubst < docker-compose.prod.yml > docker-compose.rendered.yml - - - name: Deploy to Portainer - env: - PORTAINER_URL: ${{ secrets.PORTAINER_URL }} - PORTAINER_API_KEY: ${{ secrets.PORTAINER_API_KEY }} - PORTAINER_ENDPOINT_ID: ${{ secrets.PORTAINER_ENDPOINT_ID }} - PORTAINER_STACK_NAME: ${{ secrets.PORTAINER_STACK_NAME }} + - name: Trigger Portainer Webhook run: | - set -eu - PORTAINER_BASE_URL="${PORTAINER_URL%/}" - STACK_FILE_PATH="docker-compose.rendered.yml" - - # Le script reste identique au vôtre pour la logique cURL... - STACKS_RESPONSE=$(curl -sS -H "X-API-Key: $PORTAINER_API_KEY" "$PORTAINER_BASE_URL/api/stacks") - STACK_ID=$(echo "$STACKS_RESPONSE" | jq -r ".[] | select(.Name == \"$PORTAINER_STACK_NAME\") | .Id") - - if [ -z "$STACK_ID" ]; then - echo "Creating new stack..." - JSON_PAYLOAD=$(jq -n --arg name "$PORTAINER_STACK_NAME" --rawfile content "$STACK_FILE_PATH" '{name: $name, stackFileContent: $content, prune: true, fromAppTemplate: false}') - curl -sS -X POST "$PORTAINER_BASE_URL/api/stacks/create/standalone/string?endpointId=$PORTAINER_ENDPOINT_ID" \ - -H "X-API-Key: $PORTAINER_API_KEY" -H "Content-Type: application/json" --data "$JSON_PAYLOAD" - else - echo "Updating existing stack $STACK_ID..." - JSON_PAYLOAD=$(jq -n --arg id "$STACK_ID" --rawfile content "$STACK_FILE_PATH" '{id: ($id|tonumber), stackFileContent: $content, prune: false, pullImage: true}') - curl -sS -X PUT "$PORTAINER_BASE_URL/api/stacks/$STACK_ID?endpointId=$PORTAINER_ENDPOINT_ID&method=string" \ - -H "X-API-Key: $PORTAINER_API_KEY" -H "Content-Type: application/json" --data "$JSON_PAYLOAD" - fi + curl -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 0b4fe0d..35a8a02 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,16 +1,18 @@ services: - chassepeche-api: - image: "${CI_REGISTRY_IMAGE}:latest" + starter-api: + # REMPLACE par ton URL Gitea réelle + image: gitea.leonmorival.com/leon-morival/laravel-starter:latest restart: unless-stopped depends_on: - - pgsql + pgsql: + condition: service_healthy ports: - "8002:80" environment: - APP_ENV: "local" + APP_ENV: "production" # Changé de local à production APP_KEY: "${APP_KEY}" APP_URL: "${APP_URL}" - APP_DEBUG: "true" + APP_DEBUG: "false" # Sécurité : false en prod FILESYSTEM_DISK: "public" DB_CONNECTION: "pgsql" DB_HOST: "pgsql" @@ -23,14 +25,14 @@ services: - storage-public-data:/var/www/html/storage/app/public pgsql: - image: postgres:18-alpine + image: postgres:15-alpine # Attention: postgres 18 n'existe pas encore (17 max), 15 est stable restart: unless-stopped environment: POSTGRES_DB: "${DB_DATABASE}" POSTGRES_USER: "${DB_USERNAME}" POSTGRES_PASSWORD: "${DB_PASSWORD}" volumes: - - pgsql-data:/var/lib/postgresql + - pgsql-data:/var/lib/postgresql/data # Ajout de /data pour la persistance correcte ports: - "5428:5432" healthcheck: @@ -38,20 +40,11 @@ services: interval: 5s timeout: 5s retries: 10 - start_period: 10s - - adminer: - image: adminer:latest - restart: unless-stopped - ports: - - "8083:8080" # Accès via http://localhost:8080 - depends_on: - - pgsql volumes: pgsql-data: external: true - name: todo_pgsql_data + name: starter_pgsql_data storage-data: storage-public-data: - name: todo_storage_public_data + name: starter_storage_public_data