6262 if : github.ref == 'refs/heads/main'
6363 runs-on : ubuntu-latest
6464 steps :
65- - name : Trigger Portainer stack redeploy (pull latest image)
65+ - name : Trigger Portainer git redeploy
6666 env :
6767 PORTAINER_URL : ${{ secrets.PORTAINER_URL }}
6868 PORTAINER_API_KEY : ${{ secrets.PORTAINER_API_KEY }}
@@ -71,22 +71,19 @@ jobs:
7171 run : |
7272 set -euo pipefail
7373
74- # Re-deploy the existing stack with its current file + env, forcing an
75- # image pull so the freshly pushed tag is rolled out. Reusing the
76- # stored content means no secrets need to be re-supplied here.
77- content=$(curl -fsS -H "X-API-Key: $PORTAINER_API_KEY" \
78- "$PORTAINER_URL/api/stacks/$STACK_ID/file" | jq -r '.StackFileContent')
74+ # The stack is deployed from this Git repository and built on the host.
75+ # Re-pull the latest commit and rebuild, preserving the stack's stored
76+ # environment (which holds SESSION_SECRET) so no secrets are handled here.
7977 env_json=$(curl -fsS -H "X-API-Key: $PORTAINER_API_KEY" \
8078 "$PORTAINER_URL/api/stacks/$STACK_ID" | jq -c '.Env // []')
8179
82- jq -n --arg content "$content" --argjson env "$env_json" \
83- '{StackFileContent: $content, Env: $env, Prune: true, PullImage: true}' \
84- > payload.json
80+ jq -n --argjson env "$env_json" \
81+ '{env: $env, prune: true, pullImage: false}' > payload.json
8582
8683 curl -fsS -X PUT \
8784 -H "X-API-Key: $PORTAINER_API_KEY" \
8885 -H "Content-Type: application/json" \
89- "$PORTAINER_URL/api/stacks/$STACK_ID?endpointId=$ENDPOINT_ID" \
86+ "$PORTAINER_URL/api/stacks/$STACK_ID/git/redeploy ?endpointId=$ENDPOINT_ID" \
9087 --data @payload.json > /dev/null
9188
92- echo "Portainer stack $STACK_ID redeployed."
89+ echo "Portainer stack $STACK_ID redeployed from latest commit ."
0 commit comments