diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eeb88e6..ef7fb26 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @- <