59 lines
1.5 KiB
YAML
59 lines
1.5 KiB
YAML
stages:
|
|
- build
|
|
- test
|
|
- deploy
|
|
|
|
|
|
build-job:
|
|
stage: build
|
|
tags:
|
|
- deploiement
|
|
script:
|
|
- echo "Compilation du code..."
|
|
# Ajoutez vos commandes de build ici
|
|
|
|
test-job:
|
|
stage: test
|
|
tags:
|
|
- deploiement
|
|
script:
|
|
- echo "Exécution des tests..."
|
|
# Ajoutez vos commandes de test ici
|
|
|
|
deploy-job:
|
|
stage: deploy
|
|
script:
|
|
- |
|
|
set -x
|
|
echo "Déploiement sur Portainer..."
|
|
echo "Utilisation du token API de Portainer..."
|
|
|
|
# Vérification des variables d'environnement
|
|
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
|
|
|
|
# Affichage des variables (sauf les sensibles)
|
|
echo "PORTAINER_URL : $PORTAINER_URL"
|
|
echo "STACK_ID : $STACK_ID"
|
|
|
|
echo "Déploiement de la stack sur Portainer..."
|
|
|
|
RESPONSE=$(curl -v -X PUT \
|
|
-H "Authorization: Bearer $PORTAINER_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"Prune": true}' \
|
|
http://$PORTAINER_URL/api/stacks/$STACK_ID/deploy 2>&1)
|
|
|
|
HTTP_CODE=$(echo "$RESPONSE" | grep "< HTTP/" | awk '{print $3}')
|
|
|
|
echo "Réponse de l'API :"
|
|
echo "$RESPONSE"
|
|
|
|
if [ "$HTTP_CODE" != "200" ]; then
|
|
echo "Erreur : Échec du déploiement. Code HTTP : $HTTP_CODE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Déploiement terminé avec succès."
|