-
Notifications
You must be signed in to change notification settings - Fork 3
144 lines (123 loc) · 4.28 KB
/
deploy-stage.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
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
name: "Deploy to stage"
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
# branches: [develop]
jobs:
deploy-to-stage:
name: Deploy to stage
environment: prod
runs-on: ubuntu-latest
steps:
# E2E tests in docker
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
- name: Cache node_modules
id: cache_node_modules
uses: actions/cache@v2
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/ci-package.json') }}
- name: Install packages
run: yarn install --link-duplicates --non-interactive
if: ${{steps.cache_node_modules.outputs.cache-hit != 'true' }}
- name: Run build scripts
run: |
npm run scripts:build
- name: Build the test prod on docker
run: |
. ./env/prod.env.sh
export MAILER_TRANSPORT=${{ secrets.MAILER_TRANSPORT }}
npm run docker:prod-local:test-build
- name: Show backend docker logs
run: |
var1=$(docker logs rucken-site-backend-service)
if grep -q "Listening at" <<<"$var1"; then
echo "ok"
else
echo $var1
exit 1
fi
- name: Test backend docker
run: |
var1=$(docker run --network container:rucken-site-backend-service appropriate/curl -s --retry 40 --retry-connrefused http://localhost:5000/home)
if grep -q "<title>Cross-platform fullstack core libraries for create Angular,
NestJS and Ionic applications with samples working on NX workspace - Rucken</title" <<<"$var1"; then
echo "ok"
else
echo $var1
exit 1
fi
# Delivery to host
- name: Run build scripts
run: |
npm run scripts:build
- name: Run build code
run: |
npm run generate-ci
npm run build:ssr
- name: Run generate K8S files
run: |
. ./env/prod.env.sh
export MAILER_TRANSPORT=${{ secrets.MAILER_TRANSPORT }}
export HOST=${{ secrets.HOST }}
node ./k8s/generators/generator.js
- name: Copy K8S files to host
uses: appleboy/scp-action@master
if: ${{ github.event_name == 'push' }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "k8s,env,VERSION.txt"
target: "vps/rucken-site"
rm: true
- name: Run build Docker images
run: |
npm run k8s:prod:build-images
- name: Add size of images to file
run: ls ./tmp -l --block-size=MB >> temp_file_list.txt
- name: Create comment for size of images
id: get-comment-body
run: |
body=$(cat temp_file_list.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Add size of images to commit as comment
uses: peter-evans/commit-comment@v1
with:
body: ${{ steps.get-comment-body.outputs.body }}
- name: Copy docker images to host
uses: appleboy/scp-action@master
if: ${{ github.event_name == 'push' }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "tmp/rucken-site-backend-prod.tar.gz"
target: "vps/rucken-site"
overwrite: true
# Apply changes
- name: Apply to K8S
uses: appleboy/ssh-action@master
if: ${{ github.event_name == 'push' }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
cd ./vps/rucken-site
. ./env/prod.env.sh
export MAILER_TRANSPORT=${{ secrets.MAILER_TRANSPORT }}
export HOST=${{ secrets.HOST }}
./k8s/import-images.sh
./k8s/apply.sh