feat: try fix ci/cd

This commit is contained in:
leon-morival 2025-11-30 17:03:00 +01:00
parent f17a561cd2
commit 1765fca240
1 changed files with 15 additions and 14 deletions

View File

@ -93,34 +93,35 @@ deploy-to-portainer:
STACKS_JSON="$BODY"
STACK_ID=$(echo "$STACKS_JSON" | jq ".[] | select(.Name == \"$PORTAINER_STACK_NAME\") | .Id")
# Contenu du compose rendu (une seule ligne, guillemets échappés)
STACK_FILE_CONTENT=$(sed 's/"/\\"/g' docker-compose.rendered.yml | tr -d '\n')
if [ -z "$STACK_ID" ]; then
echo "🆕 Aucune stack '$PORTAINER_STACK_NAME' trouvée, création en cours..."
JSON_PAYLOAD=$(jq -n \
--arg name "$PORTAINER_STACK_NAME" \
--arg content "$STACK_FILE_CONTENT" \
'{name: $name, stackFileContent: $content, prune: true}')
curl -s -X POST "$PORTAINER_URL/api/stacks?type=2&method=string&endpointId=$PORTAINER_ENDPOINT_ID" \
-H "X-API-Key: $PORTAINER_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"name": "$PORTAINER_STACK_NAME",
"stackFileContent": "$(cat docker-compose.rendered.yml | sed 's/"/\\"/g' | tr -d '\n')",
"prune": true
}
EOF
--data "$JSON_PAYLOAD"
echo "✅ Stack créée."
else
echo "♻️ Stack '$PORTAINER_STACK_NAME' trouvée (ID=$STACK_ID), mise à jour..."
JSON_PAYLOAD=$(jq -n \
--arg id "$STACK_ID" \
--arg content "$STACK_FILE_CONTENT" \
'{id: ($id|tonumber), stackFileContent: $content, prune: true}')
curl -s -X PUT "$PORTAINER_URL/api/stacks/$STACK_ID?endpointId=$PORTAINER_ENDPOINT_ID" \
-H "X-API-Key: $PORTAINER_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"id": $STACK_ID,
"stackFileContent": "$(cat docker-compose.rendered.yml | sed 's/"/\\"/g' | tr -d '\n')",
"prune": true
}
EOF
--data "$JSON_PAYLOAD"
echo "✅ Stack mise à jour."
fi