Skip to content

Commit

Permalink
Merge pull request #8392 from stubenhuang/issue-init-plugin-8338
Browse files Browse the repository at this point in the history
feat: 容器化部署时自动上传插件到应用商店 #8338
  • Loading branch information
irwinsun authored Feb 22, 2023
2 parents ad95ffc + 2851f4d commit 89eab5e
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 19 deletions.
5 changes: 3 additions & 2 deletions docker-images/core/ci/dockerfile/backend.bkci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ ENV LANG="en_US.UTF-8"

RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' > /etc/timezone && \
yum update -y && \
yum install mysql -y && \
yum update -y &&\
yum install -y epel-release &&\
yum install -y mysql &&\
yum install -y redis &&\
yum install -y python3 &&\
pip3 install requests

Expand Down
17 changes: 17 additions & 0 deletions helm-charts/core/ci/build/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ init:
turbo: true
bkrepo: true
defaultImage: true
plugin:
enabled: true
atoms:
- url: https://github.com/TencentBlueKing/ci-checkout/releases/download/v2.0.12/checkout.zip
code: checkout
- url: https://github.com/TencentBlueKing/ci-run/releases/download/v1.0.2/run-v1.0.2.zip
code: run
- url: https://github.com/TencentBlueKing/ci-SubPipelineExec/releases/download/v1.0.4/ci-SubPipelineExec.zip
code: SubPipelineExec
- url: https://github.com/TencentBlueKing/ci-uploadArtifact/releases/download/v2.0.1/uploadArtifact_en.zip
code: uploadArtifact
- url: https://github.com/TencentBlueKing/ci-uploadReport/releases/download/v1.0.1/uploadReport_en.zip
code: uploadReport
- url: https://github.com/TencentBlueKing/ci-AcrossProjectDistribution/releases/download/v1.1.1/AcrossProjectDistribution_en.zip
code: AcrossProjectDistribution
- url: https://github.com/TencentBlueKing/ci-downloadArtifact/releases/download/v1.0.2/downloadArtifact_en.zip
code: downloadArtifact

# 多集群开关
multiCluster:
Expand Down
18 changes: 18 additions & 0 deletions helm-charts/core/ci/templates/configmap/monitoring-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#monitoring configmap
{{ if .Values.configmap.enabled -}}
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ include "bkci.names.fullname" . }}-monitoring
labels: {{- include "bkci.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: monitoring
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 4 }}
{{- end }}
data:
application.yml: |-
{{- include "bkci.monitoring.yaml" . | nindent 4 -}}
{{- end -}}
13 changes: 12 additions & 1 deletion helm-charts/core/ci/templates/init/init.defaultImages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ spec:
- "/bin/bash"
- "-c"
- |
sleep 240s;
services="store project"
for service in $services
do
until curl --connect-timeout 3 -m 1 -s "http://{{ include "bkci.names.fullname" . }}-$service.{{ .Release.Namespace }}.svc.cluster.local" > nohup
do
echo "waiting for {{ include "bkci.names.fullname" . }}-$service";
sleep 2;
done
echo "{{ include "bkci.names.fullname" . }}-$service is available";
done
echo "{{ include "bkci.names.fullname" . }}-store is available";
curl "http://{{ include "bkci.names.fullname" . }}-store.{{ .Release.Namespace }}.svc.cluster.local/api/op/market/image/init" -X POST
restartPolicy: OnFailure
{{- end -}}
65 changes: 65 additions & 0 deletions helm-charts/core/ci/templates/init/init.plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 初始化商店插件
{{ if .Values.init.plugin.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "bkci.names.fullname" . }}-init-plugin
labels: {{- include "bkci.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: init-plugin
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
metadata:
labels: {{- include "bkci.labels.standard" . | nindent 8 }}
app.kubernetes.io/component: init-plugin
spec:
containers:
- name: init-plugin
image: {{ include "common.images.image" ( dict "imageRoot" .Values.backendImage "global" $) }}
imagePullPolicy: {{ .Values.backendImage.pullPolicy }}
workingDir: /data/workspace/
{{ $mysqlData := split ":" (include "bkci.mysqlAddr" .) }}
command:
- "/bin/bash"
- "-c"
- |
services="store artifactory"
for service in $services
do
until curl --connect-timeout 3 -m 1 -s "http://{{ include "bkci.names.fullname" . }}-$service.{{ .Release.Namespace }}.svc.cluster.local" > nohup
do
echo "waiting for {{ include "bkci.names.fullname" . }}-$service";
sleep 2;
done
echo "{{ include "bkci.names.fullname" . }}-$service is available";
done
touch atom.sql
touch atom.redis
{{ range .Values.init.plugin.atoms }}
atom_code={{ .code }}
check_atom_url=http://{{ include "bkci.names.fullname" $ }}-store.{{ $.Release.Namespace }}.svc.cluster.local/api/service/pipeline/atom/codes/$atom_code/versions/1.0.0
check_atom_response=$(curl -s $check_atom_url)
if [ -z $(echo $check_atom_response | grep -o "atomCode") ]; then
atom_url={{ .url }}
atom_file=${atom_code}.zip
curl -s $atom_url -o $atom_file -L
if [ $? -eq 0 ]; then
curl "http://{{ include "bkci.names.fullname" $ }}-store.{{ $.Release.Namespace }}.svc.cluster.local/api/op/pipeline/atom/deploy" -H "X-DEVOPS-UID: admin" -F atomCode=$atom_code -F file=@$atom_file
fi
else
echo "atomCode exists"
fi
echo 'UPDATE devops_ci_store.T_ATOM SET DEFAULT_FLAG=true WHERE ATOM_CODE="$atom_code"' >> atom.sql
echo 'SADD STORE_PUBLIC_FLAG_KEY:ATOM $atom_code' >> atom.redis
{{ end }}
mysql -u{{- include "bkci.mysqlUsername" . }} -p{{- include "bkci.mysqlPassword" . }} -h{{ $mysqlData._0 }} -P{{ $mysqlData._1 }} < atom.sql
redis-cli -h {{ include "bkci.redisHost" . }} -a {{ include "bkci.redisPassword" . }} -p {{ include "bkci.redisPort" . }} < atom.redis
restartPolicy: OnFailure
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
api(project(":core:common:common-client"))
api(project(":core:common:common-auth:common-auth-api"))
api(project(":core:common:common-auth:common-auth-v3"))
api(project(":core:common:common-auth:common-auth-mock"))
api(project(":core:project:api-project-sample"))
api(project(":core:process:api-process"))
api(project(":core:repository:api-repository"))
Expand Down
Loading

0 comments on commit 89eab5e

Please sign in to comment.