Skip to content

Commit 790918f

Browse files
authored
Merge pull request #1337 from merico-dev/feat-add-staging-sync-repo
feat: add staging repo and delete old repo
2 parents 87b7f13 + e679fad commit 790918f

File tree

39 files changed

+1005
-100
lines changed

39 files changed

+1005
-100
lines changed

.yamllint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ ignore: |
3232
**/.github/**
3333
**/githubactions/**
3434
**/workflows/**
35+
**/staging/**

internal/pkg/configmanager/configmanager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pipelineTemplates:
144144
},
145145
},
146146
"branch": "main",
147-
"configLocation": "https://raw.githubusercontent.com/devstream-io/ci-template/main/github-actions/workflows/main.yml",
147+
"configLocation": "https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml",
148148
},
149149
"scm": RawOptions{
150150
"apiURL": "gitlab.com/some/path/to/your/api",

internal/pkg/configmanager/pipelineDefault.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ type pipelineOption struct {
2323
var (
2424
// github actions pipeline options
2525
githubGeneral = pipelineOption{
26-
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/ci-template/main/github-actions/workflows/main.yml",
26+
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml",
2727
optionGeneratorFunc: pipelineGeneralGenerator,
2828
}
2929
gitlabGeneral = pipelineOption{
30-
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/ci-template/main/gitlab-ci/.gitlab-ci.yml",
30+
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/gitlab-ci/.gitlab-ci.yml",
3131
optionGeneratorFunc: pipelineGeneralGenerator,
3232
}
3333
jenkinsGeneral = pipelineOption{
34-
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/ci-template/main/jenkins-pipeline/general/Jenkinsfile",
34+
defaultConfigLocation: "https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/jenkins-pipeline/general/Jenkinsfile",
3535
optionGeneratorFunc: jenkinsGenerator,
3636
}
3737
argocdApp = pipelineOption{

internal/pkg/configmanager/pipelinetemplate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var _ = Describe("PipelineTemplate struct", func() {
231231
Options: RawOptions{
232232
"pipeline": RawOptions{
233233
"test": "testV",
234-
"configLocation": "https://raw.githubusercontent.com/devstream-io/ci-template/main/github-actions/workflows/main.yml",
234+
"configLocation": "https://raw.githubusercontent.com/devstream-io/dtm-pipeline-templates/main/github-actions/workflows/main.yml",
235235
},
236236
"scm": RawOptions{
237237
"url": git.ScmURL(cloneURL),

internal/pkg/plugin/argocdapp/argocdapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func pushArgocdConfigFiles(rawOptions configmanager.RawOptions) error {
3838
}
3939

4040
// 3. get argocd configFiles from remote
41-
const configLocation = downloader.ResourceLocation("https://github.com/devstream-io/ci-template.git//argocdapp/helm")
41+
const configLocation = downloader.ResourceLocation("https://github.com/devstream-io/dtm-pipeline-templates.git//argocdapp/helm")
4242
gitFiles, err := opts.getArgocdDefaultConfigFiles(configLocation)
4343
if err != nil {
4444
return err

internal/pkg/plugin/gitlabci/generic/generic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ func repoScaffoldShareLib(repoInfo *git.RepoInfo) error {
5454
repoScaffoldOptions := configmanager.RawOptions{
5555
"sourceRepo": map[string]interface{}{
5656
"owner": "devstream-io",
57-
"repo": "gitlab-ci-library",
57+
"repo": "dtm-gitlab-share-library",
5858
"repoType": "github",
5959
},
6060
"destinationRepo": map[string]interface{}{
6161
"owner": repoInfo.GetRepoOwner(),
6262
"branch": "master",
63-
"repo": "gitlab-ci-library",
63+
"repo": "gitlab-share-library",
6464
"repoType": "gitlab",
6565
"baseURL": repoInfo.BaseURL,
6666
},

pkg/util/jenkins/tpl/repo-casc.tpl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ unclassified:
3939
scm:
4040
git:
4141
id: "56904e9b-d14b-4932-b3b3-21bc11c2cb86"
42-
remote: "https://github.com/devstream-io/jenkins-share-library.git"
42+
remote: "https://github.com/devstream-io/dtm-jenkins-share-library.git"
4343
traits:
4444
- "gitBranchDiscovery"
4545
[[- end ]]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# dtm-gitlab-share-library
2+
3+
This repo contains share library used by DevStream plugin "gitlab-ci" (thereafter: the plugin). It currently has the following functions:
4+
- send notification to dingtalk when pipeline result is success or failed.
5+
- build docker image by current project, and push this image to image repo.
6+
7+
## General config variables
8+
9+
| field | description | default_value |
10+
| ---- | ---- | ---- |
11+
| CI_REGISTRY_USER | image repo owner | |
12+
| CI_REGISTRY_PASSWORD | image repo owner's password | |
13+
14+
## Where does this repo come from?
15+
16+
`dtm-gitlab-share-library` is synced from https://github.com/devstream-io/devstream/blob/main/staging/dtm-gitlab-share-library.
17+
Code changes are made in that location, merged into `devstream-io/devstream` and later synced here.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.build-docker:
2+
stage: build
3+
script:
4+
- auth=`echo -n "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" | base64`
5+
- mkdir -p ~/.docker
6+
# - authfile=`{"auths": {"test": {"auth": "$auth"}}}`
7+
# - echo $authfile > ~/.docker/config.json
8+
- buildctl build --frontend dockerfile.v0 --local context=. --local dockerfile=. --output type=image,name=${imageRepo}:${defaultTag},push=true${opts}
9+
- echo "SUCCESS" > .job_status
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# 钉钉消息发送模版任务
2+
# 必须变量
3+
# DINGTALK_ACCESS_TOKEN 群机器人token
4+
5+
variables:
6+
# 钉钉markdown换行符 必须\n且前后跟两个空格(shell 转义)
7+
V_BR: "\ \ \\n\ \ "
8+
9+
# 消息发送准备工作
10+
# 检测钉钉消息发送access_token是否存在
11+
.prepare: &prepare
12+
# token检验
13+
- |
14+
if [ -z $DINGTALK_ACCESS_TOKEN ]; then
15+
echo "使用钉钉消息发送必须配置DINGTALK_ACCESS_TOKEN变量"
16+
exit 1
17+
fi
18+
- |
19+
if [ -z $DINGTALK_SECURITY_VALUE ]; then
20+
echo "使用钉钉消息发送必须配置DINGTALK_SECURITY_VALUE变量"
21+
exit 1
22+
fi
23+
# url编码项目地址及任务地址
24+
- |
25+
project_url="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "${GITLAB_URL}/${CI_PROJECT_PATH}/-/tree/${CI_BUILD_REF_NAME}" "" || true)"
26+
job_url="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "${GITLAB_URL}/${CI_PROJECT_PATH}/-/jobs/${CI_JOB_ID}" "" || true)"
27+
28+
# 钉钉消息发送http Anchors
29+
.send_request: &send_request
30+
# Markdown消息内容
31+
- |
32+
V_TEXT="**CI任务<font color=\\\"${V_COLOR}\\\">${V_STATUS}</font>通知**${V_BR}\
33+
任务ID: **${CI_JOB_ID}**${V_BR}\
34+
任务名: **${CI_JOB_NAME}**${V_BR}\
35+
项目: **${CI_PROJECT_PATH}**${V_BR}\
36+
分支: **${CI_BUILD_REF_NAME}**${V_BR}\
37+
执行人: **${GITLAB_USER_NAME}**\
38+
"
39+
# 钉钉消息发送json报文
40+
- |
41+
V_JSON="{
42+
\"actionCard\": {\
43+
\"title\": \"${V_TITLE}\",\
44+
\"text\": \"${V_TEXT}\", \
45+
\"btnOrientation\": \"1\",\
46+
\"btns\": [{\
47+
\"title\": \"查看项目\",
48+
\"actionURL\": \"dingtalk://dingtalkclient/page/link?url=${project_url##/?}&pc_slide=false\"
49+
}, {\
50+
\"title\": \"查看任务\",
51+
\"actionURL\": \"dingtalk://dingtalkclient/page/link?url=${job_url##/?}&pc_slide=false\"
52+
}]\
53+
},\
54+
\"msgtype\": \"actionCard\"\
55+
}"
56+
- >
57+
curl -s -H 'Content-Type: application/json; charset=utf-8' -X POST
58+
https://oapi.dingtalk.com/robot/send?access_token=${DINGTALK_ACCESS_TOKEN} -d "${V_JSON}" -w "\n"
59+
60+
# 消息发送模板任务
61+
.pre:
62+
stage: .pre
63+
image: curlimages/curl:7.86.0
64+
script:
65+
- *prepare
66+
- |
67+
V_COLOR="#FF9900"
68+
V_STATUS="启动"
69+
V_TITLE="CI任务启动通知"
70+
- echo "GITLAB_CI_STATUS=FAIL" >> build.env
71+
- *send_request
72+
artifacts:
73+
reports:
74+
dotenv: build.env
75+
76+
.post:
77+
stage: .post
78+
image: curlimages/curl:7.86.0
79+
# 发送ci结束消息
80+
script:
81+
- *prepare
82+
# 不同任务状态设置不同消息标题、颜色
83+
- |
84+
case $GITLAB_CI_STATUS in
85+
ALL_SUCCESS)
86+
V_TITLE="CI任务执行成功通知"
87+
V_STATUS="执行成功"
88+
V_COLOR="#33CC00"
89+
;;
90+
FAIL)
91+
V_TITLE="CI任务执行失败通知"
92+
V_STATUS="执行失败"
93+
V_COLOR="#FF3333"
94+
;;
95+
*)
96+
echo "不支持job状态$GITLAB_CI_STATUS"
97+
exit 1
98+
;;
99+
esac
100+
# 执行耗时计算
101+
- *send_request

0 commit comments

Comments
 (0)