add docker files

This commit is contained in:
canguilieme julien 2024-10-09 22:38:49 +02:00
parent 756fc23cfe
commit 0db6ae00f0

View File

@ -3,7 +3,6 @@ stages:
- test - test
- deploy - deploy
build-job: build-job:
stage: build stage: build
tags: tags:
@ -28,22 +27,39 @@ deploy-job:
- | - |
set -e set -e
echo "Déploiement sur Portainer..." echo "Déploiement sur Portainer..."
echo "Utilisation du token API de Portainer..." echo "Authentification avec l'API de Portainer..."
# Vérification des variables d'environnement # Vérification des variables d'environnement pour les informations d'authentification
if [ -z "$PORTAINER_API_KEY" ]; then echo "Erreur : PORTAINER_API_KEY non définie."; exit 1; fi if [ -z "$PORTAINER_USERNAME" ]; then echo "Erreur : PORTAINER_USERNAME non défini."; exit 1; fi
if [ -z "$PORTAINER_URL" ]; then echo "Erreur : PORTAINER_URL non définie."; exit 1; fi if [ -z "$PORTAINER_PASSWORD" ]; then echo "Erreur : PORTAINER_PASSWORD non défini."; exit 1; fi
if [ -z "$STACK_ID" ]; then echo "Erreur : STACK_ID non définie."; exit 1; fi if [ -z "$PORTAINER_URL" ]; then echo "Erreur : PORTAINER_URL non défini."; exit 1; fi
if [ -z "$ENDPOINT_ID" ]; then echo "Erreur : ENDPOINT_ID non définie."; exit 1; fi if [ -z "$STACK_ID" ]; then echo "Erreur : STACK_ID non défini."; exit 1; fi
if [ -z "$ENDPOINT_ID" ]; then echo "Erreur : ENDPOINT_ID non défini."; exit 1; fi
# Authentification pour obtenir un JWT
AUTH_RESPONSE=$(curl -s -k -X POST \
-H "Content-Type: application/json" \
-d "{\"Username\": \"$PORTAINER_USERNAME\", \"Password\": \"$PORTAINER_PASSWORD\"}" \
"https://$PORTAINER_URL/api/auth")
# Extraire le token JWT de la réponse
JWT_TOKEN=$(echo $AUTH_RESPONSE | jq -r .jwt)
if [ "$JWT_TOKEN" == "null" ]; then
echo "Erreur : Échec de l'authentification avec Portainer."
exit 1
fi
echo "Authentification réussie. Token JWT récupéré."
echo "Déclenchement du redeploiement de la stack Git sur Portainer..." echo "Déclenchement du redeploiement de la stack Git sur Portainer..."
# Construire le corps de la requête JSON # Construire le corps de la requête JSON
DATA="{\"endpointId\": $ENDPOINT_ID}" DATA="{\"endpointId\": $ENDPOINT_ID}"
# Exécuter la requête pour redeployer la stack Git # Exécuter la requête pour redeployer la stack Git avec le JWT récupéré
RESPONSE=$(curl -s -k -w "%{http_code}" -X PUT \ RESPONSE=$(curl -s -k -w "%{http_code}" -X PUT \
-H "Authorization: Bearer $PORTAINER_API_KEY" \ -H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$DATA" \ -d "$DATA" \
"https://$PORTAINER_URL/api/stacks/$STACK_ID/git/redeploy") "https://$PORTAINER_URL/api/stacks/$STACK_ID/git/redeploy")
@ -59,4 +75,3 @@ deploy-job:
fi fi
echo "Déploiement terminé avec succès." echo "Déploiement terminé avec succès."