From 36d007dd12f409012a592cf09ec4fa39e4e6e860 Mon Sep 17 00:00:00 2001 From: Andrey Koltsov Date: Wed, 4 Jan 2023 11:07:33 +0100 Subject: [PATCH] Implement composite build for automated, scheduled creation of Windows / 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. --- .../TeamCityDockerImagesScheduledBuild.kts | 43 +++++++++++++++ .../TeamCityScheduledImageBuildLinux.kts | 51 ++++++++++++++++++ .../TeamCityScheduledImageBuildWindows.kts | 53 +++++++++++++++++++ .teamcity/settings.kts | 3 ++ 4 files changed, 150 insertions(+) create mode 100644 .teamcity/hosted/scheduled/build/TeamCityDockerImagesScheduledBuild.kts create mode 100644 .teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts create mode 100644 .teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildWindows.kts diff --git a/.teamcity/hosted/scheduled/build/TeamCityDockerImagesScheduledBuild.kts b/.teamcity/hosted/scheduled/build/TeamCityDockerImagesScheduledBuild.kts new file mode 100644 index 000000000..43e26b152 --- /dev/null +++ b/.teamcity/hosted/scheduled/build/TeamCityDockerImagesScheduledBuild.kts @@ -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 = "+:" + withPendingChangesOnly = false + } + } + + dependencies { + arrayOf( + TeamCityScheduledImageBuildWindows.TeamCityScheduledImageBuildWindows, + TeamCityScheduledImageBuildLinux.TeamCityScheduledImageBuildLinux + ).forEach { + snapshot(it) { + onDependencyFailure = FailureAction.ADD_PROBLEM + onDependencyCancel = FailureAction.CANCEL + } + } + } +}) diff --git a/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts new file mode 100644 index 000000000..b6fae41db --- /dev/null +++ b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildLinux.kts @@ -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) + } + + // - + val targetImages: HashMap = 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") + } +}) diff --git a/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildWindows.kts b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildWindows.kts new file mode 100644 index 000000000..47d1a1658 --- /dev/null +++ b/.teamcity/hosted/scheduled/build/TeamCityScheduledImageBuildWindows.kts @@ -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) + } + + // - + val targetImages: HashMap = 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") + } +}) diff --git a/.teamcity/settings.kts b/.teamcity/settings.kts index a06452e61..74c2c99c5 100644 --- a/.teamcity/settings.kts +++ b/.teamcity/settings.kts @@ -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" @@ -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")