This commit is contained in:
parent
8bebde2f58
commit
8d261a9de3
@@ -7,9 +7,6 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
|
||||||
volumes:
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -27,7 +24,6 @@ jobs:
|
|||||||
PORTAINER_USER: ${{ secrets.PORTAINER_USER }}
|
PORTAINER_USER: ${{ secrets.PORTAINER_USER }}
|
||||||
PORTAINER_PASSWORD: ${{ secrets.PORTAINER_PASSWORD }}
|
PORTAINER_PASSWORD: ${{ secrets.PORTAINER_PASSWORD }}
|
||||||
run: |
|
run: |
|
||||||
# Authentification
|
|
||||||
JWT=$(curl -s -X POST http://portainer:9000/api/auth \
|
JWT=$(curl -s -X POST http://portainer:9000/api/auth \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"Username\":\"$PORTAINER_USER\",\"Password\":\"$PORTAINER_PASSWORD\"}" | jq -r '.jwt')
|
-d "{\"Username\":\"$PORTAINER_USER\",\"Password\":\"$PORTAINER_PASSWORD\"}" | jq -r '.jwt')
|
||||||
@@ -37,37 +33,32 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Recuperer les infos de la stack mangarr
|
|
||||||
STACK_INFO=$(curl -s http://portainer:9000/api/stacks \
|
STACK_INFO=$(curl -s http://portainer:9000/api/stacks \
|
||||||
-H "Authorization: Bearer $JWT")
|
-H "Authorization: Bearer $JWT")
|
||||||
STACK_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .Id')
|
STACK_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .Id')
|
||||||
ENDPOINT_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .EndpointId')
|
ENDPOINT_ID=$(echo "$STACK_INFO" | jq '.[] | select(.Name=="mangarr") | .EndpointId')
|
||||||
|
|
||||||
if [ -z "$STACK_ID" ] || [ "$STACK_ID" = "null" ]; then
|
if [ -z "$STACK_ID" ] || [ "$STACK_ID" = "null" ]; then
|
||||||
echo "Erreur: stack mangarr non trouvee dans Portainer"
|
echo "Erreur: stack mangarr non trouvee"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Stack ID: $STACK_ID, Endpoint ID: $ENDPOINT_ID"
|
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" \
|
STACK_FILE=$(curl -s "http://portainer:9000/api/stacks/$STACK_ID/file" \
|
||||||
-H "Authorization: Bearer $JWT" | jq -r '.StackFileContent')
|
-H "Authorization: Bearer $JWT" | jq -r '.StackFileContent')
|
||||||
STACK_ENV=$(curl -s "http://portainer:9000/api/stacks/$STACK_ID" \
|
STACK_ENV=$(curl -s "http://portainer:9000/api/stacks/$STACK_ID" \
|
||||||
-H "Authorization: Bearer $JWT" | jq '.Env')
|
-H "Authorization: Bearer $JWT" | jq '.Env')
|
||||||
|
|
||||||
# Redeployer la stack (recree les containers avec la nouvelle image)
|
HTTP_CODE=$(curl -s -o /tmp/deploy_result.json -w "%{http_code}" -X PUT \
|
||||||
DEPLOY_RESULT=$(curl -s -w "\n%{http_code}" -X PUT \
|
|
||||||
"http://portainer:9000/api/stacks/$STACK_ID?endpointId=$ENDPOINT_ID" \
|
"http://portainer:9000/api/stacks/$STACK_ID?endpointId=$ENDPOINT_ID" \
|
||||||
-H "Authorization: Bearer $JWT" \
|
-H "Authorization: Bearer $JWT" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"stackFileContent\":$(echo "$STACK_FILE" | jq -Rs .),\"env\":$STACK_ENV,\"prune\":true,\"pullImage\":false}")
|
-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"
|
echo "Portainer redeploy: HTTP $HTTP_CODE"
|
||||||
|
|
||||||
if [ "$HTTP_CODE" -ge 300 ]; then
|
if [ "$HTTP_CODE" -ge 300 ]; then
|
||||||
echo "$DEPLOY_RESULT" | head -n -1
|
cat /tmp/deploy_result.json
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -75,6 +66,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "Attente du demarrage de Mangarr..."
|
echo "Attente du demarrage de Mangarr..."
|
||||||
sleep 15
|
sleep 15
|
||||||
docker exec mangarr php bin/console doctrine:migrations:migrate --no-interaction || echo "Migrations: rien a migrer"
|
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
|
docker exec mangarr php bin/console cache:clear --env=prod || true
|
||||||
echo "Deploy termine avec succes"
|
echo "Deploy termine avec succes"
|
||||||
|
|||||||
Reference in New Issue
Block a user