-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
278 lines (245 loc) · 10 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
stages:
- prepare
- build
- test
- distribute
- build_image
- test_image
- release_image
- clean
image: registry.cnrgh.fr/images/sources/ibfj-bioinfo-analysis-r:latest
variables:
#DOCKER_DRIVER: overlay2
LANG: 'en_US.UTF-8'
DOCKER_REPO: 'registry.cnrgh.fr/$CI_PROJECT_NAMESPACE/contatester/'
IMAGE_NAME: 'contatester'
CONTAINER_NAME: 'contatester'
CONTATESTER_VERSION: '1.0.0'
.active_python_venv:
before_script:
- source venv/bin/activate
- export R_LIBS="$(pwd)/rlib:/ur/lib64/Rlibrary"
- curl -LO https://repo.ius.io/ius-release-el7.rpm
- yum update -y ius-release-el7.rpm
- yum install -y libcurl openssl
.docker_jobs:
image: docker:stable
tags:
- dind
cache:
key: ${CI_PIPELINE_ID}-docker_lbi-1
untracked: true
# No var expansion as bash do see: https://www.trek10.com/blog/making-ci-easier-with-gitlab/
before_script:
- eval export IMAGE_FILE="contatester-${CI_COMMIT_SHORT_SHA}.tar.gz"
- echo "${CI_JOB_TOKEN}" | docker login -u gitlab-ci-token --password-stdin registry.cnrgh.fr
.cleaning_docker:
stage: prepare
extends: .docker_jobs
script:
- for i in $(docker images | grep contatester | tr -s ' ' | cut -d ' ' -f3 ); do docker rmi -f $i ; done
- for i in $(docker images | grep none | tr -s ' ' | cut -d ' ' -f3 ); do docker rmi -f $i ; done
- for i in $(docker ps -a | grep Exited | tr -s ' ' | cut -d ' ' -f1 ); do docker rm -f $i ; done
- docker images
- docker ps -a
.info_docker:
stage: prepare
extends: .docker_jobs
script:
- echo "$CI_COMMIT_REF_NAME | $CI_COMMIT_REF_SLUG"
- docker ps -a
- for i in $(docker ps -a | grep runner | tr -s ' ' | cut -d ' ' -f1); do echo $i ; docker inspect $i; done
- docker volume ls
- docker ps -q -f "label=com.gitlab.gitlab-runner.job.ref=$CI_COMMIT_REF_NAME" -f "label=com.gitlab.gitlab-runner.type=cache"
- docker ps -aq -f "label=com.gitlab.gitlab-runner.job.ref=$CI_COMMIT_REF_NAME" -f "label=com.gitlab.gitlab-runner.type=cache"
- docker ps -q -f "label=com.gitlab.gitlab-runner.type=cache"
- docker ps -aq -f "label=com.gitlab.gitlab-runner.type=cache"
- docker ps -q -f "label=com.gitlab.gitlab-runner.job.ref=$CI_COMMIT_REF_NAME"
- docker ps -aq -f "label=com.gitlab.gitlab-runner.job.ref=$CI_COMMIT_REF_NAME"
- for i in $(docker volume ls | grep local | tr -s ' ' | cut -d ' ' -f2); do echo $i ; docker volume inspect $i; done
prepare_python_env:
stage: prepare
tags:
- nodind
cache:
key: ${CI_COMMIT_REF_SLUG}-1
untracked: true
paths:
- venv
- rlib
artifacts:
untracked: true
paths:
- venv
- rlib
before_script:
- curl -LO https://repo.ius.io/ius-release-el7.rpm
- yum update -y ius-release-el7.rpm
- yum install -y libcurl-devel g++ openssl-devel
- python3 -m venv venv
- source venv/bin/activate
script:
- pip3 install setuptools wheel
- pip3 install --upgrade pip
- pip3 install --upgrade wheel
- pip3 install --upgrade setuptools
- mkdir -p rlib
- echo -e ".libPaths('$(pwd)/rlib')\noptions(repos = c(CRAN = 'https://cran.rstudio.com'))" > .Rprofile
- export R_LIBS="$(pwd)/rlib:/ur/lib64/Rlibrary"
- ./rPackageInstaller.r
build_contatester:
stage: build
extends: .active_python_venv
artifacts:
untracked: true
paths:
- dist/contatester-${CONTATESTER_VERSION}-py2.py3-none-any.whl
script:
- sed -r "/VERSION\s+=\s+'/s/[0-9\.]+/${CONTATESTER_VERSION}/g" setup.py
- python3 setup.py clean
- python3 setup.py bdist_wheel
test_all:
stage: test
extends: .active_python_venv
artifacts:
untracked: true
script:
- pip3 install dist/contatester-${CONTATESTER_VERSION}-py2.py3-none-any.whl
- ./run_tests.sh
coverage_contatester:
stage: test
extends: .active_python_venv
artifacts:
name: reports
paths:
- htmlcov/*
script:
- pip3 install coverage
- python3 setup.py coverage
wheel_contatester:
stage: distribute
extends: .active_python_venv
artifacts:
name: wheel
paths:
- dist/contatester-${CONTATESTER_VERSION}-py2.py3-none-any.whl
script:
- python3 setup.py bdist_wheel
build_contatester_image:
stage: build_image
extends: .docker_jobs
artifacts:
name: docker_image
paths:
#- ${CI_COMMIT_SHA}/image/contatester-*.tar.gz # Artifacts can only exist in directories relative to the build directory
# Only predefined variables can be used which exclude variables define in script section
expire_in: 3d
script:
#- mkdir -p ${CI_COMMIT_SHA}/image/
#- archive_file="contatester_src_$(date +'%s').tar.gz" # prevent docker cache
#- |
# tar czf "${archive_file}" rlib dist/contatester-${CONTATESTER_VERSION}-py2.py3-none-any.whl
#- du -sh rlib dist/contatester-${CONTATESTER_VERSION}-py2.py3-none-any.whl "${archive_file}"
- docker images
- |
docker build \
--build-arg CONTATESTER_VERSION="${CONTATESTER_VERSION}" \
-t "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" .
#- docker save "${DOCKER_REPO}${IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" | gzip -c > "${CI_COMMIT_SHA}/image/${IMAGE_FILE}"
- docker push "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}"
- docker images
test_contatester_image:
stage: test_image
extends: .docker_jobs
script:
#- docker load --input "${CI_COMMIT_SHA}/image/${IMAGE_FILE}"
- docker pull "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}"
#- echo "CI_RUNNER_ID -> $CI_RUNNER_ID | CI_JOB_ID -> $CI_JOB_ID"
#- docker ps -aq -f "label=com.gitlab.gitlab-runner.job.id=$CI_JOB_ID" -f "label=com.gitlab.gitlab-runner.type=build"
#- for i in $(docker ps -aq -f "label=com.gitlab.gitlab-runner.job.ref=$CI_COMMIT_REF_NAME" -f "label=com.gitlab.gitlab-runner.type=cache"); do echo $i ; docker inspect $i; done
#- for i in $(docker ps -a | grep runner | tr -s ' ' | cut -d ' ' -f1); do echo $i ; docker inspect $i; done
#- for i in $(docker volume ls | grep local | tr -s ' ' | cut -d ' ' -f2); do echo $i ; docker volume inspect $i; done
- cache_container_id=$(docker ps -a -q -f "label=com.gitlab.gitlab-runner.job.id=$CI_JOB_ID" -f "label=com.gitlab.gitlab-runner.type=build")
#- echo ${cache_container_id}
- cwd=$(pwd)
#- echo "${cwd}"
- sed -i 's|^|'"${cwd}/"'|' data_examples/vcfs_list.txt
- |
docker run --rm \
--name="${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-0" \
"${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" -h
# For docker in docker, need to mount volume from host machine
- |
docker run --rm \
--name="${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-3" \
--volumes-from "${cache_container_id}" \
"${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" -t 1 -f "${cwd}"/data_examples/test_1.vcf.gz -o /my_out_dir
- |
docker run --rm \
--name="${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-4" \
--volumes-from "${cache_container_id}" \
"${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" -t 1 -l "${cwd}"/data_examples/vcfs_list.txt -o /my_out_dir
# For simple docker use :
#- |
# docker run --rm \
# --name="${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-3" \
# --volume "$(pwd)"/data_examples:/data_examples \
# --volume "$(pwd)"/my_out_dir:/my_out_dir \
# "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" -f /data_examples/test_1.vcf.gz -o /my_out_dir
#- |
# docker run --rm \
# --name="${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-4" \
# --volume "$(pwd)"/data_examples:/data_examples \
# --volume "$(pwd)"/my_out_dir:/my_out_dir \
# "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" -l /data_examples/vcfs_list.txt -o /my_out_dir
master_image:
stage: release_image
extends: .docker_jobs
script:
#- docker load --input "${CI_COMMIT_SHA}/image/${IMAGE_FILE}"
- docker pull "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}"
- docker tag "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" ${DOCKER_REPO}${IMAGE_NAME}:latest
- docker push "${DOCKER_REPO}${IMAGE_NAME}:latest"
only:
- master
release_master_image:
stage: release_image
extends: .docker_jobs
script:
#- docker load --input "${CI_COMMIT_SHA}/image/${IMAGE_FILE}"
- docker pull "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}"
- docker tag "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" "${DOCKER_REPO}${IMAGE_NAME}:${CONTATESTER_VERSION}"
- docker push "${DOCKER_REPO}${IMAGE_NAME}:${CONTATESTER_VERSION}"
only:
- tags
remove image:
stage: clean
extends: .docker_jobs
when: always
script:
- docker images
- docker rm -f "${CONTAINER_NAME}-${CI_COMMIT_SHORT_SHA}-*" || true
# Stop any running containers, if they are not running anymore (since its not a run -d), ignore errors about that.
- docker rm -f "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" ${IMAGE_NAME} || true
# Remove pulled images
- docker rmi -f "${DOCKER_REPO}${IMAGE_NAME}-devel:${CI_COMMIT_SHORT_SHA}" || true
# Remove pulled images
- docker rmi -f "${DOCKER_REPO}${IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}" || true
# Remove all images (current et previouslys build container missed) [Optional]
#- docker images | awk -v pattern="${DOCKER_REPO}${IMAGE_NAME}" '{if( $1 ~ /^pattern/ ){ print $1":"$2; system(docker rmi -f $1":"$2) }}'
- docker images
docker remove all temp files:
stage: clean
when: always
cache:
key: ${CI_PIPELINE_ID}-docker_lbi-1
script:
- rm -fr ${CI_COMMIT_SHA}/
python remove all temp files:
stage: clean
when: always
cache:
key: ${CI_PIPELINE_ID}-py_lbi-1
script:
- rm -fr .eggs .pytest_cache/ build/ dist/ htmlcov/ src/contatester.egg-info/
- find . -name __pycache__ | xargs rm -fr