-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (106 loc) · 4.37 KB
/
frontend.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Build and Deploy
env:
PROJECT_NAME: bozo # Change project name
PROJECT_TYPE: frontend # Change to frontend for frontend deployment
WORKING_DIRECTORY: frontend # Change to frontend for frontend deployment
DEV_APP_PORT: 3618 # Update this port as needed
DEV_DOMAIN_NAME: bozo.avrean.net # Change domain name
PROD_APP_PORT: 3620 # Update this port as needed
PROD_DOMAIN_NAME: bozo.network # Change domain name
ENABLE_CACHE: false
ENABLE_CACHE_CONTROL: false
ENABLE_RATE_LIMITING: false
DEV_SERVER_USER: ${{ secrets.SERVER_HETZNER_USER }}
DEV_SERVER_IP: ${{ secrets.SERVER_HETZNER_IP }}
DEV_SERVER_PASSWORD: ${{ secrets.SERVER_HETZNER_DEV_PASSWORD }}
PROD_SERVER_USER: ${{ secrets.SERVER_HETZNER_USER }}
PROD_SERVER_IP: ${{ secrets.SERVER_HETZNER_IP }}
PROD_SERVER_PASSWORD: ${{ secrets.SERVER_HETZNER_DEV_PASSWORD }}
on:
push:
branches:
- "*"
paths:
- "frontend/**/*" # Change path
workflow_dispatch:
inputs:
ref:
description: "The branch, tag or SHA to run this workflow on"
required: true
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Cache Node.js packages
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- run: npm install -g pnpm
- run: pnpm install --no-frozen-lockfile
- run: pnpm run lint
- run: pnpm run build
deploy:
needs: [build]
runs-on: ubuntu-latest
if: (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main') && success()
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set environment variables for Dev
if: github.ref == 'refs/heads/dev'
run: |
echo "SERVER_USER=${{ env.DEV_SERVER_USER }}" >> $GITHUB_ENV
echo "SERVER_IP=${{ env.DEV_SERVER_IP }}" >> $GITHUB_ENV
echo "SERVER_PASSWORD=${{ env.DEV_SERVER_PASSWORD }}" >> $GITHUB_ENV
echo "ENVIRONMENT=dev" >> $GITHUB_ENV
echo "APP_PORT=${{ env.DEV_APP_PORT }}" >> $GITHUB_ENV
echo "DOMAIN_NAME=${{ env.DEV_DOMAIN_NAME }}" >> $GITHUB_ENV
- name: Set environment variables for Prod
if: github.ref != 'refs/heads/dev'
run: |
echo "SERVER_USER=${{ env.PROD_SERVER_USER }}" >> $GITHUB_ENV
echo "SERVER_IP=${{ env.PROD_SERVER_IP }}" >> $GITHUB_ENV
echo "SERVER_PASSWORD=${{ env.PROD_SERVER_PASSWORD }}" >> $GITHUB_ENV
echo "ENVIRONMENT=prod" >> $GITHUB_ENV
echo "APP_PORT=${{ env.PROD_APP_PORT }}" >> $GITHUB_ENV
echo "DOMAIN_NAME=${{ env.PROD_DOMAIN_NAME }}" >> $GITHUB_ENV
- name: SSH and Prepare Server
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ env.SERVER_IP }}
username: ${{ env.SERVER_USER }}
password: ${{ env.SERVER_PASSWORD }}
script: |
rm -rf /home/${{ env.SERVER_USER }}/sites/${{ env.PROJECT_NAME }}/${{ env.ENVIRONMENT }}/${{ env.PROJECT_TYPE }}
mkdir -p /home/${{ env.SERVER_USER }}/sites/${{ env.PROJECT_NAME }}/${{ env.ENVIRONMENT }}/${{ env.PROJECT_TYPE }}
- name: SCP to Server
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ env.SERVER_IP }}
username: ${{ env.SERVER_USER }}
password: ${{ env.SERVER_PASSWORD }}
source: ${{ env.WORKING_DIRECTORY }}
target: /home/${{ env.SERVER_USER }}/sites/${{ env.PROJECT_NAME }}/${{ env.ENVIRONMENT }}/
- name: Deploy
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ env.SERVER_IP }}
username: ${{ env.SERVER_USER }}
password: ${{ env.SERVER_PASSWORD }}
script: |
/home/dev/scripts/start_script.sh -e ${{ env.ENVIRONMENT }} -p ${{ env.PROJECT_NAME }} -d ${{env.WORKING_DIRECTORY}} -t ${{ env.PROJECT_TYPE }} -P ${{ env.APP_PORT }} -s ${{ env.DOMAIN_NAME }} -r ${{ env.ENABLE_RATE_LIMITING }} -c ${{ env.ENABLE_CACHE }} -C ${{ env.ENABLE_CACHE_CONTROL }} -v true