-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
77 lines (71 loc) · 2.16 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
image: python:3.8-alpine3.10
stages:
- test
- build
- publish
before_script:
- export DOCKER_REPOSITORY="canyan/canyan-tester"
- export DOCKER_TAG=${CI_COMMIT_REF_SLUG:-master}
- export SERVICE_IMAGE=$DOCKER_REPOSITORY:$DOCKER_TAG
- export COMMIT_TAG="$CI_COMMIT_REF_SLUG"_"$CI_COMMIT_SHA"
test:
image: tiangolo/docker-with-compose
services:
- docker:dind
stage: test
script:
- echo "building canyan-tester for ${SERVICE_IMAGE}"
- docker build -t $DOCKER_REPOSITORY:tests -f Dockerfile.tests .
- echo -n $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- docker-compose -f docker-compose.tests.yaml up -d
- docker-compose -f docker-compose.tests.yaml exec -T tests make check
- docker-compose -f docker-compose.tests.yaml exec -T tests make coverage
- docker-compose -f docker-compose.tests.yaml down -v
- mkdir -p tests/unit-coverage && find . -name 'coverage.xml' -exec cp --parents {} ./tests/unit-coverage \;
- tar -cvf $CI_PROJECT_DIR/unit-coverage.tar tests/unit-coverage
artifacts:
expire_in: 2w
paths:
- unit-coverage.tar
build:
image: docker
stage: build
services:
- docker:dind
script:
- echo "building canyan-tester for ${SERVICE_IMAGE}"
- docker build -t $SERVICE_IMAGE .
- docker save $SERVICE_IMAGE > image.tar
artifacts:
expire_in: 2w
paths:
- image.tar
tags:
- docker
publish:tests:
stage: publish
before_script:
- apk add --no-cache bash curl findutils git
dependencies:
- test
script:
- tar -xvf unit-coverage.tar
- bash -c "bash <(curl -s https://codecov.io/bash) -Z -s ./tests/unit-coverage"
publish:build:
image: docker
stage: publish
only:
- /^(master|[0-9]+\.[0-9]+\.x)$/
services:
- docker:dind
dependencies:
- build
script:
- docker load -i image.tar
- docker tag $SERVICE_IMAGE $DOCKER_REPOSITORY:$COMMIT_TAG
- docker tag $SERVICE_IMAGE $DOCKER_REPOSITORY:$CI_COMMIT_REF_SLUG
- echo -n $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- docker push $DOCKER_REPOSITORY:$COMMIT_TAG
- docker push $SERVICE_IMAGE
tags:
- docker