-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.gitlab-ci.yml
218 lines (201 loc) · 6.7 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
stages:
- prepare
- test
- build_img
- build
- deploy
- after_test
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
CI_REGISTRY: "cerit.io"
CI_REGISTRY_IMAGE: "${CI_REGISTRY}/einfracz/mkdocs"
GIT_SUBMODULE_STRATEGY: recursive
GIT_DEPTH: 0
check_current_version:
image: alpine:3.8
before_script:
- apk add html-xml-utils curl jq
stage: prepare
script:
- echo https://$HOSTING_HOST
- 'export CSITE_VERSION=$(curl -s https://${HOSTING_HOST} | hxnormalize -xe | hxselect -c "script#__config" | hxuncdata | jq -r .version)'
- echo "Found https://${HOSTING_HOST} site version ${CSITE_VERSION}, git commit version ${CI_COMMIT_SHORT_SHA}."
- test "$CSITE_VERSION" != "$CI_COMMIT_SHORT_SHA"
- echo "There is change in content so we need to deploy."
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
docs:
stage: test
image: it4innovations/docker-mdcheck:latest
allow_failure: true
script:
- mdl -r ~MD013,~MD010,~MD014,~MD024,~MD026,~MD029,~MD033,~MD036,~MD037,~MD046 *.md main/ topics/ # BUGS
# pylint:
# stage: test
# image: it4innovations/docker-pycheck:latest
# before_script:
# - source /opt/.venv3/bin/activate
# script:
# - pylint $(find . -name "*.py" -not -name "feslicescript.py")
# pysafety:
# stage: test
# image: it4innovations/docker-pycheck:latest
# allow_failure: true
# before_script:
# - source /opt/.venv3/bin/activate
# script:
# - cat requirements.txt | safety check --stdin --full-report
capitalize:
stage: test
image: it4innovations/docker-mkdocscheck:latest
allow_failure: true
script:
- find mkdocs.yml topics/ main/ \( -name '*.md' -o -name '*.yml' \) -print0 | xargs -0 -n1 scripts/titlemd.py --test
ext_links:
stage: after_test
image: it4innovations/docker-mdcheck:latest
allow_failure: true
after_script:
# remove JSON results
- rm *.json
script:
- find topics/ main/ -name '*.md' -exec grep --color -l http {} + | xargs awesome_bot -t 10 --allow-dupe --allow-redirect
404s:
stage: after_test
image: it4innovations/docker-mkdocscheck:latest
allow_failure: true
before_script:
- wget -V
- echo https://${HOSTING_HOST}/review/$CI_BUILD_REF_NAME/
- wget --spider -e robots=off -o wget.log -r -p https://${HOSTING_HOST}/review/$CI_BUILD_REF_NAME/ || true
script:
- cat wget.log | awk '/^Found [0-9]+ broken link[s]?.$/,/FINISHED/ { rc=-1; print $0 }; END { exit rc }'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH
# mkdocs:
# stage: build
# image: it4innovations/docker-mkdocscheck:latest
# before_script:
# - source /opt/.venv3/bin/activate
# - python -V # debug
# - pip freeze # debug
# - mkdocs -V # debug
# script:
# # add version to footer
# - bash scripts/add_version.sh
# # get modules list from clusters
# - bash scripts/get_modules.sh
# # generate site_url
# - (if [ "${CI_BUILD_REF_NAME}" != 'master' ]; then sed -i "s/\(site_url.*$\)/\1devel\/$CI_BUILD_REF_NAME\//" mkdocs.yml;fi);
# # generate ULT for code link
# - sed -i "s/master/$CI_BUILD_REF_NAME/g" material/partials/toc.html
# # regenerate modules matrix
# - python scripts/modules_matrix.py > docs.it4i/modules-matrix.md
# - python scripts/modules_matrix.py --json > docs.it4i/modules-matrix.json
# - curl -f0 https://code.it4i.cz/sccs/scs-api-public/raw/master/scs_api.server_public.md -o docs.it4i/apiv1.md
# # build pages
# - mkdocs build
# # replace broken links in 404.html
# - sed -i 's,href="" title=",href="/" title=",g' site/404.html
# - cp site/404.html site/403.html
# - sed -i 's/404 - Not found/403 - Forbidden/g' site/403.html
# # compress sitemap
# - gzip < site/sitemap.xml > site/sitemap.xml.gz
# artifacts:
# paths:
# - site
# expire_in: 1 week
docker-build:
stage: build_img
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
before_script:
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${HUB_REGISTRY_USER}" "${HUB_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_SHORT_SHA"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--cache=true
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}${tag}"
.mkdocs-build: &mkdocs-build
stage: build
before_script:
- git submodule update --remote --recursive
script:
- export SITE_VERSION="$CI_COMMIT_SHORT_SHA"
- export SITE_BUILD_DATE="$(env TZ=Europe/Prague date -I)"
- mkdocs build
artifacts:
paths:
- site
expire_in: 1 week
mkdocs:
image:
name: "${CI_REGISTRY_IMAGE}:latest"
entrypoint: ["/bin/sh", "-c"]
<<: *mkdocs-build
only:
- master
mkdocs-dev:
image:
name: "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}"
entrypoint: ["/bin/sh", "-c"]
<<: *mkdocs-build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH
.prepare_deploy: &prepare_deploy
image: alpine:3.8
stage: deploy
before_script:
- apk update && apk add rsync openssh
- eval $(ssh-agent -s)
- echo "$SSH_HOSTING_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS__HOSTING" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
deploy production:
needs: ["mkdocs"]
environment:
name: production
url: https://${HOSTING_HOST}
script:
- rsync -a -e "ssh -p ${HOSTING_SSH_PORT_NUMBER} -o StrictHostKeyChecking=no" --delete --exclude=/review site/ ${HOSTING_USERNAME}@${HOSTING_HOST}:~/public_html
only:
- master
<<: *prepare_deploy
deploy dev:
needs: ["mkdocs-dev"]
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://${HOSTING_HOST}/review/$CI_COMMIT_REF_SLUG
<<: *prepare_deploy
script:
- rsync -a -e "ssh -p ${HOSTING_SSH_PORT_NUMBER} -o StrictHostKeyChecking=no" --delete --exclude=/review site/ ${HOSTING_USERNAME}@${HOSTING_HOST}:~/public_html/review/$CI_COMMIT_REF_SLUG
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
- if: $CI_COMMIT_BRANCH
stop_review:
<<: *prepare_deploy
script:
- ssh -p ${HOSTING_SSH_PORT_NUMBER} -o StrictHostKeyChecking=no ${HOSTING_USERNAME}@${HOSTING_HOST} rm -rf ~/public_html/review/$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
rules:
- if: $CI_MERGE_REQUEST_ID
when: manual