-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
202 lines (190 loc) · 6.2 KB
/
.gitlab-ci.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
stages:
- npm-dependencies
- build
- test
- sonarqube
- deploy
tag_checker:
stage: build
script:
- python3 tag_checker.py $CI_COMMIT_TAG
only:
- tags
npm-install:
stage: npm-dependencies
cache:
key: node-modules
paths:
- frontend/node_modules
script:
- cd frontend
- npm install
junit:
stage: test
script:
- cd backend
- ./gradlew test
# Run acceptance (cucumber) tests
cucumber:
stage: test
script:
- cd backend
- ./gradlew cucumber
jest:
stage: test
cache:
key: node-modules
paths:
- frontend/node_modules
policy: pull
script:
- cd frontend
- npm run test
# Export sonarqube (static code analysis) reports
dev-sonarqube:
stage: sonarqube
cache:
key: node-modules
paths:
- frontend/node_modules
- backend/build/jacoco
policy: pull
script:
- cd frontend
- npm run test
- npm run sonarqube
- cd ../backend
- ./gradlew test
- ./gradlew sonarqube
only:
- dev
# builds all branches, except dev and master
branch-build:
stage: build
cache:
key: node-modules
paths:
- frontend/node_modules
policy: pull
script:
- cd frontend
- npm run build
- cd ../backend
- ./gradlew bootJar
artifacts:
paths:
- frontend/dist
- backend/build/libs
except:
- tags
- master
- dev
deploy-staging-backend:
stage: deploy
script:
- cd backend
- ./gradlew bootJar
- rm -rf /home/gitlab-runner/staging-backend/ || true
- mkdir /home/gitlab-runner/staging-backend/
- cp -r ./build/libs /home/gitlab-runner/staging-backend
- cp ../runner/staging-backend.sh /home/gitlab-runner/staging-backend.sh
# environment variables added to file
- echo "export DB_URL=${DB_URL_STAGING}" >> /home/gitlab-runner/staging-backend/env_var.txt
- echo "export DB_USERNAME=${DB_USERNAME}" >> /home/gitlab-runner/staging-backend/env_var.txt
- echo "export DB_PASSWORD=${DB_PASSWORD}" >> /home/gitlab-runner/staging-backend/env_var.txt
- echo "export DGAA_EMAIL=${DGAA_EMAIL}" >> /home/gitlab-runner/staging-backend/env_var.txt
- echo "export DGAA_PASSWORD=${DGAA_PASSWORD}" >> /home/gitlab-runner/staging-backend/env_var.txt
- chmod u+x /home/gitlab-runner/staging-backend.sh
- sudo systemctl restart seng302-staging-backend
artifacts:
paths:
- backend/build/libs
only:
- dev
deploy-staging-frontend:
stage: deploy
cache:
key: node-modules
paths:
- frontend/node_modules
policy: pull
script:
- mkdir -p /home/gitlab-runner/staging-frontend/dist/prod_images
- mkdir -p /home/gitlab-runner/staging-frontend/dist/business_images
- mkdir -p /home/gitlab-runner/staging-frontend/dist/user_images
- mv -f /home/gitlab-runner/staging-frontend/dist/prod_images /home/gitlab-runner
- mv -f /home/gitlab-runner/staging-frontend/dist/business_images /home/gitlab-runner
- mv -f /home/gitlab-runner/staging-frontend/dist/user_images /home/gitlab-runner
- cd frontend
- export NODE_ENV=staging
- npm run build
- unset NODE_ENV
- rm -rf /home/gitlab-runner/staging-frontend/ || true
- mkdir /home/gitlab-runner/staging-frontend/
- cp -r ./dist/ /home/gitlab-runner/staging-frontend
- cp ../runner/staging-frontend.sh /home/gitlab-runner/staging-frontend.sh
- chmod u+x /home/gitlab-runner/staging-frontend.sh
- sudo systemctl restart seng302-staging-frontend
- mv -f /home/gitlab-runner/prod_images /home/gitlab-runner/staging-frontend/dist
- mv -f /home/gitlab-runner/business_images /home/gitlab-runner/staging-frontend/dist
- mv -f /home/gitlab-runner/user_images /home/gitlab-runner/staging-frontend/dist
artifacts:
paths:
- frontend/dist
only:
- dev
deploy-production-backend:
stage: deploy
script:
- cd backend
- ./gradlew bootJar
- rm -rf /home/gitlab-runner/production-backend/ || true
- mkdir /home/gitlab-runner/production-backend/
- cp -r ./build/libs /home/gitlab-runner/production-backend
- cp ../runner/production-backend.sh /home/gitlab-runner/production-backend.sh
# environment variables added to file
- echo "export DB_URL=${DB_URL_PROD}" >> /home/gitlab-runner/production-backend/env_var.txt
- echo "export DB_USERNAME=${DB_USERNAME}" >> /home/gitlab-runner/production-backend/env_var.txt
- echo "export DB_PASSWORD=${DB_PASSWORD}" >> /home/gitlab-runner/production-backend/env_var.txt
- echo "export DGAA_EMAIL=${DGAA_EMAIL}" >> /home/gitlab-runner/production-backend/env_var.txt
- echo "export DGAA_PASSWORD=${DGAA_PASSWORD}" >> /home/gitlab-runner/production-backend/env_var.txt
- chmod u+x /home/gitlab-runner/production-backend.sh
- sudo systemctl restart seng302-production-backend
artifacts:
paths:
- backend/build/libs
only:
- tags
- master
deploy-production-frontend:
stage: deploy
cache:
key: node-modules
paths:
- frontend/node_modules
policy: pull
script:
- mkdir -p /home/gitlab-runner/production-frontend/dist/prod_images
- mkdir -p /home/gitlab-runner/production-frontend/dist/business_images
- mkdir -p /home/gitlab-runner/production-frontend/dist/user_images
- mv -f /home/gitlab-runner/production-frontend/dist/prod_images /home/gitlab-runner
- mv -f /home/gitlab-runner/production-frontend/dist/business_images /home/gitlab-runner
- mv -f /home/gitlab-runner/production-frontend/dist/user_images /home/gitlab-runner
- cd frontend
- export NODE_ENV=production
- npm run build-prod
- rm -rf /home/gitlab-runner/production-frontend/ || true
- mkdir /home/gitlab-runner/production-frontend/
- cp -r ./dist/ /home/gitlab-runner/production-frontend
- cp ../runner/production-frontend.sh /home/gitlab-runner/production-frontend.sh
- chmod u+x /home/gitlab-runner/production-frontend.sh
- sudo systemctl restart seng302-production-frontend
- mv -f /home/gitlab-runner/prod_images /home/gitlab-runner/production-frontend/dist
- mv -f /home/gitlab-runner/business_images /home/gitlab-runner/production-frontend/dist
- mv -f /home/gitlab-runner/user_images /home/gitlab-runner/production-frontend/dist
artifacts:
paths:
- frontend/dist
only:
- tags
- master