Skip to content

Commit 5d713d5

Browse files
authored
Update README.md
1 parent 3c347ea commit 5d713d5

File tree

1 file changed

+58
-17
lines changed

1 file changed

+58
-17
lines changed

README.md

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
# GitHub Actions SSH Docker Update Template
1+
# GitHub Actions SSH Git Update Template
22

3-
This repository provides a **GitHub Actions CI/CD template** to automatically **update and restart a Docker Compose project** on a remote server using **SSH**.
3+
This repository provides a **GitHub Actions CI/CD template** to automatically **update code from Git** and **restart a Linux service or PM2-managed app** on a remote server using **SSH**.
44

5-
> 📦 Ideal for quickly deploying updates to remote Docker apps from your GitHub repository.
5+
> 🚀 Ideal for deploying updates to remote Git projects directly from your GitHub repository.
66
77
---
88

9-
## 🚀 Features
9+
## Features
1010

1111
- ✅ Automatic deployment on push to `main` (or any branch)
12-
- 🔐 Secure connection via SSH with secrets
13-
- 🐳 Docker Compose support (`docker compose pull` + `up -d`)
14-
- 🔁 Easy to fork and reuse across projects
12+
- 🔐 Secure connection via SSH (using GitHub secrets)
13+
- 🌀 Pulls the latest code from Git
14+
- 🔁 Restarts a **Linux service** or **PM2 process**
15+
- 🔧 Easy to fork and adapt for any project
1516

1617
---
1718

@@ -28,10 +29,11 @@ This repository provides a **GitHub Actions CI/CD template** to automatically **
2829
## ⚙️ Prerequisites
2930

3031
1. Remote server with:
31-
- Docker & Docker Compose installed
32-
- Public SSH key of the GitHub Action added to `~/.ssh/authorized_keys`
32+
- Git installed
33+
- PM2 (for Node.js apps) or a systemd-managed service
34+
- SSH access configured
3335
2. GitHub repository with:
34-
- This template forked or cloned
36+
- This template copied or forked
3537
- Required secrets added (see below)
3638

3739
---
@@ -45,11 +47,13 @@ Go to your repo → **Settings** → **Secrets and variables** → **Actions**
4547
| `SSH_HOST` | IP or domain of your remote server |
4648
| `SSH_USERNAME` | SSH user with access to the project directory |
4749
| `SSH_KEY` | Private SSH key (no passphrase) |
48-
| `PROJECT_PATH` | Absolute path of the Docker Compose project |
50+
| `SSH_PASSWORD` | SSH password with access to the project directory |
51+
| `PROJECT_PATH` | Absolute path of the Git project on the server |
52+
| `RESTART_COMMAND` | Command to restart the service or PM2 app |
4953

5054
---
5155

52-
## 📦 GitHub Actions Workflow (`.github/workflows/deploy.yml`)
56+
## 📦 GitHub Actions Workflow - SSH by Key (`.github/workflows/git-ssh-key.yml`)
5357

5458
```yaml
5559
name: Deploy via SSH
@@ -76,9 +80,44 @@ jobs:
7680
run: |
7781
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
7882
cd ${{ secrets.PROJECT_PATH }}
79-
git pull origin main
80-
docker compose pull
81-
docker compose up -d
83+
git fetch origin main
84+
git reset --hard origin/main
85+
git clean -fd
86+
${{ secrets.RESTART_COMMAND }}
87+
EOF
88+
```
89+
90+
## 📦 GitHub Actions Workflow - SSH by Password (`.github/workflows/git-ssh-password.yml`)
91+
92+
```yaml
93+
name: Deploy via SSH
94+
95+
on:
96+
push:
97+
branches:
98+
- main
99+
100+
jobs:
101+
deploy:
102+
runs-on: ubuntu-latest
103+
104+
steps:
105+
- name: Checkout repo
106+
uses: actions/checkout@v4
107+
108+
- name: Set up SSH
109+
uses: webfactory/ssh-agent@v0.9.0
110+
with:
111+
ssh-private-key: ${{ secrets.SSH_KEY }}
112+
113+
- name: Connect and Deploy
114+
run: |
115+
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} << 'EOF'
116+
cd ${{ secrets.PROJECT_PATH }}
117+
git fetch origin main
118+
git reset --hard origin/main
119+
git clean -fd
120+
${{ secrets.RESTART_COMMAND }}
82121
EOF
83122
```
84123

@@ -93,9 +132,11 @@ jobs:
93132

94133
Change main to another branch in the on.push.branches section
95134

96-
Adjust the docker compose commands if your setup differs
135+
Use different `RESTART_COMMAND` values such as:
97136

98-
Add steps for migrations, backups, health checks, etc.
137+
- `pm2 restart app-name`
138+
- `sudo systemctl restart my-service`
139+
- `npm run build && pm2 reload ecosystem.config.js`
99140

100141
## 🧪 Testing
101142

0 commit comments

Comments
 (0)