-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
124 lines (110 loc) · 3.75 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
112
113
114
115
116
117
118
119
120
121
122
123
124
image: golang:1.11
# This is NOT a job and will be ignored by GitLab-CI
.golang_before_script: &goBeforeScript # This is an anchor
before_script:
- go mod tidy
- go get -u golang.org/x/lint/golint
#cache:
# paths:
# - /apt-cache
# - /go/src/github.com
# # - /go/src/gitlab.com
# - /go/src/golang.org
# - /go/src/google.golang.org
# - /go/src/gopkg.in
# - /go/pkg
stages:
- test
- compile
- build
#before_script:
# # - mkdir -p /go/src/gitlab.com/$CI_PROJECT_NAMESPACE /go/src/_/builds
# # - cp -r $CI_PROJECT_DIR /go/src/gitlab.com/$CI_PROJECT_PATH
# # - ln -s /go/src/gitlab.com/$CI_PROJECT_NAMESPACE /go/src/_/builds/$CI_PROJECT_NAMESPACE
# - go mod tidy
# - go get -u golang.org/x/lint/golint
golang_unit_tests:
stage: test
<<: *goBeforeScript # This is a reference to the anchor.
script:
- go test -short ./...
golang_race_detector:
stage: test
<<: *goBeforeScript # This is a reference to the anchor.
script:
- go test -race -short ./...
#golang_memory_sanitizer:
# stage: test
# <<: *goBeforeScript # This is a reference to the anchor.
# script:
# - go test -msan -short ./...
#golang_code_coverage:
# stage: test
# <<: *goBeforeScript # This is a reference to the anchor.
# script:
# - for package in $(go list ./...); do
# go test -covermode=count -coverprofile "cover/${package##*/}.cov" "$package" ;
# done
# - tail -q -n +2 cover/*.cov >> cover/coverage.cov
# - go tool cover -func=cover/coverage.cov
#golang_code_coverage_report:
# stage: test
# <<: *goBeforeScript # This is a reference to the anchor.
# script:
# - for package in $(go list ./...); do
# go test -covermode=count -coverprofile "cover/${package##*/}.cov" "$package" ;
# done
# - tail -q -n +2 cover/*.cov >> cover/coverage.cov
# - go tool cover -func=cover/coverage.cov
# - go tool cover -html=cover/coverage.cov -o coverage.html
# only:
# - master
golang_lint_code:
stage: test
<<: *goBeforeScript # This is a reference to the anchor.
script:
- golint -set_exit_status ./...
golang_compile:
stage: compile
<<: *goBeforeScript # This is a reference to the anchor.
script:
- go build -o bin/$CI_PROJECT_NAME -v .
artifacts:
paths:
- $CI_PROJECT_DIR/bin/$CI_PROJECT_NAME
docker_build_image:
stage: build
image: docker:19.03.1
services:
- docker:19.03.1-dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
- docker run -e BUILD_TEST="TRUE" $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
only:
- master
docker_hub_push:
stage: build
image: docker:19.03.1
services:
- docker:19.03.1-dind
only:
- tags
except:
- /^(?!master).+@/ # Ruby RegEx for anything not starting with 'master'
variables:
DOCKER_HUB_IMAGE: $DOCKER_HUB_USER/$CI_PROJECT_NAME
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_TOKEN $DOCKER_HUB_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $DOCKER_HUB_IMAGE:latest
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $DOCKER_HUB_IMAGE:$CI_COMMIT_TAG
- docker run -e BUILD_TEST="TRUE" $DOCKER_HUB_IMAGE:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker push $DOCKER_HUB_IMAGE:$CI_COMMIT_TAG
- docker push $DOCKER_HUB_IMAGE:latest