-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.gitlab-ci.yml
49 lines (44 loc) · 1.11 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
image: docker:stable
stages: # 阶段
- test
- build
- deploy
variables: # 声明环境变量
BUILD_TAG: 1.0.
IMAGE: 镜像仓库地址/test01:v${BUILD_TAG}
test_job:
stage: test
image: golang:1.14.4-stretch
only:
- master
tags: # CI tag 名称
- k8s-runner
script: # 构建命令
- echo "test code"
- go env -w GOPROXY=https://goproxy.cn,direct
- make test
build_job:
stage: build
image: docker:stable
only:
- master
tags: # CI tag 名称
- k8s-runner
script: # 构建命令
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -t ${IMAGE}${CI_PIPELINE_ID} .
- docker push ${IMAGE}${CI_PIPELINE_ID}
deploy_job:
image: registry.cn-hangzhou.aliyuncs.com/haoshuwei24/kubectl:1.16.6
stage: deploy
environment:
name: production #必须完全匹配
url: http://xxx/test01/healthy
tags:
- k8s-runner
script:
- mkdir -p ~/.kube
- echo ${K8S_CONFIG} | base64 -d > ~/.kube/config
- sed -i "s/<BUILD_NUMBER>/${BUILD_TAG}${CI_PIPELINE_ID}/g" dev.yaml
- cat dev.yaml
- kubectl apply -f dev.yaml