Skip to content

Commit c1d8f40

Browse files
authored
Create deploy.yml
1 parent 38859f9 commit c1d8f40

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: grpc-crud CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.23.0'
21+
22+
- name: Install dependencies
23+
run: go mod download
24+
25+
- name: Build application
26+
run: go build -o grpc-crud .
27+
28+
- name: Deploy to EC2
29+
if: (github.event_name == 'push' || github.event_name == 'pull_request') && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
30+
uses: easingthemes/ssh-deploy@main
31+
with:
32+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
33+
ARGS: "-rlgoDzvc -i --delete"
34+
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
35+
REMOTE_USER: ${{ secrets.REMOTE_USER }}
36+
TARGET: ${{ secrets.REMOTE_TARGET }}
37+
EXCLUDE: "uploads/, *.pem, *.env, .git*"
38+
39+
- name: Restart Application on EC2
40+
if: (github.event_name == 'push' || github.event_name == 'pull_request') && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
41+
uses: appleboy/ssh-action@master
42+
with:
43+
host: ${{ secrets.REMOTE_HOST }}
44+
username: ${{ secrets.REMOTE_USER }}
45+
key: ${{ secrets.SSH_PRIVATE_KEY }}
46+
script: |
47+
cd ${{ secrets.REMOTE_TARGET }}
48+
if pm2 list | grep -q "grpc-crud"; then
49+
pm2 reload grpc-crud
50+
else
51+
pm2 start ./grpc-crud --name grpc-crud --interpreter none
52+
fi
53+
pm2 save

0 commit comments

Comments
 (0)