Skip to content

Commit cb712b4

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

File tree

2 files changed

+63
-15
lines changed

2 files changed

+63
-15
lines changed

.github/workflows/cd_frontend.yml

Lines changed: 36 additions & 3 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
@@ -25,14 +34,38 @@ jobs:
2534
echo "Error: JWT_SECRET secret is not set"
2635
exit 1
2736
fi
37+
$secrets_valid
2838
29-
- name: Build and push
39+
- name: Build and push Frontend
3040
uses: docker/build-push-action@v5
3141
with:
3242
context: .
3343
file: ./docker/Dockerfile.frontend
44+
provenance: false
3445
build-args: |
3546
DATABASE_URL=${{ secrets.DATABASE_URL }}
3647
JWT_SECRET=${{ secrets.JWT_SECRET }}
48+
WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }}
3749
push: true
38-
tags: coderomm/collabydraw:${{ github.sha }}
50+
tags: |
51+
coderomm/collabydraw:latest
52+
coderomm/collabydraw:${{ github.sha }}
53+
54+
- name: Deploy to VM
55+
uses: appleboy/[email protected]
56+
with:
57+
host: ${{ secrets.VM_HOST }}
58+
username: ${{ secrets.VM_USERNAME }}
59+
key: ${{ secrets.SSH_PRIVATE_KEY }}
60+
script: |
61+
docker pull coderomm/collabydraw:${{ github.sha }}
62+
docker stop collabydraw-frontend || true
63+
docker rm collabydraw-frontend || true
64+
docker run -d \
65+
--name collabydraw-frontend \
66+
-p 3000:3000 \
67+
-e DATABASE_URL=${{ secrets.DATABASE_URL }} \
68+
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \
69+
-e WEBSOCKET_URL=${{ secrets.WEBSOCKET_URL }} \
70+
coderomm/collabydraw:${{ github.sha }}
71+

.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/[email protected]
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)