Skip to content

Commit bb7df30

Browse files
Add GitHub Actions workflow for automatic deployment on release tags. This workflow triggers deployment to a droplet when a tag matching v* is pushed, utilizing SSH for secure access and including steps for building the backend and frontend applications.
1 parent d57960d commit bb7df30

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Deploy security-admin-dashboard (frontend + backend) to droplet when a release tag is pushed.
2+
# Trigger: push a tag matching v* (e.g. v1.0.0, v1.2.3).
3+
#
4+
# Required GitHub secrets:
5+
# DEPLOY_HOST - Droplet IP or hostname (e.g. 129.212.238.68)
6+
# SSH_PRIVATE_KEY - Private key for SSH (root or deploy user) to the droplet
7+
#
8+
# Optional (defaults shown):
9+
# DEPLOY_USER - SSH user (default: root)
10+
# DEPLOY_PATH - Repo path on server (default: ~/security-admin-dashboard)
11+
12+
name: Deploy on release tag
13+
14+
on:
15+
push:
16+
tags:
17+
- 'v*'
18+
19+
jobs:
20+
deploy:
21+
name: Deploy to droplet
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Get tag name
25+
id: tag
26+
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
27+
28+
- name: Deploy via SSH
29+
uses: appleboy/ssh-action@v1.0.3
30+
with:
31+
host: ${{ secrets.DEPLOY_HOST }}
32+
username: ${{ secrets.DEPLOY_USER || 'root' }}
33+
key: ${{ secrets.SSH_PRIVATE_KEY }}
34+
port: 22
35+
script: |
36+
set -e
37+
DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}"
38+
[ -z "$DEPLOY_PATH" ] && DEPLOY_PATH=~/security-admin-dashboard
39+
TAG="${{ steps.tag.outputs.TAG }}"
40+
echo "Deploying tag: $TAG to $DEPLOY_PATH"
41+
cd "$DEPLOY_PATH"
42+
git fetch --tags origin
43+
git checkout "$TAG"
44+
echo "Building backend..."
45+
cd backend && npm ci && npm run build && cd ..
46+
echo "Installing frontend dependencies..."
47+
cd frontend && npm ci && cd ..
48+
echo "Restarting dashboard apps..."
49+
pm2 restart dashboard-backend dashboard-frontend
50+
pm2 save
51+
echo "Deploy completed: $TAG"

0 commit comments

Comments
 (0)