forked from jerikan-network/cmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
80 lines (76 loc) · 2.38 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
before_script:
- docker info
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
stages:
- build
- report
- deploy
build templates:
stage: build
tags: [network]
script:
# Retrieve master output if we are in a merge request
- |
if test -n "$CI_MERGE_REQUEST_ID"; then
echo "Target branch is $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
ref=$(git ls-remote origin refs/heads/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME | awk '{print $1}')
echo "Target branch ref is $ref"
git cat-file -e $ref || git fetch -q origin $ref
ref=$(git merge-base $ref HEAD)
image=${CI_REGISTRY_IMAGE}:outputs-$ref
echo "Common ancestor with $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME is $ref"
echo "Pulling docker image $image"
docker pull $image
echo "Extract to output-master"
docker container create --name tmp_$$ $image nothing
mkdir output-master
docker container export tmp_$$ \
| tar -C output-master -xf - --strip-components=1 --wildcards output/\*
docker container rm tmp_$$
fi
# Build templates
- docker-compose rm -s -f -v
- docker image rm --no-prune cmdb_jerikan-ci:latest || true
- docker-compose pull
- SERVICE=jerikan-ci ./run build $(test -n "$CI_MERGE_REQUEST_ID" && echo --diff=output-master)
rules:
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_MERGE_REQUEST_ID
cache:
paths:
- .cache~
artifacts:
name: "$CI_COMMIT_REF_SLUG"
expose_as: configurations and report
when: always
expire_in: 3 months
paths:
- output/
reports:
junit: output/junit.xml
push artifacts to registry:
stage: report
tags: [network]
rules:
- if: $CI_COMMIT_BRANCH == "master"
- if: $CI_MERGE_REQUEST_ID
dependencies:
- build templates
script:
- tar zcf - output | docker image import - $CI_REGISTRY_IMAGE:outputs-$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:outputs-$CI_COMMIT_SHA
diff generated:
stage: report
tags: [network]
rules:
- if: $CI_MERGE_REQUEST_ID
dependencies:
- build templates
script:
- docker-compose build diff2html
- (cat output/*/diff.txt; echo) | docker-compose run --rm diff2html > diff.html
artifacts:
expose_as: differences with master
expire_in: 1 month
paths:
- diff.html