-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (158 loc) · 6.6 KB
/
release-to-prod.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Release to prod
on:
push:
#branches:
# - main
# - master
tags:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
checks:
runs-on: ubuntu-latest
name: Check application
steps:
# Setup
- uses: actions/checkout@v3
- name: '[PHP] Setup'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, intl
# Prepare application
- name: '[INIT] Check composer.json'
run: composer validate --no-check-all --no-check-publish --no-check-lock
# Install dependencies
- name: '[Install] Install composer dependencies'
run: composer install
# Check application
- name: '[CHECK] analyze'
run: composer analyze
- name: '[CHECK] phpstan'
run: composer phpstan
- name: '[CHECK] Unit tests'
run: composer test-ci
download-deploy-console:
runs-on: ubuntu-latest
name: Download deploy-console
steps:
# Deploy console
- name: '[DEPLOY-CONSOLE] Download deploy-console'
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'vysokeskoly/deploy-console'
version: 'latest'
file: 'deploy-console.phar'
token: ${{ secrets.DEPLOY_CONSOLE_RELEASE_API_KEY }}
- name: '[ARTIFACT] Upload a deploy-console'
uses: actions/upload-artifact@v3
with:
name: deploy-console
path: './deploy-console.phar'
build:
runs-on: ubuntu-latest
name: Build deb package
environment: prod
steps:
# Setup
- uses: actions/checkout@v3
# Build
- name: '[BUILD] Build deb package'
run: bin/build-deb-app
env:
BUILD_NUMBER: ${{ github.run_id }}
BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: '[ARTIFACT] Upload a deploy-console'
uses: actions/upload-artifact@v3
with:
name: deb-package
path: './*.deb'
release:
runs-on: ubuntu-latest
name: Release deb packages
needs:
- checks
- download-deploy-console
- build
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.job) }}
environment: prod
steps:
# Setup
- uses: actions/checkout@v3
- name: '[PHP] Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: mbstring, intl
- name: '[ARTIFACT] Download artifacts'
uses: actions/download-artifact@v3
- name: '[ARTIFACT] Move to root'
run: |
mv deb-package/* ./
mv deploy-console/* ./
- name: '[DEPLOY-CONSOLE] Grant execute for deploy-console'
run: chmod +x ./deploy-console.phar
- name: '[DEPLOY-CONSOLE] Display deploy-console info'
run: ./deploy-console.phar -V
- name: '[DEB] Display deb package'
run: ls -l *.deb
# Connect to VPN
- name: '[VPN] Install Open VPN'
run: sudo apt-get install openvpn
- name: '[VPN] Connect'
uses: golfzaptw/action-connect-ovpn@master
id: connect_vpn
with:
PING_URL: '172.27.128.47'
FILE_OVPN: '.github/vpn/config.ovpn'
SECRET: ${{ secrets.VPN_USERNAME_PASSWORD }}
TLS_KEY: ''
env:
CA_CRT: ${{ secrets.VPN_CA }}
USER_CRT: ${{ secrets.VPN_CRT }}
USER_KEY: ${{ secrets.VPN_KEY }}
- name: '[VPN] Check Connection'
run: echo ${{ steps.connect_vpn.outputs.STATUS }}
# SSH
- name: '[SSH] Define IP for private servers'
run: |
sudo echo "172.27.128.47 apback-2.prod" | sudo tee -a /etc/hosts
sudo echo "172.27.128.47 release.vysokeskoly.cz" | sudo tee -a /etc/hosts
- name: '[SSH] Prepare ssh key'
run: |
mkdir -p /home/runner/.ssh
echo '${{ secrets.SSH_KEY_RELEASE }}' > /home/runner/.ssh/id_rsa
chmod 700 /home/runner/.ssh/
chmod 600 /home/runner/.ssh/id_rsa
# Release to prod
- name: '[RELEASE] Release deb to prod'
uses: nick-fields/retry@v2 # https://github.com/marketplace/actions/retry-step
with:
timeout_minutes: 2
max_attempts: 3
#retry_on: timeout
command: |
./deploy-console.phar d:release prod "Github release - ${{ github.ref_type }}: ${{ github.ref_name }}" -P
# Notify
- name: Slack Notification - success
if: success()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: release
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
#SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_MESSAGE: ':rocket: Release successful :white_check_mark:'
SLACK_TITLE: SolrFeeder - Release to prod
SLACK_USERNAME: Github Action
SLACK_WEBHOOK: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
- name: Slack Notification - fail
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: release
SLACK_COLOR: ${{ job.status }} # or a specific color like 'good' or '#ff00ff'
#SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_MESSAGE: ':rocket: Release failed :boom:'
SLACK_TITLE: SolrFeeder - Release to prod
SLACK_USERNAME: Github Action
SLACK_WEBHOOK: ${{ secrets.SLACK_RELEASE_WEBHOOK }}