From 5bc1fe011b24ead6ebb4ab3901da646267d04102 Mon Sep 17 00:00:00 2001 From: Andrey Koltsov Date: Fri, 16 Jun 2023 17:19:34 +0200 Subject: [PATCH] Enhance nightly build of Linux-based Docker images. (#78) * Publish images only if build of each one of them succeeds. * Include release number into image tag. * Update version number. --- .../TeamCityScheduledImageBuildLinux.kts | 5 +++-- .../TeamCityScheduledImageBuildLinux_Base.kt | 7 ++++++- .teamcity/hosted/utils/Utils.kt | 2 +- .teamcity/hosted/utils/steps/DockerSteps.kt | 20 ++++++++++++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts index e631ed874..f09f7bd87 100644 --- a/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts +++ b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts @@ -8,7 +8,6 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.AbsoluteId import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.dockerSupport import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script -import java.io.File /** @@ -29,7 +28,9 @@ object TeamCityScheduledImageBuildLinux : BuildType({ param("docker.buildRepository", "%docker.nightlyRepository%") // no postfix needed param("docker.buildImagePostfix", "") - param("tc.image.version", "%dockerImage.teamcity.buildNumber%") + + // 'trunk' could be replaced with a particular release number, such as 2023.05. + param("tc.image.version", "trunk-%dockerImage.teamcity.buildNumber%") } steps { diff --git a/.teamcity/hosted/scheduled/build/base/TeamCityScheduledImageBuildLinux_Base.kt b/.teamcity/hosted/scheduled/build/base/TeamCityScheduledImageBuildLinux_Base.kt index 5442f84ef..98eec4a91 100644 --- a/.teamcity/hosted/scheduled/build/base/TeamCityScheduledImageBuildLinux_Base.kt +++ b/.teamcity/hosted/scheduled/build/base/TeamCityScheduledImageBuildLinux_Base.kt @@ -3,6 +3,8 @@ import hosted.utils.ImageInfoRepository import hosted.utils.Utils import hosted.utils.models.ImageInfo import hosted.utils.steps.buildAndPublishImage +import hosted.utils.steps.buildImage +import hosted.utils.steps.publishImage import jetbrains.buildServer.configs.kotlin.v2019_2.AbsoluteId import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.dockerSupport @@ -50,8 +52,11 @@ class TeamCityScheduledImageBuildLinux_Base(private val platform: String, privat } steps { + // build each image + images.forEach { imageInfo -> buildImage(imageInfo) } - images.forEach { imageInfo -> buildAndPublishImage(imageInfo) } + // publish images if build of each one of them succeeded + images.forEach { imageInfo -> publishImage(imageInfo) } script { name = "Generate Sample docker-compose manifest for the created images" diff --git a/.teamcity/hosted/utils/Utils.kt b/.teamcity/hosted/utils/Utils.kt index c7624f2e5..93c319191 100644 --- a/.teamcity/hosted/utils/Utils.kt +++ b/.teamcity/hosted/utils/Utils.kt @@ -130,4 +130,4 @@ class Utils { """ } } -} \ No newline at end of file +} diff --git a/.teamcity/hosted/utils/steps/DockerSteps.kt b/.teamcity/hosted/utils/steps/DockerSteps.kt index 4fde185d0..ed2f72f9d 100644 --- a/.teamcity/hosted/utils/steps/DockerSteps.kt +++ b/.teamcity/hosted/utils/steps/DockerSteps.kt @@ -13,11 +13,11 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script */ + /** - * Build and publishes given Docker image. - * @param imageInfo information about Docker image + * Build given image: sets context, builds it, adds tag. */ -fun BuildSteps.buildAndPublishImage(imageInfo: ImageInfo) { +fun BuildSteps.buildImage(imageInfo: ImageInfo) { this.script { name = "Set build context for [${imageInfo.name}]" scriptContent = Utils.getDockerignoreCtx(imageInfo) @@ -43,7 +43,12 @@ fun BuildSteps.buildAndPublishImage(imageInfo: ImageInfo) { commandArgs = "${imageInfo.baseFqdn} ${imageInfo.stagingFqdn}" } } +} +/** + * Publishes provided image into its registry. + */ +fun BuildSteps.publishImage(imageInfo: ImageInfo) { this.dockerCommand { name = "Push image to registry - [${imageInfo.stagingFqdn}]" commandType = push { @@ -52,3 +57,12 @@ fun BuildSteps.buildAndPublishImage(imageInfo: ImageInfo) { } } } + +/** + * Build and publishes given Docker image. + * @param imageInfo information about Docker image + */ +fun BuildSteps.buildAndPublishImage(imageInfo: ImageInfo) { + buildImage(imageInfo) + publishImage(imageInfo) +}