Getting Started
Install and Setup Guide to Begin.
To get started, create or update your workflow file and review the usage.
You can also view the features and additional examples.
Workflow
Add the step to an existing workflow or create a new one.
If creating a new workflow, place it in the .github/workflows
directory.
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name" # set to your stack name
file: "docker-compose.yaml" # set to your compose file
mode: "swarm" # if not using swarm set to "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
name: "Docker Stack Deploy"
on:
workflow_dispatch:
jobs:
deploy:
name: "Deploy"
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v5
# Add Steps to Prepare Your Stack File or Environment...
- name: "Stack Deploy"
uses: cssnr/stack-deploy-action@v1
with:
name: "stack-name" # set to your stack name
file: "docker-compose.yaml" # set to your compose file
mode: "swarm" # if not using swarm set to "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
Make sure to update the highlighted lines and add your secrets.
The only 4 required inputs are name, host, user and pass or ssh_key (not both).
See the Inputs Documentation for more options and default values.
Usage
The stack is deployed from the current actions working directory (no files copied). Therefore, all paths are relative to the actions' directory.
If you check out your repository to the root and your compose file is in the app
directory, set file to: app/docker-compose.yaml
If using the env_file compose directive in your stack file, this file's path would be relative to your docker-compose.yaml
file.
The workflow runs based on the events defined in the on:
parameter. If using the workflow_dispatch
trigger you can manually run the job at any time.
See the Inputs Documentation for more options to customize your deployment.
Command
The command used to deploy the stack is generated depending on mode.
docker stack deploy -c ${INPUT_FILE} ${EXTRA_ARGS[@]} ${INPUT_NAME}
docker compose ${STACK_FILES[@]} -p ${INPUT_NAME} up -d -y ${EXTRA_ARGS[@]}
Compose. To see how ${STACK_FILES[@]}
is generated see the file input documentation.
You can view the full deployment script on GitHub: src/main.sh
See the Inputs Documentation for more options to customize the deployment.
Secrets
You should store your credentials in GitHub Actions Secrets.
The SSH key should be copied and pasted exactly as it appears in the private keyfile.
You do not need to add all values as a secret. However, be aware that any inputs not added as a secret, will be visible in the GitHub Actions Logs.
Likewise, if you add your GitHub username or the port number 22 as a secret, these values will be replaced with ***
's anywhere they appear in the logs, including repository names.
If working within an GitHub Organization you can create these secrets in the organization and make them available to all your repositories. This is why I use the cssnr organization.
Portainer
If you use Portainer, you should deploy directly to Portainer for full control.
For this you should use: cssnr/portainer-stack-deploy-action
For more details visit the website: https://portainer-deploy.cssnr.com/
Request a Feature
If you need more options, please open a feature request