-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (69 loc) · 2.52 KB
/
Copy pathdeploy.yml
File metadata and controls
84 lines (69 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: 🚀 Deploy React App (Vite + Nginx) to Azure Blob + Ubuntu Server
on:
push:
branches: [ "dev" ] # 👈 Trigger only on dev branch
workflow_dispatch: # Allow manual runs from GitHub Actions UI
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 🧰 Step 1 — Checkout code
- name: Checkout repository
uses: actions/checkout@v4
# 🧰 Step 2 — Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
# 🏗️ Step 3 — Install dependencies and build app
- name: Install dependencies
run: npm ci
- name: Build the Vite React app
run: npm run build
# ☁️ Step 4 — Log in to Azure
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# ☁️ Step 5 — Upload assets to Azure Blob
- name: Upload built assets to Azure Blob
uses: azure/cli@v2
with:
inlineScript: |
echo "☁️ Uploading assets to Azure Blob Storage..."
az storage blob upload-batch \
--account-name ${{ secrets.AZURE_STORAGE_ACCOUNT }} \
--destination ${{ secrets.AZURE_STORAGE_CONTAINER }}/assets \
--source dist/assets \
--overwrite
# 🐳 Step 6 — Build Docker image (React + Nginx)
- name: Build Docker image
run: docker build -t taskmgt:latest .
# 📦 Step 7 — Save Docker image to tar
- name: Save Docker image as tar
run: docker save taskmgt:latest -o taskmgt.tar
# 📤 Step 8 — Copy Docker image to Ubuntu server
- name: Upload image to Ubuntu server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: "taskmgt.tar"
target: "~/"
# ⚙️ Step 9 — SSH into server and deploy container
- name: SSH into server and deploy app
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
echo "🧹 Cleaning old container..."
docker stop taskmgt || true
docker rm taskmgt || true
echo "📦 Loading new image..."
docker load -i ~/taskmgt.tar
echo "🚀 Starting new container..."
docker run -d --name taskmgt -p 80:80 taskmgt:latest
echo "✅ Deployment successful!"