fix env deploy
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 33s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 33s
This commit is contained in:
@@ -49,13 +49,24 @@ jobs:
|
||||
echo "STACK_ID=$STACK_ID" >> $GITHUB_ENV
|
||||
echo "Got stack ID: $STACK_ID matched with Endpoint ID: $ENDPOINT_ID"
|
||||
|
||||
- name: Fetch Stack
|
||||
run: |
|
||||
# Get the stack details (including env vars)
|
||||
STACK_DETAILS=$(curl -s -H "X-API-Key: $PORTAINER_TOKEN" "$PORTAINER_API_URL/stacks/$STACK_ID")
|
||||
|
||||
# Extract environment variables from the stack
|
||||
echo "$STACK_DETAILS" | jq -r '.Env' > stack_env.json
|
||||
|
||||
echo "Existing stack environment variables:"
|
||||
cat stack_env.json
|
||||
|
||||
- name: Redeploy stack in Portainer
|
||||
run: |
|
||||
# Read stack file content
|
||||
STACK_FILE_CONTENT=$(echo "$(<prod-compose.yml )")
|
||||
|
||||
# Parse .env file into JSON array format for Portainer
|
||||
ENV_VARS=$(cat .env | grep -v '^#' | grep -v '^$' | jq -R -s -c 'split("\n") | map(select(length > 0)) | map(split("=") | {name: .[0], value: (.[1:] | join("="))}) | map(select(.name != ""))')
|
||||
# Read existing environment variables from the fetched stack
|
||||
ENV_VARS=$(cat stack_env.json)
|
||||
|
||||
# Prepare JSON payload with environment variables
|
||||
JSON_PAYLOAD=$(jq -n --arg stackFileContent "$STACK_FILE_CONTENT" --argjson pullImage true --argjson env "$ENV_VARS" \
|
||||
|
||||
Reference in New Issue
Block a user