-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy path.gitlab-ci.yml
97 lines (95 loc) · 3.93 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
variables:
PATH: /opt/go/go/bin/:/opt/node/node/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
GOROOT: /opt/go/go
GOPROXY: https://goproxy.cn
SAVE_DIR: /opt/apinto-dashboard
VERSION: $CI_COMMIT_SHORT_SHA
APP: apserver
APP_PRE: ${APP}_${VERSION}
BUILD_DIR: apserver-build
default:
cache:
paths:
- frontend/dist/
- ${BUILD_DIR}
stages:
- notice
- prefix
- build
- publish
- webhook
feishu-informer: # 飞书回调
stage: notice
variables:
DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs"
rules:
- if: $CI_PIPELINE_SOURCE=="merge_request_event"
script:
- echo "merge request"
- |
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:${CI_PROJECT_NAME}\\n提交人:${GITLAB_USER_NAME}\\n提交信息:${CI_MERGE_REQUEST_TITLE}\\n合并分支信息:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\\n差异性地址:${DIFF_URL}\\n请及时review代码\"}}" \
https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
prebuild:
stage: prefix
script:
- echo "prebuild"
- chmod +x ./scripts/prefix.sh
- ./scripts/prefix.sh
frontend-builder: # 前端构建
stage: build
rules:
- if: $CI_COMMIT_TITLE =~ /^frontend-business/ && ($CI_COMMIT_BRANCH == "V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/) # 当前端提交后触发
variables:
BUILD_TYPE: business
- if: $CI_COMMIT_TITLE =~ /^frontend/ && ($CI_COMMIT_BRANCH == "V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/) # 当前端提交后触发
script:
# - sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- go mod tidy
- ./scripts/build.sh $BUILD_DIR all ${VERSION} ${BUILD_TYPE}
golang-builder:
stage: build
rules:
- if: $CI_COMMIT_TITLE !~ /^frontend/ && ($CI_COMMIT_BRANCH == "V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/) # 当后端提交后触发
variables:
BUILD_TYPE: business
script:
# - sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- go mod tidy
- ./scripts/build.sh $BUILD_DIR backend ${VERSION} ${BUILD_TYPE}
deployer:
stage: publish
rules:
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/ || $CI_COMMIT_TITLE =~ /^frontend/
variables:
DEPLOY_DESC: "DEV 环境"
VIEW_ADDR: http://172.18.166.219:8080/
script:
- cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR}
- cd ${SAVE_DIR};tar -zxvf ${APP_PRE}_linux_amd64.tar.gz;cd ${APP_PRE};./install.sh ${SAVE_DIR};./run.sh restart;cd ${SAVE_DIR};./clean.sh ${APP_PRE}
when: on_success
success:
stage: webhook
rules:
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/
variables:
DEPLOY_DESC: "DEV 环境"
VIEW_ADDR: http://172.18.166.219:8080/
script:
- |
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:apinto-dashboard\\n环境:${DEPLOY_DESC}\\n更新部署完成.\\n访问地址:${VIEW_ADDR}\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
when: on_success
failure:
stage: webhook
rules:
- if: $CI_COMMIT_BRANCH=="V2.0" || $CI_COMMIT_BRANCH =~ /^release\/v/
variables:
DEPLOY_DESC: "DEV 环境"
script:
- |
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:apinto-dashboard\\n环境:${DEPLOY_DESC}\\n更新部署失败,请及时到gitlab上查看\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
when: on_failure