-
Notifications
You must be signed in to change notification settings - Fork 50
83 lines (76 loc) · 2.53 KB
/
prod.yml
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
name: Build, Test, and Deploy for Production
on:
push:
branches:
- main
jobs:
build_and_upload_artifact:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
environment: production
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Golang
uses: actions/setup-go@v4
with:
go-version: "1.22.1"
- name: Create app config file
run: cp app-sample.env app.env
- name: Build the application
run: go build -o production_app
- name: Create app.env file
uses: vicradon/[email protected]
with:
action_input_file: "app-sample.env"
action_output_file: "app.env"
action_true_string_variables: |
MAIL_PASSWORD
SERVER_PORT: ${{ secrets.SERVER_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
USERNAME: ${{ secrets.USERNAME }}
APP_NAME: "production"
APP_URL: ${{ vars.URL}}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
MAIL_SERVER: ${{ secrets.MAIL_SERVER }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MIGRATE: "true"
- name: Copy artifacts to server
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
source: "app.env,production_app"
target: ~/deployments/production
restart_app:
runs-on: ubuntu-latest
needs: build_and_upload_artifact
environment: production
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: SSH into server and deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
script: |
mkdir -p ~/deployments/production
cd ~/deployments/production
git reset --hard
git pull origin main
pm2 restart production_app