Skip to main content

On This Page

Streamlining Docker Swarm and Compose Deployments via GitHub Actions

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

I Deploy to Docker Swarm from GitHub Actions — Here’s the Setup That Actually Works

Sulthon Zainul Habib has released the docker-remote-deployment-action for GitHub Actions. This tool eliminates the need for 200-line shell scripts by automating SSH, SCP, and Docker deployment commands.

Why This Matters

Standard CI pipelines excel at building and testing but often fail at the ‘last mile’ of remote deployment, forcing engineers to rely on fragile, bespoke SSH hacks and manual file transfers. This creates a technical gap where deployment logic is decoupled from version control, increasing the risk of configuration drift and security leaks when managing private keys across multiple environments.

Key Insights

  • The docker-remote-deployment-action supports two distinct modes: docker-compose for standard containers and docker-swarm for stack deployments (v1.0.0).
  • Automated cleanup can be achieved via keep_files: N, which prunes old deployment directories on the remote host to prevent disk exhaustion.
  • Pre-deployment hooks are supported via pre_deployment_command_args, enabling critical tasks like database migrations (e.g., running rake db:migrate) before service updates.
  • Disk space management on small VPS instances is handled through an optional docker_prune: true flag that executes a system prune after deployment.

Working Examples

Minimal GitHub Action workflow setup for Docker Compose deployment.

- name: Deploy to server
uses: sulthonzh/docker-remote-deployment-action@v1
with:
remote_docker_host: [email protected]
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }}
deployment_mode: docker-compose
stack_file_name: docker-compose.yml
args: up -d

Configuration for deploying to a Docker Swarm cluster with file persistence and auto-cleanup.

- name: Deploy to Swarm
uses: sulthonzh/docker-remote-deployment-action@v1
with:
remote_docker_host: [email protected]
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh_public_key: ${{ secrets.SSH_PUBLIC_KEY }}
deployment_mode: docker-swarm
copy_stack_file: true
deploy_path: /opt/deployments/myapp
stack_file_name: docker-compose.yaml
keep_files: 5
args: myapp

Practical Applications

References:

github.com/sulthonzh/docker$-remote$-deployment$-action$

Continue reading

Next article

Why Switching to Tailwind CDN Solves LLM Responsive Design Failures

Related Content