forked from sagikazarmark/modern-go-application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
111 lines (97 loc) · 2.8 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
image: golang:1.12
variables:
DOCKER_IMAGE: registry.gitlab.com/${CI_PROJECT_PATH}
GOFLAGS: -mod=readonly
GOPATH: ${CI_PROJECT_DIR}/vendor/go
stages:
- dependencies
- test
- build
- packaging
.modcache: &modcache
key: modcache
paths:
- vendor/go/pkg/mod/
dependencies:
stage: dependencies
script: go mod download
cache: *modcache
test:
stage: test
script: make test
cache:
<<: *modcache
policy: pull
artifacts:
reports:
junit: build/test_results/main/results.xml
test-integration:
stage: test
script: make test-integration
cache:
<<: *modcache
policy: pull
artifacts:
reports:
junit: build/test_results/integration/results.xml
lint:
stage: test
script: make lint
cache:
<<: *modcache
policy: pull
.build: &build_definition
stage: build
script:
- export CI_BUILD_DATE=$(date +%FT%T%z)
- make build-release VERSION=${CI_COMMIT_REF_NAME} COMMIT_HASH=${CI_COMMIT_SHA} BUILD_DATE=${CI_BUILD_DATE}
- make build-debug VERSION=${CI_COMMIT_REF_NAME} COMMIT_HASH=${CI_COMMIT_SHA} BUILD_DATE=${CI_BUILD_DATE}
cache:
<<: *modcache
policy: pull
snapshot:
<<: *build_definition
only:
- master
artifacts:
paths:
- build/
expire_in: 2 days
release:
<<: *build_definition
only:
- tags
artifacts:
paths:
- build/
.docker: &docker_definition
stage: packaging
image: docker:stable
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
- apk add --update --no-cache ca-certificates make
script:
- docker build --build-arg BUILD_DIR=build/release --build-arg BINARY_NAME=$(make var-BINARY_NAME) -t ${DOCKER_IMAGE}:${CI_COMMIT_REF_NAME} -f Dockerfile.local .
- docker build --build-arg BUILD_DIR=build/debug --build-arg BINARY_NAME=$(make var-BINARY_NAME) -t ${DOCKER_IMAGE}:${CI_COMMIT_REF_NAME}-debug -f Dockerfile.debug .
- if [[ "${CI_COMMIT_REF_NAME}" == "${CI_COMMIT_TAG}" ]]; then docker tag ${DOCKER_IMAGE}:${CI_COMMIT_REF_NAME} ${DOCKER_IMAGE}:latest; fi
- if [[ "${CI_COMMIT_REF_NAME}" == "${CI_COMMIT_TAG}" ]]; then docker tag ${DOCKER_IMAGE}:${CI_COMMIT_REF_NAME}-debug ${DOCKER_IMAGE}:latest-debug; fi
- docker push ${DOCKER_IMAGE}
- docker push ${DOCKER_IMAGE}
docker:snapshot:
<<: *docker_definition
dependencies:
- snapshot
only:
- master
docker:release:
<<: *docker_definition
dependencies:
- release
only:
- tags