forked from sprintertech/sygma-relayer
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9fdc697
Add deployment with Portainer
akandic47 5d7b86c
Test on PR
akandic47 b15e85a
Add virtual host and tweak commands
akandic47 f9b82d5
Add environment to workflow
akandic47 4dbb298
Temp test
akandic47 99c7fe0
Add labels to docker compose
akandic47 e7d0055
Substitute no switch variables
akandic47 1c1f347
Switch to no_var
akandic47 91e4cff
Add one more dollar
akandic47 f56cc4f
Remove deploy on pull request
akandic47 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: Deploy to staging | ||
|
|
||
| run-name: Deploy Sprinter signing with Portainer to staging - ${{ github.event.inputs.image_version || 'latest' }} by @${{ github.actor }} | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Publish Latest Docker Image"] | ||
| types: | ||
| - completed | ||
| workflow_dispatch: | ||
| inputs: | ||
| image_version: | ||
| description: 'Signing version. Example: v2.0.0' | ||
| required: true | ||
| default: latest | ||
| env: | ||
| PORTAINER_ENDPOINT_ID: 8 | ||
| STACK_NAME: sprinter-signing-staging | ||
|
|
||
| jobs: | ||
| deploy: | ||
| 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 }} | ||
| SPRINTER_SIGNING_DOMAIN: ${{ secrets.SPRINTER_SIGNING_DOMAIN }} | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| services: | ||
| relayer1: | ||
| image: ghcr.io/sprintertech/sprinter-signing:${SIGNING_IMAGE_VERSION} | ||
| command: | ||
| - | | ||
| mkdir -p /cfg/keyshares | ||
| echo $${${no_var}CONFIG_FULL} | base64 --decode > $${${no_var}CONFIG_PATH} | ||
| echo $${${no_var}KEYSHARE} | base64 --decode > $${${no_var}KEYSHARE_PATH} | ||
| /signing run --config $${${no_var}CONFIG_PATH} --staging | ||
| entrypoint: ["/bin/sh", "-c"] | ||
| environment: | ||
| - CONFIG_FULL=${CONFIG_1_FULL} | ||
| - KEYSHARE=${KEYSHARE_1} | ||
| - CONFIG_PATH=/cfg/config_1.json | ||
| - KEYSHARE_PATH=/cfg/keyshares/0.keyshare | ||
| - VIRTUAL_HOST=${SPRINTER_SIGNING_DOMAIN} | ||
| labels: | ||
| logging: "alloy" | ||
| logging_jobname: "containerlogs" | ||
| service_name: "signing_relayer_1_staging" | ||
| ports: | ||
| - 3000:3000 | ||
| expose: | ||
| - "3000" | ||
| restart: always | ||
|
|
||
| relayer2: | ||
| image: ghcr.io/sprintertech/sprinter-signing:${SIGNING_IMAGE_VERSION} | ||
| command: | ||
| - | | ||
| mkdir -p /cfg/keyshares | ||
| echo $${${no_var}CONFIG_FULL} | base64 --decode > $${${no_var}CONFIG_PATH} | ||
| echo $${${no_var}KEYSHARE} | base64 --decode > $${${no_var}KEYSHARE_PATH} | ||
| /signing run --config $${${no_var}CONFIG_PATH} --staging | ||
| entrypoint: ["/bin/sh", "-c"] | ||
| environment: | ||
| - CONFIG_FULL=${CONFIG_2_FULL} | ||
| - KEYSHARE=${KEYSHARE_2} | ||
| - CONFIG_PATH=/cfg/config_2.json | ||
| - KEYSHARE_PATH=/cfg/keyshares/1.keyshare | ||
| labels: | ||
| logging: "alloy" | ||
| logging_jobname: "containerlogs" | ||
| service_name: "signing_relayer_2_staging" | ||
| restart: always | ||
| ports: | ||
| - 3001:3000 | ||
|
|
||
| relayer3: | ||
| image: ghcr.io/sprintertech/sprinter-signing:${SIGNING_IMAGE_VERSION} | ||
| command: | ||
| - | | ||
| mkdir -p /cfg/keyshares | ||
| echo $${${no_var}CONFIG_FULL} | base64 --decode > $${${no_var}CONFIG_PATH} | ||
| echo $${${no_var}KEYSHARE} | base64 --decode > $${${no_var}KEYSHARE_PATH} | ||
| /signing run --config $${${no_var}CONFIG_PATH} --staging | ||
| entrypoint: ["/bin/sh", "-c"] | ||
| environment: | ||
| - CONFIG_FULL=${CONFIG_3_FULL} | ||
| - KEYSHARE=${KEYSHARE_3} | ||
| - CONFIG_PATH=/cfg/config_3.json | ||
| - KEYSHARE_PATH=/cfg/keyshares/2.keyshare | ||
| labels: | ||
| logging: "alloy" | ||
| logging_jobname: "containerlogs" | ||
| service_name: "signing_relayer_3_staging" | ||
| ports: | ||
| - 3002:3000 | ||
| restart: always | ||
|
|
||
| # nginx automatically proxies exposed container ports | ||
| nginx: | ||
| image: jwilder/nginx-proxy:1.7.1 | ||
| ports: | ||
| - "80:80" | ||
| - "443:443" | ||
| volumes: | ||
| - /var/run/docker.sock:/tmp/docker.sock:ro | ||
| - /etc/nginx/ssl:/etc/nginx/certs | ||
| restart: unless-stopped |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.