-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
117 lines (102 loc) · 2.37 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
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml
image: golang:1.15
stages:
- prepare
- build
- docker-build
- test
- docker-release
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == "master"
variables:
GOPATH: $CI_PROJECT_DIR/.go
CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE
.go-cache:
variables:
GOPATH: $CI_PROJECT_DIR/.go
before_script:
- mkdir -p .go
cache:
key: "$CI_COMMIT_REF_SLUG"
paths:
- .go/pkg/mod/
gomod:
stage: prepare
extends: .go-cache
script:
- go mod download
build:
stage: build
extends: .go-cache
needs:
- gomod
variables:
CGO_ENABLED: "0"
script:
- go build -o netlify-deployer
artifacts:
paths:
- netlify-deployer
expire_in: 1 days
.docker-job:
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
.docker-build-job:
stage: docker-build
extends: .docker-job
needs:
- build
script:
- docker build -f $DOCKERFILE --pull -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
build-image-minimal:
extends: .docker-build-job
variables:
DOCKERFILE: Dockerfile.minimal
CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
build-image-ci:
extends: .docker-build-job
variables:
DOCKERFILE: Dockerfile.ci
CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-ci"
lint:
stage: test
extends: .go-cache
needs:
- gomod
image: golangci/golangci-lint:v1.27.0
script:
- golangci-lint run -v
.docker-publish-job:
stage: docker-release
extends: .docker-job
script:
- docker pull $CONTAINER_IMAGE
- docker tag $CONTAINER_IMAGE $CONTAINER_IMAGE_RELEASE
- docker push $CONTAINER_IMAGE_RELEASE
rules:
- if: $CI_COMMIT_BRANCH == "master"
publish-image-minimal:
extends: .docker-publish-job
needs:
- build-image-minimal
variables:
CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
CONTAINER_IMAGE_RELEASE: "$CI_REGISTRY_IMAGE:latest"
publish-image-ci:
extends: .docker-publish-job
needs:
- build-image-ci
variables:
CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA-ci"
CONTAINER_IMAGE_RELEASE: "$CI_REGISTRY_IMAGE:ci"