forked from silvermind/artefact_docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
322 lines (287 loc) · 9.87 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#image: docker:1.13-git
image: docker:18
services:
- postgres:latest
variables:
RAILS_ENV: 'test'
CONTAINER_IMAGE_NAME: "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME-test"
# CONTAINER_FEATURE_IMAGE_NAME: "$CI_BUILD_REF_NAME-test"
CONTAINER_IMAGE_RELEASE_NAME: "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME-latest"
CONTAINER_IMAGE_DOCUMENTATION_PATH: "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME-latest-docs"
# CONTAINER_IMAGE_DOCUMENTATION_NAME: "$CI_BUILD_REF_NAME-docs"
# CONTAINER_IMAGE_DOCUMENTATION_PATH: "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME-docs"
LANG: C.UTF-8
stages:
- build
- quality
- test
- release
- deploy
- collect-docs
- build-docs
- deploy-docs
.docker-login: &docker-login
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
.artifacts-always: &artifacts-always
artifacts:
when: always
#before_script:
# - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
build-image:
<<: *artifacts-always
<<: *docker-login
stage: build
tags:
- docker
script:
- timestamp=`date --rfc-2822`
- "echo 'Docker Image created:' $timestamp > BUILD.txt"
- "echo '' >> BUILD.txt"
- "echo '$CI_REGISTRY_IMAGE' $CI_REGISTRY_IMAGE >> BUILD.txt"
- "echo '$CI_BUILD_REF_NAME' $CI_BUILD_REF_NAME >> BUILD.txt"
- "echo '$CI_COMMIT_SHA' $CI_COMMIT_SHA >> BUILD.txt"
- "echo '' >> BUILD.txt"
- "echo '$CONTAINER_IMAGE_NAME:' $CONTAINER_IMAGE_NAME >> BUILD.txt"
- "echo '$CONTAINER_IMAGE_RELEASE_NAME:' $CONTAINER_IMAGE_RELEASE_NAME >> BUILD.txt"
- "echo '$CONTAINER_FEATURE_IMAGE_NAME:' $CONTAINER_FEATURE_IMAGE_NAME >> BUILD.txt"
- "echo '' >> BUILD.txt"
- "echo 'Project URL:' $CI_PROJECT_URL >> BUILD.txt"
- "echo '' >> BUILD.txt"
- "echo 'Build with Docker Version' $DOCKER_VERSION 'on CI_RUNNER ' $CI_RUNNER_DESCRIPTION >> BUILD.txt"
- "echo '' >> BUILD.txt"
- "echo 'Generated BUILD.txt:'"
- cat BUILD.txt
- ls -la
- docker build -f Dockerfile --pull --tag $CONTAINER_IMAGE_NAME .
- docker push $CONTAINER_IMAGE_NAME
- docker pull $CONTAINER_IMAGE_NAME
- docker inspect --format='{{index .RepoDigests 0}}' $CONTAINER_IMAGE_NAME
allow_failure: false
artifacts:
paths:
- BUILD.txt
expire_in: 1 week
# cache:
# key: "$CI_COMMIT_REF_SLUG" # per-branch caching
# paths:
# - tmp/cache/assets # used by sprockets for assets
#test-hamllint:
# tags:
# - docker
# stage: quality
# script:
# - docker run -e RAILS_ENV=test -e DOMAIN_NAME=docker-tests.example.com -e DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres $CONTAINER_IMAGE_NAME bundle exec haml-lint app/views/
# allow_failure: true
test-reek-codesmell:
<<: *artifacts-always
image: "$CONTAINER_IMAGE_NAME"
tags:
- docker
stage: test
script:
- bundle exec reek
# - docker run -e RAILS_ENV=test -e DOMAIN_NAME=docker-tests.example.com -e DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres $CONTAINER_IMAGE_NAME bundle exec reek
test-todo-notes:
<<: *artifacts-always
image: "$CONTAINER_IMAGE_NAME"
tags:
- docker
stage: test
variables:
# shared rails app configs
DOMAIN_NAME: docker-tests.example.com
script:
- export DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres
- bundle exec rails notes
allow_failure: true
#test-specs:
# image: "$CONTAINER_IMAGE_NAME"
# tags:
# - docker
# stage: test
# variables:
# # shared rails app configs
# DATABASE_URL: postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres
# DOMAIN_NAME: docker-tests.example.com
# DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: 'true'
# script:
# - export DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres
# - bundle exec rake db:migrate
# - bundle exec rspec . --seed 62376
## - docker run -e RAILS_ENV=test -e DOMAIN_NAME=docker-tests.example.com -e DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres $CONTAINER_IMAGE_NAME bundle exec rake db:migrate
## - docker run -e RAILS_ENV=test -e DOMAIN_NAME=docker-tests.example.com -e -e DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres $CONTAINER_IMAGE_NAME bundle exec rspec . --seed 62376
# allow_failure: false
# artifacts:
# when: always
# paths:
# - doc/debug_doc/code_coverage/
# expire_in: 3h
#
#test-specs-rnd-seed:
## <<: *artifacts-always
# image: "$CONTAINER_IMAGE_NAME"
# tags:
# - docker
# stage: test
# variables:
# # shared rails app configs
# DOMAIN_NAME: docker-tests.example.com
#
# DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: 'true'
# script:
# - export DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/postgres
# - bundle exec rake db:migrate
# - bundle exec rspec . --order rand
# allow_failure: false
test-rubocop:
<<: *artifacts-always
image: "$CONTAINER_IMAGE_NAME"
tags:
- docker
stage: test
script:
- bundle exec rubocop
allow_failure: true
test-bundle-audit:
<<: *artifacts-always
image: "$CONTAINER_IMAGE_NAME"
stage: test
services: []
tags:
- docker
# variables:
# needs a DB URL, but does not use the connection
# FAKE_DATABASE_URL: "mysql2://no-user:no-pwd@anyhost:3306/any-db"
script:
- bundle exec bundle-audit check --update
allow_failure: false
release-image:
<<: *docker-login
tags:
- docker
stage: release
script:
- docker pull $CONTAINER_IMAGE_NAME
- docker tag $CONTAINER_IMAGE_NAME $CONTAINER_IMAGE_RELEASE_NAME
- docker push $CONTAINER_IMAGE_RELEASE_NAME
# only:
# - master
#deploy_production:
# stage: deploy
# environment:
# name: production
# url: https://demo.e-request.ch
# script:
# - cd ctron && ./ctron_exec_prod.sh
# only:
# - master
collect-docs:
<<: *artifacts-always
image: "$CONTAINER_IMAGE_NAME"
stage: collect-docs
services: []
tags:
- docker
# variables:
# needs a DB URL, but does not use the connection
# FAKE_DATABASE_URL: "mysql2://no-user:no-pwd@anyhost:3306/any-db"
script:
# - export DATABASE_URL=postgres://postgres:postgres@$POSTGRES_PORT_5432_TCP_ADDR:5432/FAKE_DATABASE
# - bundle exec i18n-tasks unused > doc/debug_doc/translations_unused.txt
# - bundle exec i18n-tasks missing > doc/debug_doc/translations_missing.txt
#
# - script/rails routes > doc/debug_doc/app_routes.txt
# - script/rails stats > doc/debug_doc/app_stats.txt
# - script/rails notes > doc/debug_doc/app_notes.txt
# - script/rails middleware > doc/debug_doc/app_middleware_stack.txt
# - script/rails about > doc/debug_doc/app_about.txt
- mkdir -p ./tmp
- echo "IT WORKS" > tmp/app_about.txt
# - ./generate_debug_doc.sh
allow_failure: false
artifacts:
when: always
paths:
- tmp/
expire_in: 1h
# Push the Branche :latest image only if all Specs have been passed.
# Loads a SSH Private key from the CI variable
# a key which is allowed to login into the Dev Server using SSH
#
# POC ONLY, may not get response if deployment failed!!
#
# SSH Infos see: http://docs.gitlab.com/ce/ci/ssh_keys/README.html
build-docs:
<<: *artifacts-always
<<: *docker-login
stage: build-docs
tags:
- docker
# environment:
# name: Develop Doc Preview
# url: https://docs.dev.youngsolutions.ch
script:
- mkdir -p ./tmp
- ls -la ./tmp
- mkdir ./static-html-docs
# copy frameset and build infos
# - cp -Rv ./doc/static-html-docs/* ./static-html-docs/
- cp ./README.md ./static-html-docs/README.md
- cp ./BUILD.txt ./static-html-docs/BUILD.txt
# collect all artifacts stored in tmp
- echo "IT WORKS 2" > ./tmp/app_about2.txt
# - cp -Rv ./coverage/ ./static-html-docs/
- cp -Rv ./tmp/* ./static-html-docs/
# - cp ./rails_best_practices_output.html ./static-html-docs/rails_best_practices.html
# build documentation container using Dockerfile.documentation with path ./static-html-docs
- docker build -f Dockerfile.documentation --pull --tag $CONTAINER_IMAGE_DOCUMENTATION_PATH .
- docker push $CONTAINER_IMAGE_DOCUMENTATION_PATH
- docker pull $CONTAINER_IMAGE_DOCUMENTATION_PATH
# - docker inspect --format='{{index .RepoDigests 0}}' $CONTAINER_IMAGE_DOCUMENTATION_PATH
allow_failure: false
# only:
# - develop
# Push the Branche :latest image only if all Specs have been passed.
# Loads a SSH Private key from the CI variable
# a key which is allowed to login into the Dev Server using SSH
#
# POC ONLY, may not get response if deployment failed!!
#
# SSH Infos see: http://docs.gitlab.com/ce/ci/ssh_keys/README.html
deploy-docs:
<<: *artifacts-always
<<: *docker-login
stage: deploy-docs
tags:
- docker
# environment:
# name: Develop Doc Preview
# url: https://docs.dev.youngsolutions.ch
script:
- env
# # Install ssh-agent if not already installed, it is required by Docker.
# # (change apt-get to yum if you use a CentOS-based image)
# - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
#
# # Run ssh-agent (inside the build environment)
# - eval $(ssh-agent -s)
#
# # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
# - echo "$SSH_PRIVATE_KEY_TO_DEV_SERVER" > /tmp/deploy_key
# - chmod 700 /tmp/deploy_key
# - ssh-add /tmp/deploy_key
#
# # For Docker builds disable host key checking. Be aware that by adding that
# # you are suspectible to man-in-the-middle attacks.
# # WARNING: Use this only with the Docker executor, if you use it with shell
# # you will overwrite your user's SSH config.
# - mkdir -p ~/.ssh
# - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# TEST
# - ssh -T [email protected]
# Execute Deploy Script on Dev Server
# - ssh [email protected] /home/default/deploy_documentation_script.sh $CONTAINER_IMAGE_DOCUMENTATION_NAME
allow_failure: false
# only:
# - develop