-
Notifications
You must be signed in to change notification settings - Fork 1
61 lines (50 loc) · 1.82 KB
/
Copy pathdeploy.yml
File metadata and controls
61 lines (50 loc) · 1.82 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
name: Build and Deploy Go Project
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
container:
image: almalinux:8.10
steps:
- name: Install dependencies
run: |
dnf -y install golang make git
- name: Checkout code
uses: actions/checkout@v4
# Install project dependencies
- name: Install project deps
run: go install -buildvcs=false
# Build project
- name: Build project
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -buildvcs=false -o ./bin/main ./main.go
# Verify output exists
- name: Verify build output
run: ls -lh ./bin/main
# Setup SSH key for deploy
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.TULUCENTRE_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.TULUCENTRE_SERVER_IP }} >> ~/.ssh/known_hosts
# Stop existing pm2 process
- name: Stop existing pm2 process
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.TULUCENTRE_SERVER_USER }}@${{ secrets.TULUCENTRE_SERVER_IP }} \
'pm2 stop file-server || true; [ -f /home/tulucentre/main ] && rm -f /home/tulucentre/main || true'
# Copy files to server
- name: Copy files to server
run: |
scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ./bin/main \
${{ secrets.TULUCENTRE_SERVER_USER }}@${{ secrets.TULUCENTRE_SERVER_IP }}:/home/tulucentre/
# Restart pm2 process
- name: Restart pm2 process
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.TULUCENTRE_SERVER_USER }}@${{ secrets.TULUCENTRE_SERVER_IP }} \
'pm2 restart file-server'