-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.8 KB
/
server.yaml
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 Go Application
on:
push:
branches:
- main
paths:
- server/**
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Install dependencies for CGO
run: |
sudo apt-get update
sudo apt-get install -y gcc libc6-dev
- name: Build Go binary with verbose output
run: |
cd server
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v -o main
env:
CGO_ENABLED: '1'
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: go-binary
path: server/main
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: go-binary
- name: Remove existing file on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S rm -f /home/seanwelch/bin/main || true
- name: Copy files to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
source: main
target: /home/seanwelch/bin/
- name: Deploy and restart service
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl stop farmec.service
sudo rm -f /home/seanwelch/server/bin/main
sudo cp /home/seanwelch/bin/main /home/seanwelch/server/bin/main
sudo chmod +x /home/seanwelch/server/bin/main
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl start farmec.service
echo ${{ secrets.SUDO_PASSWORD }} | sudo -S systemctl restart nginx