update ci cd
This commit is contained in:
parent
4a156692d8
commit
902c919fa9
|
|
@ -3,20 +3,16 @@ name: Laravel CI-CD (Gitea)
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: "Tests Unitaires"
|
name: "Tests Unitaires"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# On ne met pas le container ici au sommet !
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- 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
|
- name: Run Tests
|
||||||
# On utilise "uses: docker://..." ou on définit le container pour cette étape
|
|
||||||
uses: docker://laravelsail/php84-composer:latest
|
uses: docker://laravelsail/php84-composer:latest
|
||||||
env:
|
env:
|
||||||
APP_ENV: testing
|
APP_ENV: testing
|
||||||
|
|
@ -27,8 +23,9 @@ jobs:
|
||||||
args: |
|
args: |
|
||||||
bash -c "apt-get update && apt-get install -y libicu-dev && \
|
bash -c "apt-get update && apt-get install -y libicu-dev && \
|
||||||
docker-php-ext-configure intl && docker-php-ext-install intl && \
|
docker-php-ext-configure intl && docker-php-ext-install intl && \
|
||||||
composer install --no-interaction --prefer-dist && \
|
composer install --no-interaction && \
|
||||||
php artisan test"
|
php artisan test"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: "Build & Push Docker"
|
name: "Build & Push Docker"
|
||||||
needs: test
|
needs: test
|
||||||
|
|
@ -41,64 +38,24 @@ jobs:
|
||||||
- name: Login to Gitea Registry
|
- name: Login to Gitea Registry
|
||||||
uses: actions/docker/login@v2
|
uses: actions/docker/login@v2
|
||||||
with:
|
with:
|
||||||
# Remplacez par l'URL de votre registry Gitea (ex: gitea.votre-domaine.com)
|
|
||||||
registry: ${{ github.server_url }}
|
registry: ${{ github.server_url }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITEA_TOKEN }}
|
password: ${{ secrets.TOKEN_GITEA }}
|
||||||
|
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME="${{ github.repository }}" # Format: user/repo
|
# On utilise l'image du serveur Gitea
|
||||||
REGISTRY_URL=$(echo "${{ github.server_url }}" | sed -e 's|https://||')
|
REGISTRY=$(echo "${{ github.server_url }}" | sed -e 's|https://||')
|
||||||
FULL_IMAGE_NAME="$REGISTRY_URL/$IMAGE_NAME"
|
IMAGE="$REGISTRY/${{ github.repository }}:latest"
|
||||||
|
docker build -t "$IMAGE" .
|
||||||
docker build -t "$FULL_IMAGE_NAME:${{ github.sha }}" -t "$FULL_IMAGE_NAME:latest" .
|
docker push "$IMAGE"
|
||||||
docker push "$FULL_IMAGE_NAME:${{ github.sha }}"
|
|
||||||
docker push "$FULL_IMAGE_NAME:latest"
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: "Déploiement Portainer"
|
name: "Déploiement Simplifié"
|
||||||
needs: build
|
needs: build
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
|
||||||
image: alpine:latest
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Trigger Portainer Webhook
|
||||||
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 }}
|
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
curl -X POST "${{ secrets.PORTAINER_WEBHOOK_URL }}"
|
||||||
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
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
services:
|
services:
|
||||||
chassepeche-api:
|
starter-api:
|
||||||
image: "${CI_REGISTRY_IMAGE}:latest"
|
# REMPLACE par ton URL Gitea réelle
|
||||||
|
image: gitea.leonmorival.com/leon-morival/laravel-starter:latest
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- pgsql
|
pgsql:
|
||||||
|
condition: service_healthy
|
||||||
ports:
|
ports:
|
||||||
- "8002:80"
|
- "8002:80"
|
||||||
environment:
|
environment:
|
||||||
APP_ENV: "local"
|
APP_ENV: "production" # Changé de local à production
|
||||||
APP_KEY: "${APP_KEY}"
|
APP_KEY: "${APP_KEY}"
|
||||||
APP_URL: "${APP_URL}"
|
APP_URL: "${APP_URL}"
|
||||||
APP_DEBUG: "true"
|
APP_DEBUG: "false" # Sécurité : false en prod
|
||||||
FILESYSTEM_DISK: "public"
|
FILESYSTEM_DISK: "public"
|
||||||
DB_CONNECTION: "pgsql"
|
DB_CONNECTION: "pgsql"
|
||||||
DB_HOST: "pgsql"
|
DB_HOST: "pgsql"
|
||||||
|
|
@ -23,14 +25,14 @@ services:
|
||||||
- storage-public-data:/var/www/html/storage/app/public
|
- storage-public-data:/var/www/html/storage/app/public
|
||||||
|
|
||||||
pgsql:
|
pgsql:
|
||||||
image: postgres:18-alpine
|
image: postgres:15-alpine # Attention: postgres 18 n'existe pas encore (17 max), 15 est stable
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_DB: "${DB_DATABASE}"
|
POSTGRES_DB: "${DB_DATABASE}"
|
||||||
POSTGRES_USER: "${DB_USERNAME}"
|
POSTGRES_USER: "${DB_USERNAME}"
|
||||||
POSTGRES_PASSWORD: "${DB_PASSWORD}"
|
POSTGRES_PASSWORD: "${DB_PASSWORD}"
|
||||||
volumes:
|
volumes:
|
||||||
- pgsql-data:/var/lib/postgresql
|
- pgsql-data:/var/lib/postgresql/data # Ajout de /data pour la persistance correcte
|
||||||
ports:
|
ports:
|
||||||
- "5428:5432"
|
- "5428:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|
@ -38,20 +40,11 @@ services:
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 10
|
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:
|
volumes:
|
||||||
pgsql-data:
|
pgsql-data:
|
||||||
external: true
|
external: true
|
||||||
name: todo_pgsql_data
|
name: starter_pgsql_data
|
||||||
storage-data:
|
storage-data:
|
||||||
storage-public-data:
|
storage-public-data:
|
||||||
name: todo_storage_public_data
|
name: starter_storage_public_data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue