BaseMax / github-actions-ssh-docker-update
A ready-to-use GitHub Actions template for CI/CD deployments via SSH. Automatically pull, rebuild, and restart Docker Compose services on a remote server whenever you push to your repository. Ideal for personal projects, VPS-based apps, and quick Docker updates without extra tools.
README
GitHub Actions SSH Docker Update Template
This repository provides a GitHub Actions CI/CD template to automatically update and restart a Docker Compose project on a remote server using SSH.
๐ฆ Ideal for quickly deploying updates to remote Docker apps from your GitHub repository.
๐ Features
- โ
Automatic deployment on push to
main(or any branch) - ๐ Secure connection via SSH with secrets
- ๐ณ Docker Compose support (
docker compose pull+up -d) - ๐ Easy to fork and reuse across projects
๐ Project Structure
.github/
โโโ workflows/
โโโ deploy.yml # CI/CD workflow
โ๏ธ Prerequisites
- Remote server with:
- Docker & Docker Compose installed
- Public SSH key of the GitHub Action added to
~/.ssh/authorized_keys
- GitHub repository with:
- This template forked or cloned
- Required secrets added (see below)
๐ Required GitHub Secrets
Go to your repo โ Settings โ Secrets and variables โ Actions โ New repository secret and add:
| Secret Name | Description |
|---|---|
SSH_HOST |
IP or domain of your remote server |
SSH_PORT |
IP or domain of your remote server |
SSH_USERNAME |
SSH user with access to the project directory |
SSH_KEY |
Private SSH key (no passphrase) |
SSH_PASSWORD |
SSH Passphrase |
PROJECT_DIRECTORY |
Absolute path of the Docker Compose project |
๐ฆ GitHub Actions Workflow (.github/workflows/deploy-docker-ssh-key.yml)
name: Deploy via SSH by Key
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Connect and Deploy
run: |
ssh -e ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
cd ${{ secrets.PROJECT_DIRECTORY }}
git fetch origin main
git reset --hard origin/main
git clean -fd
docker compose up --build -d
EOF
๐ฆ GitHub Actions Workflow (.github/workflows/deploy-docker-ssh-password.yml)
name: Deploy via SSH by Password
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Install sshpass
run: sudo apt-get update && sudo apt-get install -y sshpass
- name: Deploy to Server via SSH
env:
SSHPASS: ${{ secrets.SSH_PASSWORD }}
run: |
sshpass -e ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << EOF
cd ${{ secrets.PROJECT_DIRECTORY }}
git fetch origin main
git reset --hard origin/main
git clean -fd
docker compose up --build -d
EOF
๐ Quick Start
- Fork this repo (or copy deploy.yml to your own)
- Add the required GitHub secrets
- Ensure SSH access from GitHub to your remote server
- Push to main branch โ the deployment runs automatically!
๐ ๏ธ Customization
Change main to another branch in the on.push.branches section
Adjust the docker compose commands if your setup differs
Add steps for migrations, backups, health checks, etc.
๐งช Testing
You can manually trigger a run from GitHub:
Go to Actions โ Deploy via SSH โ Run workflow
๐งพ License
MIT License โ feel free to use and adapt.
๐โโ๏ธ Author
Max Base (Ali)
๐ GitHub: @BaseMax
