From e20a92368e619f4c2b72ea0fc92768f6ca9cb851 Mon Sep 17 00:00:00 2001 From: canguilieme julien Date: Mon, 7 Oct 2024 22:12:10 +0200 Subject: [PATCH] add docker files --- .gitlab-ci.yml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 31bfcd9..fa8fa2c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ deploy-job: - deploiement script: - | - set -x + set -e echo "Déploiement sur Portainer..." echo "Utilisation du token API de Portainer..." @@ -34,26 +34,22 @@ deploy-job: if [ -z "$PORTAINER_API_KEY" ]; then echo "Erreur : PORTAINER_API_KEY non définie."; exit 1; fi if [ -z "$PORTAINER_URL" ]; then echo "Erreur : PORTAINER_URL non définie."; exit 1; fi if [ -z "$STACK_ID" ]; then echo "Erreur : STACK_ID non définie."; exit 1; fi + if [ -z "$ENDPOINT_ID" ]; then echo "Erreur : ENDPOINT_ID non définie."; exit 1; fi - # Affichage des variables (sauf les sensibles) - echo "PORTAINER_URL : $PORTAINER_URL" - echo "STACK_ID : $STACK_ID" + echo "Déclenchement du redeploiement de la stack Git sur Portainer..." - echo "Déploiement de la stack sur Portainer..." - - RESPONSE=$(curl -v -X PUT \ + # Exécuter la requête pour redeployer la stack Git + RESPONSE=$(curl -s -k -w "%{http_code}" -X POST \ -H "Authorization: Bearer $PORTAINER_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{"Prune": true}' \ - https://$PORTAINER_URL/api/stacks/$STACK_ID/deploy 2>&1) + "https://$PORTAINER_URL/api/stacks/$STACK_ID/git/redeploy?endpointId=$ENDPOINT_ID") - HTTP_CODE=$(echo "$RESPONSE" | grep "< HTTP/" | awk '{print $3}') - - echo "Réponse de l'API :" - echo "$RESPONSE" + # Extraire le code HTTP de la réponse + HTTP_CODE="${RESPONSE: -3}" + BODY="${RESPONSE::-3}" if [ "$HTTP_CODE" != "200" ]; then echo "Erreur : Échec du déploiement. Code HTTP : $HTTP_CODE" + echo "Réponse de l'API : $BODY" exit 1 fi