Skip to content

Commit 53d6925

Browse files
committed
chore: add deploy to VM implementation
1 parent 268928d commit 53d6925

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

.github/workflows/cd_frontend.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ name: Deploy the frontend
22
on:
33
push:
44
branches: [main]
5+
paths:
6+
- 'apps/collabydraw/**'
7+
- 'packages/**'
8+
- '.github/workflows/cd_frontend.yml'
59
jobs:
6-
build:
10+
build-and-deploy:
711
runs-on: ubuntu-latest
812
steps:
913
- name: Checkout the code
1014
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 2
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
1120

1221
- name: Docker login
1322
uses: docker/login-action@v3
@@ -17,22 +26,45 @@ jobs:
1726

1827
- name: Verify secrets
1928
run: |
20-
if [ -z "${{ secrets.DATABASE_URL }}" ]; then
21-
echo "Error: DATABASE_URL secret is not set"
22-
exit 1
23-
fi
24-
if [ -z "${{ secrets.JWT_SECRET }}" ]; then
25-
echo "Error: JWT_SECRET secret is not set"
26-
exit 1
27-
fi
29+
secrets_valid=true
30+
for secret in DATABASE_URL JWT_SECRET WEBSOCKET_URL; do
31+
if [ -z "${{ secrets[secret] }}" ]; then
32+
echo "Error: $secret secret is not set"
33+
secrets_valid=false
34+
fi
35+
done
36+
$secrets_valid
2837
29-
- name: Build and push
38+
- name: Build and push Frontend
3039
uses: docker/build-push-action@v5
3140
with:
3241
context: .
3342
file: ./docker/Dockerfile.frontend
43+
provenance: false
3444
build-args: |
3545
DATABASE_URL=${{ secrets.DATABASE_URL }}
3646
JWT_SECRET=${{ secrets.JWT_SECRET }}
47+
WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }}
3748
push: true
38-
tags: coderomm/collabydraw:${{ github.sha }}
49+
tags: |
50+
coderomm/collabydraw:latest
51+
coderomm/collabydraw:${{ github.sha }}
52+
53+
- name: Deploy to VM
54+
uses: appleboy/ssh-action@master
55+
with:
56+
host: ${{ secrets.VM_HOST }}
57+
username: ${{ secrets.VM_USERNAME }}
58+
key: ${{ secrets.SSH_PRIVATE_KEY }}
59+
script: |
60+
docker pull coderomm/collabydraw:${{ github.sha }}
61+
docker stop collabydraw-frontend || true
62+
docker rm collabydraw-frontend || true
63+
docker run -d \
64+
--name collabydraw-frontend \
65+
-p 3000:3000 \
66+
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
67+
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \
68+
-e WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }} \
69+
coderomm/collabydraw:${{ github.sha }}
70+

.github/workflows/cd_ws.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ name: Deploy the websocket server
22
on:
33
push:
44
branches: [main]
5+
paths:
6+
- 'apps/ws/**'
7+
- 'packages/**'
8+
- '.github/workflows/cd_ws.yml'
9+
510
jobs:
6-
build:
11+
build-and-deploy:
712
runs-on: ubuntu-latest
813
steps:
914
- name: Checkout the code
1015
uses: actions/checkout@v2
1116

12-
- name: Debug - Show directory contents
13-
run: ls -la
14-
15-
- name: Debug - Show package.json
16-
run: cat package.json
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
1719

1820
- name: Docker login
1921
uses: docker/login-action@v2
@@ -26,11 +28,24 @@ jobs:
2628
with:
2729
context: .
2830
file: ./docker/Dockerfile.websocket
31+
provenance: false
2932
push: true
30-
tags: coderomm/collabydraw-websocket:${{ github.sha }}
33+
tags: |
34+
coderomm/collabydraw-websocket:latest
35+
coderomm/collabydraw-websocket:${{ github.sha }}
3136
32-
- name: Deploy to the VM
33-
run: |
34-
echo "${{ secrets.SSH_PRIVATE_KEY }}" &> ~/ssh_key
35-
chmod 700 /home/runner/ssh_key
36-
ssh -o StrictHostKeyChecking=no -i ~/ssh_key [email protected] -t "docker stop user_backend && docker run --name user_backend -d -p 8080:8080 coderomm/collabydraw-websocket:${{ github.sha }}"
37+
- name: Deploy to VM
38+
uses: appleboy/ssh-action@master
39+
with:
40+
host: ${{ secrets.VM_HOST }}
41+
username: ${{ secrets.VM_USERNAME }}
42+
key: ${{ secrets.SSH_PRIVATE_KEY }}
43+
script: |
44+
docker pull coderomm/collabydraw-websocket:${{ github.sha }}
45+
docker stop collabydraw-websocket || true
46+
docker rm collabydraw-websocket || true
47+
docker run -d \
48+
--name collabydraw-websocket \
49+
-p 8080:8080 \
50+
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
51+
coderomm/collabydraw-websocket:${{ github.sha }}

0 commit comments

Comments
 (0)