-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
111 lines (102 loc) · 2.88 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
variables:
APP_NAME: cago
APP_VERSION: 1.0.0
NAMESPACE: app
REGISTRY: "docker.io"
REPOSITORY: "cago/application"
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn,direct"
GOPATH: "$CI_PROJECT_DIR/.cache"
GOLANGCI_LINT_CACHE: "$CI_PROJECT_DIR/.lint-cache"
DOMAIN: "cago.com"
stages:
- test
- build
- docker
- deploy
test-job:
stage: test
image: golang:1.20-alpine3.16
cache:
key: go-cache
paths:
- .cache
script:
- go test -v ./...
lint-job:
stage: test
image: golangci/golangci-lint:v1.52
cache:
key: lint-cache
paths:
- .lint-cache
script:
- golangci-lint run -v
build:
stage: build
image: golang:1.20-alpine3.16
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/ || $CI_COMMIT_BRANCH =~ /^test\/.*$/
cache:
key: go-cache
paths:
- .cache
script:
- CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o $APP_NAME ./cmd/app
artifacts:
expire_in: 1 week
paths:
- $APP_NAME
build-docker:
stage: docker
image: docker:rc
rules:
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/ || $CI_COMMIT_BRANCH =~ /^test\/.*$/
variables:
DOCKER_HOST: tcp://docker-dind:2375
before_script:
- docker login $REGISTRY --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
script:
- docker build . --build-arg APP_NAME=$APP_NAME -f deploy/docker/Dockerfile -t $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA
- docker push $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA
deploy-prod:
stage: deploy
image: alpine/helm:3.9.0
rules:
- if: $CI_COMMIT_BRANCH == "main"
script:
- cd deploy/helm
- |
helm upgrade --install --namespace $NAMESPACE $APP_NAME . \
--set image.tag=$CI_COMMIT_SHORT_SHA --set image.repository=$REGISTRY/$REPOSITORY \
--set etcdConfig.password=$ETCD_CONFIG_PASSWORD
deploy-pre:
stage: deploy
image: alpine/helm:3.9.0
rules:
- if: $CI_COMMIT_BRANCH =~ /^release\/.*$/
script:
- cd deploy/helm
- |
helm upgrade --install \
--namespace $NAMESPACE $APP_NAME-pre . -f values.yaml \
--set image.tag=$CI_COMMIT_SHORT_SHA --set image.repository=$REGISTRY/$REPOSITORY \
--set etcdConfig.password=$ETCD_CONFIG_PASSWORD \
--set appConfig.env=pre \
--set ingress.hosts[0].host=pre.$DOMAIN \
--set ingress.tls[0].hosts[0]=pre.$DOMAIN
deploy-test:
stage: deploy
image: alpine/helm:3.9.0
rules:
- if: $CI_COMMIT_BRANCH =~ /^test\/.*$/
script:
- cd deploy/helm
- |
helm upgrade --install \
--namespace $NAMESPACE $APP_NAME-test . -f values.yaml \
--set image.tag=$CI_COMMIT_SHORT_SHA --set image.repository=$REGISTRY/$REPOSITORY \
--set etcdConfig.password=$ETCD_CONFIG_PASSWORD \
--set appConfig.env=test \
--set ingress.hosts[0].host=test.$DOMAIN \
--set ingress.tls[0].hosts[0]=test.$DOMAIN