Skip to content

Commit

Permalink
Implement composite build for automated, scheduled creation of Window…
Browse files Browse the repository at this point in the history
…s / Linux Docker Images. (#49)

* Implement composite build for creation of Windows / Linux Docker Images on nightly basis.

* * Change declaration of target platform of particular Docker Image.
* Rename 'nightly' to 'scheduled' in order to have a more generic name.

* Rename names and description for builds responsible for automated build of Docker images.

* Update name and description of composite build.
  • Loading branch information
AndreyKoltsov1997 authored Jan 4, 2023
1 parent 29b92b2 commit 36d007d
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hosted.scheduled.build

import jetbrains.buildServer.configs.kotlin.v2019_2.*
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.schedule

/**
* Scheduled Composite Build of TeamCity Docker Images for each of supported platforms.
* Purpose: ensure that all dependencies within Docker Images are up-to-date.
*/
object TeamCityDockerImagesScheduledBuild : BuildType({
name = "TeamCity Docker Images - Automated Scheduled Build"
description = "Regular automated build of TeamCity Docker Images"

type = Type.COMPOSITE

vcs {
showDependenciesChanges = true
}

triggers {
schedule {
id = "TRIGGER_TC_DOCKER_IMAGES_NIGHTLY"
schedulingPolicy = daily {
hour = 0
minute = 15
}
branchFilter = "+:<default>"
withPendingChangesOnly = false
}
}

dependencies {
arrayOf(
TeamCityScheduledImageBuildWindows.TeamCityScheduledImageBuildWindows,
TeamCityScheduledImageBuildLinux.TeamCityScheduledImageBuildLinux
).forEach {
snapshot(it) {
onDependencyFailure = FailureAction.ADD_PROBLEM
onDependencyCancel = FailureAction.CANCEL
}
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package hosted.scheduled.build

import common.TeamCityDockerImagesRepo.TeamCityDockerImagesRepo
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.DockerCommandStep
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.dockerCommand


/**
* Scheduled build of TeamCity Docker Images for Linux.
*/
object TeamCityScheduledImageBuildLinux : BuildType({
name = "TeamCity Docker Images - Automated Scheduled Build - Linux"

vcs {
root(TeamCityDockerImagesRepo)
}

// <image name> - <dockerfile path>
val targetImages: HashMap<String, String> = hashMapOf(
// Ubuntu 20.04
"teamcity-server-linux-20-04" to "context/generated/linux/Server/Ubuntu/20.04/Dockerfile",
"teamcity-minimal-agent-linux-20-04" to "context/generated/linux/MinimalAgent/Ubuntu/20.04/Dockerfile",
"teamcity-agent-linux-20-04" to "context/generated/linux/Agent/Ubuntu/20.04/Dockerfile",
"teamcity-agent-linux-sudo-20-04" to "context/generated/linux/Agent/Ubuntu/20.04-sudo/Dockerfile",
// -- ARM images are commented out since TeamCity, currently, does not support it
// "teamcity-agent-linux-arm64-20-04" to "context/generated/linux/Agent/UbuntuARM/20.04/Dockerfile",
// "teamcity-agent-linux-arm64-sudo-20-04" to "context/generated/linux/Agent/UbuntuARM/20.04-sudo/Dockerfile",
)

steps {
targetImages.forEach { (imageName, dockerfilePath) ->
dockerCommand {
name = "build $imageName"
commandType = build {
source = file {
path = dockerfilePath
}
platform = DockerCommandStep.ImagePlatform.Linux
contextDir = "context"
namesAndTags = "${imageName}:%dockerImage.teamcity.buildNumber%"
}
}
}
}

requirements {
contains("docker.server.osType", "linux")
contains("system.agent.name", "docker")
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package hosted.scheduled.build

import common.TeamCityDockerImagesRepo.TeamCityDockerImagesRepo
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.DockerCommandStep
import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.dockerCommand

/**
* Scheduled build of TeamCity Docker Images for Windows.
*/
object TeamCityScheduledImageBuildWindows : BuildType({
name = "TeamCity Docker Images - Automated Scheduled Build - Windows"

vcs {
root(TeamCityDockerImagesRepo)
}

// <image name> - <dockerfile path>
val targetImages: HashMap<String, String> = hashMapOf(
// Windows 1809
"teamcity-server-nanoserver-1809" to "context/generated/windows/Server/nanoserver/1809/Dockerfile",
"teamcity-minimal-agent-nanoserver-1809" to "context/generated/windows/MinimalAgent/nanoserver/1809/Dockerfile",
"teamcity-agent-windowsservercore-1809" to "context/generated/windows/Agent/windowsservercore/1809/Dockerfile",
"teamcity-agent-nanoserver-1809" to "context/generated/windows/Agent/nanoserver/1809/Dockerfile",

// Windows 20.04
"teamcity-server-nanoserver-2004" to "context/generated/windows/Server/nanoserver/2004/Dockerfile",
"teamcity-minimal-agent-nanoserver-2004" to "context/generated/windows/MinimalAgent/nanoserver/2004/Dockerfile",
"teamcity-agent-windowsservercore-2004" to "context/generated/windows/Agent/windowsservercore/2004/Dockerfile",
"teamcity-agent-nanoserver-2004" to "context/generated/windows/Agent/nanoserver/2004/Dockerfile",
)

steps {
targetImages.forEach { (imageName, dockerfilePath) ->
dockerCommand {
name = "build $imageName"
commandType = build {
source = file {
path = dockerfilePath
}
platform = DockerCommandStep.ImagePlatform.Windows;
contextDir = "context"
namesAndTags = "${imageName}:%dockerImage.teamcity.buildNumber%"
}
}
}
}

requirements {
contains("docker.server.osType", "windows")
contains("system.agent.name", "docker")
}
})
3 changes: 3 additions & 0 deletions .teamcity/settings.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Settings.RootProject.buildTypes
import jetbrains.buildServer.configs.kotlin.v2019_2.*
import common.TeamCityDockerImagesRepo.TeamCityDockerImagesRepo
import hosted.*
import generated.*
import hosted.scheduled.build.TeamCityDockerImagesScheduledBuild

version = "2019.2"

Expand All @@ -10,6 +12,7 @@ object RootProject : Project({
subProject(LocalProject.LocalProject)
subProject(HubProject.HubProject)
buildType(BuildAndPushHosted.BuildAndPushHosted)
buildType(TeamCityDockerImagesScheduledBuild.TeamCityDockerImagesScheduledBuild)
params {
param("dockerImage.teamcity.buildNumber", "%dep.TC_Trunk_BuildDistDocker.build.number%")
param("teamcity.ui.settings.readOnly", "false")
Expand Down

0 comments on commit 36d007d

Please sign in to comment.