Skip to content

Commit

Permalink
Enhance nightly build of Linux-based Docker images. (#78)
Browse files Browse the repository at this point in the history
* Publish images only if build of each one of them succeeds.

* Include release number into image tag.

* Update version number.
  • Loading branch information
AndreyKoltsov1997 authored Jun 16, 2023
1 parent 2e9dbd0 commit 5bc1fe0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .teamcity/hosted/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ class Utils {
"""
}
}
}
}
20 changes: 17 additions & 3 deletions .teamcity/hosted/utils/steps/DockerSteps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
}

0 comments on commit 5bc1fe0

Please sign in to comment.