TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

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.

1 1 Language: null License: MIT Updated: 9mo ago

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

  1. Remote server with:
    • Docker & Docker Compose installed
    • Public SSH key of the GitHub Action added to ~/.ssh/authorized_keys
  2. 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

0 AIs selected
Clear selection
#
Name
Task