forked from GuanceCloud/dataflux-func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
173 lines (165 loc) · 7.55 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
stages:
- build
variables:
OSS_WORKDIR : dataflux-func
OSS_RESOURCE_BASE_URL: oss://${ZY_STATIC_OSS_BUCKET}/${OSS_WORKDIR}/resource
OSS_PORTABLE_BASE_URL: oss://${ZY_STATIC_OSS_BUCKET}/${OSS_WORKDIR}/portable
CDN_REFRESH_PATH : static.guance.com/${OSS_WORKDIR}/
IMAGE : dataflux-func
IMAGE_PRIVATE : registry.jiagouyun.com/middlewares/dataflux-func
IMAGE_PUBLIC : pubrepo.jiagouyun.com/dataflux-func/dataflux-func
IMAGE_GZIP_FILE : dataflux-func.tar.gz
DOCKER_STACK_EXAMPLE_FILE: docker-stack.example.yaml
RUN_DOCKER_STACK_FILE : run-docker-stack.sh
VERSION_FILE : version
PROJECT : dataflux-func
FUNC_PKG_URL : https://static.guance.com/dataflux-func/market/packages/_dataflux/dataflux-func-latest.func-pkg
FUNC_REQUIREMENTS_URL: https://static.guance.com/dataflux-func/market/packages/_dataflux/requirements.txt
# 开发版发布
# 主要用于驻云SaaS版开发
dev:
stage: build
only:
- dev
script:
- docker buildx ls # 确认可用平台
- python echo-image-info.py > image-info.json
- mkdir -p func-pkg; wget ${FUNC_PKG_URL} -O func-pkg/dataflux.func-pkg; # 下载观测云内置库
- wget ${FUNC_REQUIREMENTS_URL} -O requirements-dataflux.txt; # 下载观测云内置库依赖索引
# 开发版只需支持amd64
- docker buildx build
--platform linux/amd64
-t ${IMAGE_PRIVATE}:${CI_COMMIT_REF_NAME}
-t ${IMAGE_PUBLIC}:${CI_COMMIT_REF_NAME}
-f Dockerfile-dataflux .
--push
# 相关文件发送到OSS资源目录
- tools/ossutil64 cp ${DOCKER_STACK_EXAMPLE_FILE} ${OSS_RESOURCE_BASE_URL}-dev/${DOCKER_STACK_EXAMPLE_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
- tools/ossutil64 cp ${RUN_DOCKER_STACK_FILE} ${OSS_RESOURCE_BASE_URL}-dev/${RUN_DOCKER_STACK_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
# 刷新OSS缓存
- pip install -r tools/requirements.txt
- python tools/cdn-refresh-tool.py Directory ${CDN_REFRESH_PATH} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
tags:
- cloudcare-multiarch
# 正式发布
# 版本号自动拆分推送为 "x", "x.y", "x.y.z", "latest"
singleton:
stage: build
only:
- /^\d+\.\d+\.\d+$/ # 如:1.2.3
- /^\d+\.\d+\.\d+rc\d+$/ # 如:1.2.3rc4
script:
- docker buildx ls # 确认可用平台
- python echo-image-info.py > image-info.json
- echo ${CI_COMMIT_REF_NAME} > ${VERSION_FILE}
# 计算版本号
- V_PARTS=(${CI_COMMIT_REF_NAME//[\.]/ })
- V_MAJOR=${V_PARTS[0]}
- V_MAJOR_MINOR=${V_PARTS[0]}.${V_PARTS[1]}
- V_MAJOR_MINOR_PATCH=${V_PARTS[0]}.${V_PARTS[1]}.${V_PARTS[2]}
# 构建/推送多架构版本
- docker buildx build
--platform linux/amd64,linux/arm64
-t ${IMAGE_PRIVATE}:latest
-t ${IMAGE_PRIVATE}:${V_MAJOR}
-t ${IMAGE_PRIVATE}:${V_MAJOR_MINOR}
-t ${IMAGE_PRIVATE}:${V_MAJOR_MINOR_PATCH}
-t ${IMAGE_PUBLIC}:latest
-t ${IMAGE_PUBLIC}:${V_MAJOR}
-t ${IMAGE_PUBLIC}:${V_MAJOR_MINOR}
-t ${IMAGE_PUBLIC}:${V_MAJOR_MINOR_PATCH}
-f Dockerfile-singleton .
--push
# 单独构建amd64版本用于导出
- docker buildx build
--platform linux/amd64
-t ${IMAGE_PUBLIC}:latest
-f Dockerfile-singleton .
--load
- docker save ${IMAGE_PUBLIC}:latest | gzip > ${IMAGE_GZIP_FILE}-amd64
# 单独构建arm64版本用于导出
- docker buildx build
--platform linux/arm64
-t ${IMAGE_PUBLIC}-arm64:latest
-f Dockerfile-singleton .
--load
- docker save ${IMAGE_PUBLIC}-arm64:latest | gzip > ${IMAGE_GZIP_FILE}-arm64
# 相关文件发送到OSS资源目录
- tools/ossutil64 cp ${DOCKER_STACK_EXAMPLE_FILE} ${OSS_RESOURCE_BASE_URL}/${DOCKER_STACK_EXAMPLE_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
- tools/ossutil64 cp ${RUN_DOCKER_STACK_FILE} ${OSS_RESOURCE_BASE_URL}/${RUN_DOCKER_STACK_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
# 相关文件发送到OSS携带版目录
- tools/ossutil64 cp ${DOCKER_STACK_EXAMPLE_FILE} ${OSS_PORTABLE_BASE_URL}/${DOCKER_STACK_EXAMPLE_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
- tools/ossutil64 cp ${IMAGE_GZIP_FILE}-amd64 ${OSS_PORTABLE_BASE_URL}/x86_64/${IMAGE_GZIP_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
- tools/ossutil64 cp ${IMAGE_GZIP_FILE}-arm64 ${OSS_PORTABLE_BASE_URL}/aarch64/${IMAGE_GZIP_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
- tools/ossutil64 cp ${VERSION_FILE} ${OSS_PORTABLE_BASE_URL}/${VERSION_FILE} -f -e ${ZY_STATIC_OSS_ENDPOINT} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
# 刷新OSS缓存
- pip install -r tools/requirements.txt
- python tools/cdn-refresh-tool.py Directory ${CDN_REFRESH_PATH} -i ${ZY_STATIC_OSS_AK_ID} -k ${ZY_STATIC_OSS_AK_SECRET}
tags:
- cloudcare-multiarch
# 观测云同捆发布
# 主要用于驻云SaaS版预发/生产环境
dataflux:
stage: build
only:
- /^pre_\d+_\d+$/ # 如:pre_20190101_01
- /^release_\d+_\d+$/ # 如:release_20190101_01
script:
- docker buildx ls # 确认可用平台
- python echo-image-info.py > image-info.json
- mkdir -p func-pkg; wget ${FUNC_PKG_URL} -O func-pkg/dataflux.func-pkg; # 下载观测云内置库
- wget ${FUNC_REQUIREMENTS_URL} -O requirements-dataflux.txt; # 下载观测云内置库依赖索引
# 构建/推送多架构版本
- docker buildx build
--platform linux/amd64,linux/arm64
-t ${IMAGE_PRIVATE}:${CI_COMMIT_REF_NAME}
-f Dockerfile-dataflux .
--push
tags:
- cloudcare-multiarch
# PaaS 预发
datafluxPaaS_prev:
stage: build
only:
- /\d+\.\d+\.\d+\.\d+-\w+-prev/ # 如:1.10.49.1-c2f4e3b-prev
script:
- docker buildx ls # 确认可用平台
- python echo-image-info.py > image-info.json
- mkdir -p func-pkg; wget ${FUNC_PKG_URL} -O func-pkg/dataflux.func-pkg; # 下载观测云内置库
- wget ${FUNC_REQUIREMENTS_URL} -O requirements-dataflux.txt; # 下载观测云内置库依赖索引
# 计算版本号
- V=(${CI_COMMIT_REF_NAME//[\.-]/ })
- VDIR=${V[0]}.${V[1]}.${V[2]}.${V[3]}
- REPO=dataflux-prev/$VDIR
- TAG=${PROJECT}-${V[4]}
# 构建/推送多架构版本
- docker buildx build
--platform linux/amd64,linux/arm64
-t pubrepo.jiagouyun.com/$REPO:$TAG
-f Dockerfile-dataflux .
--push
tags:
- cloudcare-multiarch
# PaaS 生产
datafluxPaaS_prod:
stage: build
only:
- /\d+\.\d+\.\d+-\w+-\d+-prod/ # 如: 1.9.48-356017d-1600314708-prod
script:
- docker buildx ls # 确认可用平台
- python echo-image-info.py > image-info.json
- mkdir -p func-pkg; wget ${FUNC_PKG_URL} -O func-pkg/dataflux.func-pkg; # 下载观测云内置库
- wget ${FUNC_REQUIREMENTS_URL} -O requirements-dataflux.txt; # 下载观测云内置库依赖索引
# 计算版本号
- V=(${CI_COMMIT_REF_NAME//[\.-]/ })
- VDIR=${V[0]}.${V[1]}.${V[2]}
- REPO=dataflux/$VDIR
- TAG=${PROJECT}-${V[3]}-${V[4]}
# 构建/推送多架构版本
- docker buildx build
--platform linux/amd64,linux/arm64
-t pubrepo.jiagouyun.com/$REPO:$TAG
-f Dockerfile-dataflux .
--push
tags:
- cloudcare-multiarch