Skip to content

Commit

Permalink
perf: 容器化-支持各微服务按顺序更新 TencentBlueKing#919
Browse files Browse the repository at this point in the history
镜像打包推送
  • Loading branch information
jsonwan committed Nov 30, 2022
1 parent aed5271 commit 9a7fbac
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 12 deletions.
45 changes: 45 additions & 0 deletions src/backend/job-tools/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

ext {
if (System.getProperty("jobToolsVersion")) {
set("jobToolsVersion", System.getProperty("jobToolsVersion"))
} else if (System.getProperty("bkjobVersion")) {
set("jobToolsVersion", System.getProperty("bkjobVersion"))
} else {
set("jobToolsVersion", "1.0.0")
}
}
version "${jobToolsVersion}"
subprojects {
version "${jobToolsVersion}"
dependencies {
api project(":commons:common")
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'ch.qos.logback:logback-core'
implementation 'ch.qos.logback:logback-classic'
testImplementation 'org.junit.jupiter:junit-jupiter'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@ plugins {
id "com.github.johnrengelman.shadow" version "7.1.1"
}
ext {
if (System.getProperty("jobVersion")) {
set("jobVersion", System.getProperty("jobVersion"))
if (System.getProperty("jobToolsVersion")) {
set("jobToolsVersion", System.getProperty("jobToolsVersion"))
} else if (System.getProperty("bkjobVersion")) {
set("jobVersion", System.getProperty("bkjobVersion"))
set("jobToolsVersion", System.getProperty("bkjobVersion"))
} else {
set("jobVersion", "1.0.0")
set("jobToolsVersion", "1.0.0")
}
}
version "${jobVersion}"
version "${jobToolsVersion}"
dependencies {
api project(":commons:common")
api 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-all'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'ch.qos.logback:logback-core'
implementation 'ch.qos.logback:logback-classic'
testImplementation 'org.junit.jupiter:junit-jupiter'
}
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: "application"
Expand Down
3 changes: 2 additions & 1 deletion src/backend/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ include 'job-analysis:api-job-analysis'
include 'job-analysis:service-job-analysis'
include 'job-analysis:boot-job-analysis'
include 'job-analysis:model-job-analysis'
include 'k8s-startup-controller'
include 'job-tools'
include 'job-tools:k8s-startup-controller'
include 'upgrader'

26 changes: 26 additions & 0 deletions support-files/kubernetes/images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ BUILD_ALL=1
BUILD_FRONTEND=0
BUILD_BACKEND=0
BUILD_MIGRATION=0
BUILD_STARTUP_CONTROLLER=0
BUILD_MODULES=()
VERSION=latest
PUSH=0
Expand Down Expand Up @@ -39,6 +40,7 @@ Usage:
[ --frontend [Optional] Build frontend image ]
[ --backend [Optional] Build backend image ]
[ --migration [Optional] Build migration image ]
[ --startup-controller [Optional] Build startup-controller image ]
[ -m, --modules [Optional] Build specified module images, modules are separated by commas. values:job-frontend,job-migration,job-gateway,job-manage,job-execute,job-crontab,job-logsvr,job-analysis,job-backup,job-file-gateway,job-file-worker. Example: job-manage,job-execute ]
[ -v, --version [Optional] Image tag, default latest ]
[ -p, --push [Optional] Push the image to the docker remote repository, not push by default ]
Expand Down Expand Up @@ -93,12 +95,17 @@ while (( $# > 0 )); do
BUILD_ALL=0
BUILD_MIGRATION=1
;;
--startup-controller )
BUILD_ALL=0
BUILD_STARTUP_CONTROLLER=1
;;
-m | --modules )
shift
BUILD_ALL=0
BUILD_FRONTEND=0
BUILD_BACKEND=0
BUILD_MIGRATION=0
BUILD_STARTUP_CONTROLLER=0
modules_str=$1
BUILD_MODULES=(${modules_str//,/ })
;;
Expand Down Expand Up @@ -217,13 +224,30 @@ build_migration_image(){
fi
}

# Build startup-controller image
build_startup_controller_image(){
log "Building startup-controller image, version: ${VERSION}..."
TOOL_NAME="k8s-startup-controller"
$BACKEND_DIR/gradlew -p $BACKEND_DIR clean :job-tools:$TOOL_NAME:shadowJar -DmavenRepoUrl=$MAVEN_REPO_URL -DbkjobVersion=$VERSION
rm -rf tmp/*
cp $BACKEND_DIR/release/$TOOL_NAME-$VERSION.jar tmp/$TOOL_NAME.jar
cp startup-controller/startup.sh tmp/
docker build -f startup-controller/startupController.Dockerfile -t $REGISTRY/job-tools-$TOOL_NAME:$VERSION tmp --network=host
if [[ $PUSH -eq 1 ]] ; then
docker push $REGISTRY/job-tools-$TOOL_NAME:$VERSION
fi
}

# Building
if [[ $BUILD_ALL -eq 1 || $BUILD_FRONTEND -eq 1 ]] ; then
build_frontend_module
fi
if [[ $BUILD_ALL -eq 1 || $BUILD_MIGRATION -eq 1 ]] ; then
build_migration_image
fi
if [[ $BUILD_ALL -eq 1 || $BUILD_STARTUP_CONTROLLER -eq 1 ]] ; then
build_startup_controller_image
fi
if [[ $BUILD_ALL -eq 1 || $BUILD_BACKEND -eq 1 ]] ; then
for SERVICE in ${BACKENDS[@]};
do
Expand All @@ -239,6 +263,8 @@ if [[ ${#BUILD_MODULES[@]} -ne 0 ]]; then
build_frontend_module
elif [[ "$SERVICE" == "job-migration" ]]; then
build_migration_image
elif [[ "$SERVICE" == "startup-controller" ]]; then
build_startup_controller_image
else
build_backend_module $SERVICE
fi
Expand Down

0 comments on commit 9a7fbac

Please sign in to comment.