Examples
💡 Click on the heading to expand/collapse the item.
Swarm
Swarm with Defaults
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
With Password, docker login and --with-registry-auth
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
registry_host: "ghcr.io"
registry_user: ${{ vars.GHCR_USER }}
registry_pass: ${{ secrets.GHCR_PASS }}
With SSH Key, --prune, --detach=false and --resolve-image=changed
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
detach: false
prune: true
resolve_image: "changed"
With All Swarm Inputs
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
port: 22 # 22 is default, you can remove or change this
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
env_file: "stack.env"
detach: true
prune: false
resolve_image: "always"
registry_auth: true # not needed with registry_pass/registry_user
registry_host: "ghcr.io"
registry_user: ${{ vars.GHCR_USER }}
registry_pass: ${{ secrets.GHCR_PASS }}
summary: true
Compose
Compose with Defaults
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
mode: "compose"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
Compose with Private Image
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
mode: "compose"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
registry_host: "ghcr.io"
registry_user: ${{ vars.GHCR_USER }}
registry_pass: ${{ secrets.GHCR_PASS }}
Compose with Custom Arguments
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
mode: "compose"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
args: "--remove-orphans --force-recreate"
Note: these are the default arguments. If you use args
this will override the default arguments unless they are included. You can disable them by passing an empty string. For more details, see the compose up docs.
With All Compose Inputs
yaml
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
mode: "compose"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
port: 22 # 22 is default, you can remove or change this
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
env_file: "stack.env"
registry_host: "ghcr.io"
registry_user: ${{ vars.GHCR_USER }}
registry_pass: ${{ secrets.GHCR_PASS }}
args: "--remove-orphans --force-recreate"
summary: true
Full Workflows
Simple Workflow Example
yaml
name: "Docker Stack Deploy"
on:
workflow_dispatch:
jobs:
deploy:
name: "Deploy"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
port: 22 # 22 is default, you can remove or change this
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
Full Workflow Example
yaml
name: "Docker Stack Deploy"
on:
workflow_dispatch:
inputs:
tags:
description: "Tags: comma,separated"
required: true
default: "latest"
env:
REGISTRY: "ghcr.io"
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@v2
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: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name"
file: "docker-compose.yaml"
host: ${{ secrets.DOCKER_HOST }}
user: ${{ secrets.DOCKER_USER }}
port: 22 # 22 is default, you can remove or change this
pass: ${{ secrets.DOCKER_PASS }} # not needed with ssh_key
ssh_key: ${{ secrets.DOCKER_SSH_KEY }} # not needed with pass
cleanup:
name: "Cleanup"
runs-on: ubuntu-latest
timeout-minutes: 5
needs: deploy
permissions:
contents: read
packages: write
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/stack-deploy-action/network/dependents