-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
94 lines (82 loc) · 2.86 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
variables:
IMAGE_NAME: emcmongoose/darzee
LATEST_IMAGE_TAG: latest
TESTING_IMAGE_TAG: testing
IMAGE_FILE_NAME: darzee.tar
CREATED_DARZEE_DOCKERFILE_PATH: docker/Dockerfile
stages:
- create_dockerfile
- build_docker_image
- push_testing_image
- release_into_the_dockerhub
create_dockerfile:
stage: create_dockerfile
image: java:8-jdk
artifacts:
paths:
- $CREATED_DARZEE_DOCKERFILE_PATH
script:
- ./gradlew clean createDockerfile
build_docker_image:
stage: build_docker_image
# WARNING: Make sure docker:dind and docker image matches, otherwise ...
# ... errors could occur. If you run docker-in-docker in your own GitLab CI ...
# ... runner, make sure it's launched in privileged mode unless dind won't work.
image: docker:stable
# NOTE: Setting up dind service inside a stage since it conflicts with a JDK image used ...
# ... in dockerfile creation stage.
services:
- docker:dind
variables:
SERVICE_HOST: docker # should be used instead of the "localhost"/"127.0.0.1" in GL CI
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- cp $CREATED_DARZEE_DOCKERFILE_PATH .
- docker build -t emcmongoose/darzee:latest .
- docker save emcmongoose/darzee:latest > darzee.tar
- echo $CI_COMMIT_SHA
- echo $DOCKER_USER
artifacts:
paths:
- darzee.tar
# NOTE: Releasing testing image into the docker hub. This is done in order to ...
# ... test Darzee's updated version in deployment environment before the release.
push_testing_image:
stage: push_testing_image
image: docker:stable
# NOTE: For some reasons, docker image conflicts with JDK image (which was used in a first stage), ...
# ... this is why I'm reinitializing it here. If you know better solutions, please, ...
# ... open a up PR.
services:
- docker:dind
variables:
SERVICE_HOST: docker
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- docker load < darzee.tar
- docker tag $IMAGE_NAME $IMAGE_NAME:$TESTING_IMAGE_TAG
- docker push $IMAGE_NAME:$TESTING_IMAGE_TAG
# NOTE: Releasing new Darzee version under tha "latest" tag only ...
# ... in case of merge into master.
release_into_the_dockerhub:
stage: release_into_the_dockerhub
# NOTE: For some reasons, docker image conflicts with JDK image (which was used in a first stage), ...
# ... this is why I'm reinitializing it here. If you know better solutions, please, ...
# ... open a up PR.
image: docker:stable
services:
- docker:dind
variables:
SERVICE_HOST: docker
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script:
- docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- docker load < darzee.tar
- docker tag $IMAGE_NAME $IMAGE_NAME:$LATEST_IMAGE_TAG
- docker push $IMAGE_NAME:$LATEST_IMAGE_TAG
only:
- master