-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
55 lines (47 loc) · 1.9 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
stages:
- test
- publish
.basic_setup: &setup
variables:
IMAGE_TAG: "$CI_PROJECT_NAME:$CI_COMMIT_SHA"
before_script:
- docker build -t "$IMAGE_TAG" -f Dockerfile .
after_script:
- docker rmi "$IMAGE_TAG"
test_container:
<<: *setup
stage: test
script:
- export CONTAINER_ID=$(docker run -p 80 -d "$IMAGE_TAG")
- export CONTAINER_IP=$(docker inspect --format="{{ .NetworkSettings.Networks.bridge.IPAddress }}" "$CONTAINER_ID")
- tmpfile1=$(mktemp "/tmp/test_run_1.XXXXXX")
- curl -s "$CONTAINER_IP/env" -o "$tmpfile1"
- docker kill $CONTAINER_ID
- export CONTAINER_ID=$(docker run -p 80 -d -e NGINX_ENV_VARS="TEST1" -e TEST1="bla" "$IMAGE_TAG")
- export CONTAINER_IP=$(docker inspect --format="{{ .NetworkSettings.Networks.bridge.IPAddress }}" "$CONTAINER_ID")
- tmpfile2=$(mktemp "/tmp/test_run_2.XXXXXX")
- curl -s "$CONTAINER_IP/env" -o "$tmpfile2"
- docker kill $CONTAINER_ID
- export CONTAINER_ID=$(docker run -p 80 -d -e NGINX_ENV_VARS="TEST1,TEST2" -e TEST1="bla1" -e TEST2="bla2" "$IMAGE_TAG")
- export CONTAINER_IP=$(docker inspect --format="{{ .NetworkSettings.Networks.bridge.IPAddress }}" "$CONTAINER_ID")
- tmpfile3=$(mktemp "/tmp/test_run_3.XXXXXX")
- curl -s "$CONTAINER_IP/env" -o "$tmpfile3"
- docker kill $CONTAINER_ID
- test "{\"vars_list\":\"empty\"}" = $(cat "$tmpfile1")
- test "{\"TEST1\":\"bla\",\"vars_list\":\"TEST1\"}" = $(cat "$tmpfile2")
- test "{\"vars_list\":\"TEST1,TEST2\",\"TEST2\":\"bla2\",\"TEST1\":\"bla1\"}" = $(cat "$tmpfile3")
- rm "$tmpfile1" "$tmpfile2" "$tmpfile3"
tags:
- staging
publish container:
<<: *setup
stage: publish
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.motius.de
- docker tag $IMAGE_TAG "$CI_REGISTRY_IMAGE:stable"
- docker push "$CI_REGISTRY_IMAGE:stable"
- docker rmi $IMAGE_TAG
tags:
- staging
only:
- master