Examples
💡 Click on the heading to expand/collapse the item.
Steps
Deploy from the repository
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
Deploy from a compose file
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
type: file
Deploy from a different repository
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
repo: https://github.com/user/some-other-repo
ref: refs/heads/master
Specify environment variables
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
env_json: '{"KEY": "Value"}'
env_file: .env
Merging existing environment variables
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
env_json: '{"KEY": "Value"}'
merge_env: true
Multiline JSON data input
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
env_json: |
{
"APP_PRIVATE_KEY": "${{ secrets.APP_PRIVATE_KEY }}",
"VERSION": "${{ inputs.VERSION }}"
}
Only run on release events
This is done by setting: if: ${{ github.event_name == 'release' }}
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
if: ${{ github.event_name == 'release' }}
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
Deploy with relative path volumes
yaml
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
fs_path: /mnt
Multi-Step
Use Output with toJSON - hashicorp/vault-action
yaml
- name: "Import Secrets"
id: import-secrets
uses: hashicorp/vault-action@v2
with:
url: https://vault.mycompany.com:8200
token: ${{ secrets.VAULT_TOKEN }}
caCertificate: ${{ secrets.VAULT_CA_CERT }}
secrets: |
secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
secret/data/ci npm_token
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
url: ${{ secrets.PORTAINER_URL }}
token: ${{ secrets.PORTAINER_TOKEN }}
env_json: ${{ toJSON(steps.import-secrets.outputs) }}
Workflows
Full Workflow Example
yaml
name: "Portainer Stack Deploy"
on:
workflow_dispatch:
inputs:
tags:
description: "Tags: comma,separated"
required: true
default: "latest"
env:
REGISTRY: "ghcr.io"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
packages: write
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Setup Buildx"
uses: docker/setup-buildx-action@v3
with:
platforms: "linux/amd64,linux/arm64"
- name: "Docker Login"
uses: docker/login-action@v3
with:
registry: $${{ env.REGISTRY }}
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_PASS }}
- name: "Generate Tags"
id: tags
uses: cssnr/docker-tags-action@v1
with:
images: $${{ env.REGISTRY }}/${{ github.repository }}
tags: ${{ inputs.tags }}
- name: "Build and Push"
uses: docker/build-push-action@v6
with:
context: .
platforms: "linux/amd64,linux/arm64"
push: true
tags: ${{ steps.tags.outputs.tags }}
labels: ${{ steps.tags.outputs.labels }}
deploy:
name: "Deploy"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: build
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Portainer Deploy"
uses: cssnr/portainer-stack-deploy-action@v1
with:
token: ${{ secrets.PORTAINER_TOKEN }}
url: https://portainer.example.com
name: stack-name
file: docker-compose-swarm.yaml
cleanup:
name: "Cleanup"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: deploy
steps:
- name: "Purge Cache"
uses: cssnr/cloudflare-purge-cache-action@v2
with:
token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
zones: cssnr.com
For more examples, you can check out other projects using this action:
https://github.com/cssnr/portainer-stack-deploy-action/network/dependents