forked from cytomine/Cytomine-postgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
executable file
·78 lines (65 loc) · 2.44 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
stages:
- lint
- build
variables:
ENTRYPOINT_SCRIPTS_VERSION: '1.3.0'
IMAGE_NAME: "cytomine/postgis"
IMAGE_VERSION: "${CI_COMMIT_TAG}"
POSTGIS_VERSION: "15-3.3-alpine"
# Those other vars should be inherited from GitLab:
# DOCKER_HUB_AUTH_CONFIG
workflow:
rules:
# Avoid the pipeline to be triggered for merge request event, because it would be a duplicated event when
# a push is made on a branch that has an open merge request linked (as suggested in the default GitLab workflow)
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
# TODO: reuse the tag regexp common job/rule
# Publish it if it has ANY tag.
- if: $CI_COMMIT_TAG != null
variables:
IS_OPEN_SOURCE_RELEASE_CANDIDATE: "true"
- when: always
default:
tags:
- docker
lint-dockerfiles:
stage: lint
image: hadolint/hadolint:latest-alpine
# Uncomment to silent some warnings if needed
#variables:
# HADOLINT_OPT: --ignore DL3008
script:
- hadolint ${HADOLINT_OPT} Dockerfile
rules:
- changes:
- Dockerfile
when: always
# If the Dockerfile has not been changed, this job can be skipped and manually invoked later
- when: manual
allow_failure: true
build-docker-image:
stage: build
image: docker:latest
rules:
- if: $IS_OPEN_SOURCE_RELEASE_CANDIDATE == 'true'
script:
- echo "The tag $CI_COMMIT_TAG has been pushed. Build & publish the image."
- echo "Build the docker image ${DOCKER_IMAGE_NAME}:${IMAGE_VERSION}"
- |
docker build \
--build-arg ENTRYPOINT_SCRIPTS_VERSION=${ENTRYPOINT_SCRIPTS_VERSION} \
--build-arg IMAGE_VERSION=${IMAGE_VERSION} \
--build-arg IMAGE_REVISION=${CI_COMMIT_SHORT_SHA} \
--build-arg POSTGIS_VERSION=${POSTGIS_VERSION} \
-t ${IMAGE_NAME}:${IMAGE_VERSION} \
-t ${IMAGE_NAME}:latest \
-f Dockerfile \
.
# 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"
- echo "Pushing image to registry, tagged as ${IMAGE_NAME}:${IMAGE_VERSION} and ${IMAGE_NAME}:latest"
- docker push ${IMAGE_NAME}:${IMAGE_VERSION}
- docker push ${IMAGE_NAME}:latest
- echo "Successfully pushed docker image ${IMAGE_NAME}:${IMAGE_VERSION} and ${IMAGE_NAME}:latest"