forked from Cytomine-ULiege/pims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
153 lines (144 loc) · 5.47 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
stages:
- prepare
- test
- build
- publish
- clean
# variable to register in project:
# - DOCKERHUB_URL: url of dockerhub (e.g. docker.io)
# - DOCKERHUB_USER: cytomine username on dockerhub
# - DOCKERHUB_PASSWORD: cytomine password on dockerhub
# - PYPI_USERNAME: pypi username for package upload
# - PYPI_PASSWORD: pypi password for package upload
default:
tags:
- docker
variables:
DOCKERHUB_PIMS_REPO: cytomine/pims
DOCKER_IMAGE_NAME_FOR_TESTS: $CI_PIPELINE_ID-test:latest
DOCKER_IMAGE_NAME_TMP_BUILD: $CI_PIPELINE_ID:latest
ENTRYPOINT_SCRIPTS_VERSION: '1.3.0'
GUNICORN_VERSION: '20.1.0'
OPENJPEG_URL: 'https://github.com/uclouvain/openjpeg/archive'
OPENJPEG_VERSION: '2.4.0'
PLUGIN_CSV: 'scripts/plugin-list.csv'
PY_VERSION: "3.8"
SETUPTOOLS_VERSION: '59.6.0'
UBUNTU_VERSION: '20.04'
VIPS_URL: 'https://github.com/libvips/libvips/releases/download'
VIPS_VERSION: '8.12.1'
workflow:
rules:
# - if: $CI_COMMIT_REF_PROTECTED != "true"
# when: never
# only publish artifacts (docker image and python package) if tag is a PEP440 compatible version (see long regex)
# open-source if tag is not post- nor pre-release
- if: $CI_COMMIT_TAG != null && $CI_COMMIT_TAG =~ /^v?(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*$/
variables:
PUBLISH_ARTIFACTS: "true"
IS_OPEN_SOURCE_RELEASE_CANDIDATE: "true"
- if: $CI_COMMIT_TAG != null && $CI_COMMIT_TAG =~ /^v?((?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*(?:[-_\.]?(?:a|b|c|rc|alpha|beta|pre|preview)[-_\.]?(?:[0-9]+)?)?(?:-[0-9]+|[-_\.]?(?:post|rev|r)[-_\.]?(?:[0-9]+)?)?(?:[-_\.]?dev[-_\.]?(?:[0-9]+)?)?)(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)?$/
variables:
PUBLISH_ARTIFACTS: "true"
IS_OPEN_SOURCE_RELEASE_CANDIDATE: "false"
- if: $CI_COMMIT_TAG == null || $CI_COMMIT_TAG !~ /^v?((?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*(?:[-_\.]?(?:a|b|c|rc|alpha|beta|pre|preview)[-_\.]?(?:[0-9]+)?)?(?:-[0-9]+|[-_\.]?(?:post|rev|r)[-_\.]?(?:[0-9]+)?)?(?:[-_\.]?dev[-_\.]?(?:[0-9]+)?)?)(?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)?$/
variables:
PUBLISH_ARTIFACTS: "false"
IS_OPEN_SOURCE_RELEASE_CANDIDATE: "false"
# build docker image for test
build-docker-image-for-tests:
stage: prepare
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:latest
script:
- |
docker build \
--build-arg ENTRYPOINT_SCRIPTS_VERSION=${ENTRYPOINT_SCRIPTS_VERSION} \
--build-arg GUNICORN_VERSION=${GUNICORN_VERSION} \
--build-arg OPENJPEG_URL=${OPENJPEG_URL} \
--build-arg OPENJPEG_VERSION=${OPENJPEG_VERSION} \
--build-arg PLUGIN_CSV="scripts/plugin-list.csv" \
--build-arg PY_VERSION=${PY_VERSION} \
--build-arg SETUPTOOLS_VERSION=${SETUPTOOLS_VERSION} \
--build-arg UBUNTU_VERSION=${UBUNTU_VERSION} \
--build-arg VIPS_URL=${VIPS_URL} \
--build-arg VIPS_VERSION=${VIPS_VERSION} \
-t "${DOCKER_IMAGE_NAME_FOR_TESTS}" \
-f docker/backend.dockerfile \
.
run-pytest:
stage: test
image:
name: $DOCKER_IMAGE_NAME_FOR_TESTS
entrypoint: [""]
pull_policy: never
needs:
- job: build-docker-image-for-tests
artifacts: false
script:
- pip install pytest
- pytest ./tests --junit-xml=ci/test-reports/pytest_unit.xml
artifacts:
reports:
junit: ci/test-reports/pytest_unit.xml
build-python-package:
stage: build
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:${PY_VERSION}-slim-bullseye
rules:
- if: $PUBLISH_ARTIFACTS == "true"
script:
- sed -i -- "s/__version__ = \"0.0.0\"/__version__ = \"$CI_COMMIT_TAG\"/g" pims/__version__.py
- python setup.py sdist
# Canonical version is automatically generated by setuptools matching PEP440
- DIST_FILENAME=$(ls dist/cytomine-pims-*.tar.gz)
- |
if [ ! -f "$DIST_FILENAME" ]; then
echo "could not build the package, $DIST_FILENAME seems to be missing"
exit -1
fi
- VERSION=$(python -c 'import re; import sys; m = re.match(r"^dist/cytomine-pims-(.+)\.tar\.gz$", sys.argv[1].strip()); print(m.group(1))' $DIST_FILENAME)
- echo "CANONICAL_VERSION_NUMBER=$VERSION" > .env
artifacts:
paths:
- dist/cytomine-pims-*.tar.gz
reports:
# to export canonical version number
dotenv: .env
publish-python-package:
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/python:${PY_VERSION}-slim-bullseye
stage: publish
rules:
- if: $PUBLISH_ARTIFACTS == "true"
needs:
- job: run-pytest
artifacts: false
- job: build-python-package
artifacts: true
script:
- pip install twine
- |
if [ $IS_OPEN_SOURCE_RELEASE_CANDIDATE = "true" ]; then
export TARGET_PYTHON_REPO=https://upload.pypi.org/legacy/
export TWINE_USERNAME=$PYPI_USERNAME
export TWINE_PASSWORD=$PYPI_PASSWORD
else
export TARGET_PYTHON_REPO=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi
export TWINE_USERNAME=gitlab-ci-token
export TWINE_PASSWORD=$CI_JOB_TOKEN
fi
- twine upload dist/cytomine-pims-*.tar.gz --repository-url $TARGET_PYTHON_REPO
# cleaning temporary docker images
clean-docker-images:
stage: clean
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:latest
rules:
- when: always
needs:
- job: publish-docker-image
artifacts: false
optional: true
- job: run-pytest
artifacts: false
script:
# '|| true' so that job proceeds even if an image does not exist
- docker rmi $DOCKER_IMAGE_NAME_TMP_BUILD || true
- docker rmi $DOCKER_IMAGE_NAME_FOR_TESTS || true