-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add deployment with Portainer #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.inputs.image_version }} | ||
| runs-on: | ||
| group: portainer-deployment | ||
| # environment: staging | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| clean: true | ||
|
|
||
| - name: Check if stack exists in Portainer | ||
| id: check_stack | ||
| env: | ||
| PORTAINER_URL: ${{ secrets.PORTAINER_URL }} | ||
| PORTAINER_API_TOKEN: ${{ secrets.PORTAINER_API_TOKEN }} | ||
| run: | | ||
| RESPONSE=$(curl -s -H "X-API-Key: ${{ secrets.PORTAINER_API_TOKEN }}" "${{ secrets.PORTAINER_URL }}/api/stacks") | ||
| STACK_ID=$(echo "$RESPONSE" | jq -r --arg name "$STACK_NAME" '.[] | select(.Name == $name) | .Id') | ||
|
|
||
| if [ -n "$STACK_ID" ]; then | ||
| echo "Stack exists. ID: $STACK_ID" | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| echo "stack_id=$STACK_ID" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Stack does not exist." | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Render docker-compose.yml with envsubst | ||
| env: | ||
| DOCKER_COMPOSE_PATH: ./deploy/docker-compose.staging.yml | ||
| # export here all secrets used in the docker-compose environment | ||
| SIGNING_IMAGE_VERSION: ${{ github.event.inputs.image_version || 'latest' }} | ||
| CONFIG_1_FULL: ${{ secrets.CONFIG_1_FULL }} | ||
| CONFIG_2_FULL: ${{ secrets.CONFIG_2_FULL }} | ||
| CONFIG_3_FULL: ${{ secrets.CONFIG_3_FULL }} | ||
| KEYSHARE_1: ${{ secrets.KEYSHARE_1 }} | ||
| KEYSHARE_2: ${{ secrets.KEYSHARE_2}} | ||
| KEYSHARE_3: ${{ secrets.KEYSHARE_3 }} | ||
| run: | | ||
| envsubst < ${DOCKER_COMPOSE_PATH} > docker-compose.rendered.yml | ||
| echo "Rendered docker-compose" | ||
|
|
||
| - name: Deploy stack (create or update) | ||
| env: | ||
| PORTAINER_URL: ${{ secrets.PORTAINER_URL }} | ||
| PORTAINER_API_TOKEN: ${{ secrets.PORTAINER_API_TOKEN }} | ||
| run: | | ||
| ESCAPED_COMPOSE=$(cat docker-compose.rendered.yml | jq -Rs .) | ||
| STACK_EXISTS="${{ steps.check_stack.outputs.exists }}" | ||
| STACK_ID="${{ steps.check_stack.outputs.stack_id }}" | ||
|
|
||
| if [ "$STACK_EXISTS" = "true" ]; then | ||
| echo "Updating existing stack with ID: $STACK_ID" | ||
|
|
||
| echo "{\"stackFileContent\": $ESCAPED_COMPOSE, \"prune\": true, \"pullImage\": true, \"env\": []}" > payload.json | ||
|
|
||
| curl -s -X PUT "$PORTAINER_URL/api/stacks/$STACK_ID?endpointId=$PORTAINER_ENDPOINT_ID" \ | ||
| -H "X-API-Key: $PORTAINER_API_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d @payload.json \ | ||
| --fail | ||
| else | ||
| echo "Creating new stack: $STACK_NAME" | ||
|
|
||
| echo "{\"name\": \"$STACK_NAME\", \"fromAppTemplate\": false, \"stackFileContent\": $ESCAPED_COMPOSE, \"env\": []}" > payload.json | ||
| cat payload.json | ||
| curl -v -s -X POST "$PORTAINER_URL/api/stacks/create/standalone/string?endpointId=$PORTAINER_ENDPOINT_ID" \ | ||
| -H "X-API-Key: $PORTAINER_API_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d @payload.json \ | ||
| --fail | ||
| fi | ||
|
|
||
| - name: Cleanup | ||
| run: rm -rf docker-compose.rendered.yml payload.json |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix the issue, explicitly add a permissions block with the minimal privilege required to the workflow file. You can place this block at the top of the workflow YAML (after name: and before on:) to apply the permission settings globally for all jobs within the workflow, or inside individual jobs if different jobs require distinct permissions. In this case, the workflow does not need to write to contents, issues, or pull requests—so contents: read is the correct, minimal starting setting. Add the permissions: stanza after line 1 and before the on: block (current line 5). No imports or other definition changes are necessary; simply the addition of a YAML block at the right place.
-
Copy modified lines R3-R5
| @@ -1,5 +1,8 @@ | ||
| name: Deploy to staging | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| run-name: Deploy Sprinter signing with Portainer to staging - ${{ github.event.inputs.image_version || 'latest' }} by @${{ github.actor }} | ||
|
|
||
| on: |
|
Go Test coverage is 54.9 %\ ✨ ✨ ✨ |
|
Go Test coverage is 54.9 %\ ✨ ✨ ✨ |
|
Go Test coverage is 54.9 %\ ✨ ✨ ✨ |
|
Go Test coverage is 54.9 %\ ✨ ✨ ✨ |
Description
Related Issue Or Context
Closes: #
How Has This Been Tested? Testing details.
Types of changes
Checklist: