forked from cytomine/Cytomine-Web-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
71 lines (62 loc) · 2.27 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
stages:
- prepare
- build
- publish
variables:
DOCKER_IMAGE_NAME: 'cytomine/web_ui'
ENTRYPOINT_SCRIPTS_VERSION: '1.3.0'
NGINX_VERSION: '1.22.1'
NODE_VERSION: '14.16.1-alpine3.13'
default:
tags:
- docker
make-version-name:
stage: prepare
# regex check does not work with /bin/sh because of parenthesis so we need /bin/bash here
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/bash:5.2.15-alpine3.16
script:
#- if [[ "$CI_COMMIT_REF_NAME" =~ ^refs/tags/ ]] then
# echo "CM_VERSION=$CI_COMMIT_TAG" > .env;
# else
# echo "CM_VERSION=$CI_COMMIT_SHORT_SHA-$(date '+%Y%m%d%H%M%S')-SNAPSHOT" > .env;
# fi
# TODO: reuse the tag regexp common job/rule
- | # If no tag has been pushed ($CI_COMMIT_TAG is empty), name it as SNAPSHOT
if [ -z $CI_COMMIT_TAG ]; then
echo "CM_VERSION=$CI_COMMIT_BRANCH" > .env
else
# Else use the tag
echo "CM_VERSION=$CI_COMMIT_TAG" > .env
fi
- cat .env
artifacts:
reports:
dotenv: .env
build-push-docker-image:
stage: build
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:latest
needs:
- job: make-version-name
artifacts: true
rules:
- if: $CI_COMMIT_TAG
script:
# Use credential helper (see https://docs.docker.com/engine/reference/commandline/login/#credentials-store)
- mkdir -p $HOME/.docker && echo $DOCKER_HUB_AUTH_CONFIG > $HOME/.docker/config.json
- echo "Registry credentials configured at $HOME/.docker/config.json"
# Prepare some vars
- sed -i -- "s/WEB_UI_VERSION/${CM_VERSION}-${CI_COMMIT_SHORT_SHA}/g" public/index.html
- echo "Build the docker image ${DOCKER_IMAGE_NAME}:${CM_VERSION}"
- |
docker build \
--build-arg NODE_VERSION=${NODE_VERSION} \
--build-arg NGINX_VERSION=${NGINX_VERSION} \
--build-arg ENTRYPOINT_SCRIPTS_VERSION=${ENTRYPOINT_SCRIPTS_VERSION} \
--build-arg WEB_UI_VERSION=${CM_VERSION} \
--build-arg WEB_UI_REVISION=${CI_COMMIT_SHORT_SHA} \
-t ${DOCKER_IMAGE_NAME}:${CM_VERSION} \
-f docker/Dockerfile \
.
- echo "Pushing docker image ${DOCKER_IMAGE_NAME}:${CM_VERSION}"
- docker push ${DOCKER_IMAGE_NAME}:${CM_VERSION}
- echo "Successfully pushed docker image ${DOCKER_IMAGE_NAME}:${CM_VERSION}"