-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (112 loc) · 4.47 KB
/
deploy_action.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
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
113
114
115
116
117
118
119
120
121
122
name: Test and Deploy Application
on:
push:
branches: [ main ]
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: 8.3
extensions: mbstring, ctype, fileinfo, openssl, PDO, bcmath, json, tokenizer, xml
tools: composer:v2
coverage: xdebug
- name: Composer install
run: |
composer install --no-interaction --prefer-dist --optimize-autoloader
- name: Install Dependencies
run: |
npm install
npm run build
- name: Stan
run: |
make stan
- name: Tests
run: |
touch database/database.sqlite
make test
create-deployment-matrix:
name: Create deployment matrix
runs-on: ubuntu-latest
needs: ci
outputs:
DEPLOYMENT_MATRIX: ${{ steps.export-deployment-matrix.outputs.DEPLOYMENT_MATRIX }}
steps:
- uses: actions/checkout@v4
- name: Export deployment matrix
id: export-deployment-matrix
run: |
delimiter="$(openssl rand -hex 8)"
JSON="$(cat ./deployment-config.json)"
echo "DEPLOYMENT_MATRIX<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "$JSON" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
prepare-release-on-servers:
name: "${{ matrix.server.name }}: Prepare release"
runs-on: ubuntu-latest
needs: create-deployment-matrix
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-matrix.outputs.DEPLOYMENT_MATRIX) }}
steps:
- name: Create directories
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.SSH_KEY }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA
script: |
mkdir -p "${{ matrix.server.path }}/releases/${GITHUB_SHA}"
rm -rf ${{ matrix.server.path }}/releases/${GITHUB_SHA}/storage
mkdir -p ${{ matrix.server.path }}/storage/{app,public,framework,logs}
mkdir -p ${{ matrix.server.path }}/storage/framework/{cache,sessions,testing,views}
chmod -R 0777 ${{ matrix.server.path }}/storage
activate-release:
name: "${{ matrix.server.name }}: Activate release"
runs-on: ubuntu-latest
needs: [ create-deployment-matrix, prepare-release-on-servers ]
strategy:
matrix:
server: ${{ fromJson(needs.create-deployment-matrix.outputs.DEPLOYMENT_MATRIX) }}
steps:
- name: Activate release
uses: appleboy/ssh-action@master
env:
GITHUB_SHA: ${{ github.sha }}
RELEASE_PATH: ${{ matrix.server.path }}/releases/${{ github.sha }}
ACTIVE_RELEASE_PATH: ${{ matrix.server.path }}/current
STORAGE_PATH: ${{ matrix.server.path }}/storage
BASE_PATH: ${{ matrix.server.path }}
ENV_SECRET: ${{ secrets.ENV_SECRET }}
with:
host: ${{ matrix.server.ip }}
username: ${{ matrix.server.username }}
key: ${{ secrets.SSH_KEY }}
port: ${{ matrix.server.port }}
envs: GITHUB_SHA,RELEASE_PATH,ACTIVE_RELEASE_PATH,STORAGE_PATH,BASE_PATH,ENV_SECRET
script: |
cd $RELEASE_PATH && git clone git@github.com:antonL95/artistshero-laravel.git ./
cd $RELEASE_PATH && composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
cd $RELEASE_PATH && source $BASE_PATH/../.nvm/nvm.sh && npm install --no-progress && npm run build
rm -rf $RELEASE_PATH/storage
ln -s -f $STORAGE_PATH $RELEASE_PATH
/usr/bin/php $RELEASE_PATH/artisan env:decrypt --key=$ENV_SECRET --env=production
mv $RELEASE_PATH/.env.production $RELEASE_PATH/.env
/usr/bin/php $RELEASE_PATH/artisan migrate --force
/usr/bin/php $RELEASE_PATH/artisan route:clear
/usr/bin/php $RELEASE_PATH/artisan event:clear
/usr/bin/php $RELEASE_PATH/artisan view:clear
/usr/bin/php $RELEASE_PATH/artisan config:clear
/usr/bin/php $RELEASE_PATH/artisan route:cache
/usr/bin/php $RELEASE_PATH/artisan event:cache
ln -s -n -f $RELEASE_PATH $ACTIVE_RELEASE_PATH
sudo supervisorctl reload
sudo systemctl restart php8.3-fpm