forked from FredHutch/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
245 lines (223 loc) · 8.95 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
default:
before_script:
- apk update
- apk --no-cache add py3-pip python3 curl git jq bash
- pip install pip==21.3.1 # workaround: https://stackoverflow.com/a/72469586/470769
- pip3 install pyyaml
- curl -O https://raw.githubusercontent.com/FredHutch/swarm-build-helper/main/build_helper.py
# below is from https://stackoverflow.com/a/65810302/470769
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- set -x
stages:
- build
- create_search_index_0
- create_search_index_1
- test
- deploy
build:
stage: build
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
script: |
set -x
# put info about this commit/branch into /info.txt
echo Information > info.txt
echo "Branch: ${CI_COMMIT_BRANCH}" >> info.txt
echo "Commit: ${CI_COMMIT_SHA}" >> info.txt
echo "Commit comment:" >> info.txt
echo " ${CI_COMMIT_MESSAGE}" >> info.txt
echo "Build time: $(date)" >> info.txt
# get markdown pages for easybuild modules
rm -rf easybuild-life-sciences-main main.zip ./_scicomputing/bio-modules-18.04.md.orig
# faster than cloning:
curl -LO https://github.com/FredHutch/easybuild-life-sciences/archive/refs/heads/main.zip
unzip -qq main.zip
cp easybuild-life-sciences-main/docs/_r/* ./_rModules/
cp easybuild-life-sciences-main/docs/_python/* ./_pythonModules/
cp easybuild-life-sciences-main/docs/bio-modules-18.04.md ./_scicomputing/bio-modules-18.04.md.orig
FIRST_BLANK_LINE=$(grep -n -m 1 '^$' ./_scicomputing/bio-modules-18.04.md.orig | cut -d: -f1)
echo "---" >> ./_scicomputing/bio-modules-18.04.md
echo "title: Scientific Software BioModules" >> ./_scicomputing/bio-modules-18.04.md
echo "primary_reviewers: fizwit" >> ./_scicomputing/bio-modules-18.04.md
echo "toc: false" >> ./_scicomputing/bio-modules-18.04.md
echo "---" >> ./_scicomputing/bio-modules-18.04.md
echo >> ./_scicomputing/bio-modules-18.04.md
tail -n +$FIRST_BLANK_LINE ./_scicomputing/bio-modules-18.04.md.orig >> ./_scicomputing/bio-modules-18.04.md
rm -rf easybuild-life-sciences-main main.zip ./_scicomputing/bio-modules-18.04.md.orig
if [ "$CI_COMMIT_BRANCH" == "main" ]; then
export JEKYLL_ENV=production
else
export JEKYLL_ENV=development
fi
# build image
docker build --build-arg JEKYLL_ENV=$JEKYLL_ENV -t sc-registry.fredhutch.org/wiki:test .
docker push sc-registry.fredhutch.org/wiki:test
create_search_index_0:
stage: create_search_index_0
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
# services:
# - name: sc-registry.fredhutch.org/elasticsearch
# alias: elasticsearch
script: |
set -x
# build search index
# run image and copy HTML files out of it
CONTAINER_NAME=wiki_${CI_JOB_ID}
docker run -d --rm --name $CONTAINER_NAME sc-registry.fredhutch.org/wiki:test
rm -rf elasticsearch/tmp && mkdir elasticsearch/tmp
docker cp $CONTAINER_NAME:/usr/share/nginx/html/ ./elasticsearch/tmp/
docker rm -f $CONTAINER_NAME || true
echo fultr
ls -l elasticsearch
ls -l elasticsearch/tmp
docker build -t sc-registry.fredhutch.org/wiki_search_part_0 ./elasticsearch/
docker push sc-registry.fredhutch.org/wiki_search_part_0
create_search_index_1:
stage: create_search_index_1
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
services:
- name: sc-registry.fredhutch.org/wiki_search_part_0
alias: create_search_index_1
script: |
# CONTAINER_NAME=$(env | grep $HOSTNAME | grep "9200/tcp" | cut -d= -f2 | cut -d / -f 2)
# echo container name: $CONTAINER_NAME
CONTAINER_ID=$(docker ps | grep $HOSTNAME | grep "9200/tcp" | cut -d' ' -f1)
docker exec $CONTAINER_ID ls -l /
docker exec $CONTAINER_ID /indexer.sh
rm -rf idx
mkdir idx
docker cp $CONTAINER_ID:/usr/share/elasticsearch/data ./idx/
docker build -f elasticsearch/Dockerfile2 -t sc-registry.fredhutch.org/wiki_search:test .
docker push sc-registry.fredhutch.org/wiki_search:test
test:
stage: test
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
services:
- name: sc-registry.fredhutch.org/wiki_search:test
alias: elasticsearch
- name: sc-registry.fredhutch.org/wiki:test
alias: wiki
command: ["/test.sh"]
script: |
set -x
if [ "$CI_COMMIT_BRANCH" == "main" ]; then
echo "Don't check docker-compose until we deploy to swarm"
# python3 build_helper.py docker-compose.yml > /dev/null
else
python3 build_helper.py docker-compose-preview.yml > /dev/null
fi
curl -sI http://wiki:80 | head -1 | grep -q "200 OK"
export NUMHITS=$(curl -s -H "Content-Type: application/json" -XPOST "http://elasticsearch:9200/_search" -d'
{
"_source": [
"title"
],
"highlight": {
"fields": {
"content": {}
}
},
"size": 100,
"query": {
"match_phrase": {
"content": "gizmo"
}
}
}
' | jq .hits.total.value)
echo "Number of hits: $NUMHITS"
if [ "$NUMHITS" -gt 0 ]; then
echo "Search works"
# exit 0
else
echo "Search does not work"
exit 1
fi
check_for_orphan_assets:
stage: test
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
only:
refs:
- main
before_script:
- apk add curl git
- curl -LO https://github.com/cli/cli/releases/download/v2.16.1/gh_2.16.1_linux_amd64.tar.gz
- tar zxf gh_2.16.1_linux_amd64.tar.gz
- cp gh_2.16.1_linux_amd64/bin/gh /usr/local/bin
- rm -rf gh_2.16.1_linux_amd64.tar.gz gh_2.16.1_linux_amd64
script: |
# find orphan assets
rm -f orphans.txt*
for F in $(find assets/* -type f) ; do grep -r -q $F * || echo "$F"; done > orphans.txt.tmp
#cat orphans.txt.tmp | fgrep -v "assets/css/" | fgrep -v "assets/js/" > orphans.txt
fgrep -v "assets/css/" orphans.txt.tmp > orphans.txt.css || true
fgrep -v "assets/js/" orphans.txt.css > orphans.txt || true
ls -l orphans.txt
echo "---"
if [ -s orphans.txt ] ; then
echo "Orphan files found:"
cat orphans.txt
# This files an issue.
# It seems to be a little tricky to figure out the github ID of
# whoever made the commit introducing the orphan asset(s).
# So leaving that bit out for now.
rm -f issue.txt
echo "There are one or more orphan assets in the wiki. " > issue.txt
echo "These are images or other files that are not linked to." >> issue.txt
echo "Please remove them and push again." >> issue.txt
echo "Then you can close this issue." >> issue.txt
echo >> issue.txt
echo "Orphan files:" >> issue.txt
echo >> issue.txt
cat orphans.txt >> issue.txt
# TODO fix this:
######## gh issue create --title "Orphan asset files in wiki" --body-file issue.txt
# Should we really break the build here? We have created an issue
# so not sure if breaking the build would be redundant.
# Let's not break the build for now. Commented this out:
### exit 1
fi
# build for every branch EXCEPT main and push to preview site
# https://sciwiki-preview.fredhutch.org (only accessible inside
# hutch network). See
# https://sciwiki-preview.fredhutch.org/info.txt for branch
# and commit information.
deploy_preview:
stage: deploy
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
except:
refs:
- main
script:
- docker tag sc-registry.fredhutch.org/wiki:test sc-registry.fredhutch.org/wiki-preview:latest
- docker tag sc-registry.fredhutch.org/wiki_search:test sc-registry.fredhutch.org/wiki_elasticsearch-preview:latest
- docker push sc-registry.fredhutch.org/wiki-preview:latest
- docker push sc-registry.fredhutch.org/wiki_elasticsearch-preview:latest
- sleep 15
- echo $SC_SWARM_CICD_SSH_KEY | base64 -d > ./sc_swarm_cicd_ssh_key
- chmod 0400 ./sc_swarm_cicd_ssh_key
- python3 build_helper.py docker-compose-preview.yml | ssh -i ./sc_swarm_cicd_ssh_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] docker stack deploy --with-registry-auth -c - sciwiki-preview
# deploy `main` branch to
# https://sciwiki.fredhutch.org
deploy:
stage: deploy
tags: # TODO REMOVE after shell runner is disabled
- sc-swarm
only:
refs:
- main
script: |
docker tag sc-registry.fredhutch.org/wiki:test sc-registry.fredhutch.org/wiki:latest
docker tag sc-registry.fredhutch.org/wiki_search:test sc-registry.fredhutch.org/wiki_elasticsearch:latest
docker push sc-registry.fredhutch.org/wiki:latest
docker push sc-registry.fredhutch.org/wiki_elasticsearch:latest
sleep 15
echo $SC_SWARM_CICD_SSH_KEY | base64 -d > ./sc_swarm_cicd_ssh_key
chmod 0400 ./sc_swarm_cicd_ssh_key
python3 build_helper.py docker-compose.yml | ssh -i ./sc_swarm_cicd_ssh_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] docker stack deploy --with-registry-auth -c - wiki