feat: deploy
Some checks failed
Build and Deploy / deploy (push) Failing after 1s

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2026-02-08 22:43:22 +01:00
parent 5a3e68fa2a
commit 8bebde2f58

View File

@@ -14,30 +14,67 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install Docker CLI - name: Install tools
run: | run: |
apt-get update && apt-get install -y docker.io apt-get update && apt-get install -y docker.io curl jq
- name: Build production image - name: Build production image
run: | run: |
docker build \ docker build --target frankenphp_prod -t mangarr:latest .
--target frankenphp_prod \
-t mangarr:latest \
-t mangarr:${{ gitea.sha }} \
.
- name: Deploy containers - name: Redeploy via Portainer API
env:
PORTAINER_USER: ${{ secrets.PORTAINER_USER }}
PORTAINER_PASSWORD: ${{ secrets.PORTAINER_PASSWORD }}
run: | run: |
# Redemarrer le container principal avec la nouvelle image # Authentification
docker stop mangarr mangarr-worker 2>/dev/null || true JWT=$(curl -s -X POST http://portainer:9000/api/auth \
docker rm mangarr mangarr-worker 2>/dev/null || true -H "Content-Type: application/json" \
# Portainer va recréer les containers via la stack -d "{\"Username\":\"$PORTAINER_USER\",\"Password\":\"$PORTAINER_PASSWORD\"}" | jq -r '.jwt')
echo "Image mangarr:latest buildée avec succès"
echo "Redéployez la stack via : deploy-stacks.sh mangarr" if [ -z "$JWT" ] || [ "$JWT" = "null" ]; then
echo "Erreur: authentification Portainer echouee"
exit 1
fi
# Recuperer les infos de la stack mangarr
STACK_INFO=$(curl -s http://portainer:9000/api/stacks \
-H "Authorization: Bearer $JWT")
STACK_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .Id')
ENDPOINT_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .EndpointId')
if [ -z "$STACK_ID" ] || [ "$STACK_ID" = "null" ]; then
echo "Erreur: stack mangarr non trouvee dans Portainer"
exit 1
fi
echo "Stack ID: $STACK_ID, Endpoint ID: $ENDPOINT_ID"
# Recuperer le compose et les variables actuels
STACK_FILE=$(curl -s "http://portainer:9000/api/stacks/$STACK_ID/file" \
-H "Authorization: Bearer $JWT" | jq -r '.StackFileContent')
STACK_ENV=$(curl -s "http://portainer:9000/api/stacks/$STACK_ID" \
-H "Authorization: Bearer $JWT" | jq '.Env')
# Redeployer la stack (recree les containers avec la nouvelle image)
DEPLOY_RESULT=$(curl -s -w "\n%{http_code}" -X PUT \
"http://portainer:9000/api/stacks/$STACK_ID?endpointId=$ENDPOINT_ID" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d "{\"stackFileContent\":$(echo "$STACK_FILE" | jq -Rs .),\"env\":$STACK_ENV,\"prune\":true,\"pullImage\":false}")
HTTP_CODE=$(echo "$DEPLOY_RESULT" | tail -1)
echo "Portainer redeploy: HTTP $HTTP_CODE"
if [ "$HTTP_CODE" -ge 300 ]; then
echo "$DEPLOY_RESULT" | head -n -1
exit 1
fi
- name: Run migrations - name: Run migrations
run: | run: |
# Attendre que le container soit prêt echo "Attente du demarrage de Mangarr..."
sleep 10 sleep 15
docker exec mangarr php bin/console doctrine:migrations:migrate --no-interaction 2>/dev/null || echo "Migrations: container pas encore prêt, lancer manuellement" docker exec mangarr php bin/console doctrine:migrations:migrate --no-interaction || echo "Migrations: rien a migrer"
docker exec mangarr php bin/console cache:clear --env=prod 2>/dev/null || true docker exec mangarr php bin/console cache:clear --env=prod || true
echo "Deploy termine avec succes"