72 lines
2.6 KiB
YAML
72 lines
2.6 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install tools
|
|
run: |
|
|
apt-get update && apt-get install -y docker.io curl jq
|
|
|
|
- name: Build production image
|
|
run: |
|
|
docker build --target frankenphp_prod -t mangarr:latest .
|
|
|
|
- name: Redeploy via Portainer API
|
|
env:
|
|
PORTAINER_USER: ${{ secrets.PORTAINER_USER }}
|
|
PORTAINER_PASSWORD: ${{ secrets.PORTAINER_PASSWORD }}
|
|
run: |
|
|
JWT=$(curl -s -X POST http://portainer:9000/api/auth \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"Username\":\"$PORTAINER_USER\",\"Password\":\"$PORTAINER_PASSWORD\"}" | jq -r '.jwt')
|
|
|
|
if [ -z "$JWT" ] || [ "$JWT" = "null" ]; then
|
|
echo "Erreur: authentification Portainer echouee"
|
|
exit 1
|
|
fi
|
|
|
|
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"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Stack ID: $STACK_ID, Endpoint ID: $ENDPOINT_ID"
|
|
|
|
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')
|
|
|
|
HTTP_CODE=$(curl -s -o /tmp/deploy_result.json -w "%{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}")
|
|
|
|
echo "Portainer redeploy: HTTP $HTTP_CODE"
|
|
if [ "$HTTP_CODE" -ge 300 ]; then
|
|
cat /tmp/deploy_result.json
|
|
exit 1
|
|
fi
|
|
|
|
- name: Run migrations
|
|
run: |
|
|
echo "Attente du demarrage de Mangarr..."
|
|
sleep 15
|
|
docker exec mangarr php bin/console doctrine:migrations:migrate --no-interaction || echo "Rien a migrer"
|
|
docker exec mangarr php bin/console cache:clear --env=prod || true
|
|
echo "Deploy termine avec succes"
|