From 01fcddaa1fc7010006b502999fab84ea854d5cec Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Thu, 27 Oct 2022 18:13:00 +0100 Subject: [PATCH] (#3020) Adds Kotlin Docker Builds These builds should produce the Chocolatey docker images. Require TeamCity to have a Docker agent pool, as well as the update to the agent_pool parameter to allow projects to be added to multiple pools. --- .teamcity/pom.xml | 104 --------------- .teamcity/settings.kts | 296 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 294 insertions(+), 106 deletions(-) delete mode 100644 .teamcity/pom.xml diff --git a/.teamcity/pom.xml b/.teamcity/pom.xml deleted file mode 100644 index d51e03b8ae..0000000000 --- a/.teamcity/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - Chocolatey Config DSL Script - Chocolatey - Chocolatey_dsl - 1.0-SNAPSHOT - - - org.jetbrains.teamcity - configs-dsl-kotlin-parent - 1.0-SNAPSHOT - - - - - jetbrains-all - https://download.jetbrains.com/teamcity-repository - - true - - - - teamcity-server - https://teamcityserver/app/dsl-plugins-repository - - true - - - - - - - JetBrains - https://download.jetbrains.com/teamcity-repository - - - - - ${basedir} - - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - - - - - compile - process-sources - - compile - - - - test-compile - process-test-sources - - test-compile - - - - - - org.jetbrains.teamcity - teamcity-configs-maven-plugin - ${teamcity.dsl.version} - - kotlin - target/generated-configs - - - - - - - - org.jetbrains.teamcity - configs-dsl-kotlin - ${teamcity.dsl.version} - compile - - - org.jetbrains.teamcity - configs-dsl-kotlin-plugins - 1.0-SNAPSHOT - pom - compile - - - org.jetbrains.kotlin - kotlin-stdlib-jdk8 - ${kotlin.version} - compile - - - org.jetbrains.kotlin - kotlin-script-runtime - ${kotlin.version} - compile - - - \ No newline at end of file diff --git a/.teamcity/settings.kts b/.teamcity/settings.kts index f835207c87..37b7c98ea8 100644 --- a/.teamcity/settings.kts +++ b/.teamcity/settings.kts @@ -1,14 +1,19 @@ import jetbrains.buildServer.configs.kotlin.v2019_2.* +import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.DockerCommandStep +import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.dockerCommand import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.script import jetbrains.buildServer.configs.kotlin.v2019_2.buildSteps.powerShell +import jetbrains.buildServer.configs.kotlin.v2019_2.Dependencies import jetbrains.buildServer.configs.kotlin.v2019_2.buildFeatures.pullRequests import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs +import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.finishBuildTrigger import jetbrains.buildServer.configs.kotlin.v2019_2.vcs.GitVcsRoot -version = "2021.2" - project { buildType(Chocolatey) + buildType(ChocolateyDockerWin) + buildType(ChocolateyPosix) + buildType(ChocolateyDockerManifest) } object Chocolatey : BuildType({ @@ -74,4 +79,291 @@ object Chocolatey : BuildType({ } } } +}) + +object ChocolateyDockerWin : BuildType({ + id = AbsoluteId("ChocolateyDockerWin") + name = "Docker (Windows)" + + params { + // TeamCity has suggested "${Chocolatey.depParamRefs.buildNumber}" + param("env.CHOCOLATEY_VERSION", "%dep.Chocolatey.build.number%") + } + + vcs { + root(DslContext.settingsRoot) + } + + steps { + step { + name = "Login Docker" + type = "DockerLogin" + } + + dockerCommand { + name = "Build Docker Image" + commandType = build { + source = file { + path = "docker/Dockerfile.windows" + } + contextDir = "." + platform = DockerCommandStep.ImagePlatform.Windows + namesAndTags = "chocolatey/choco:latest-windows" + } + } + + // powerShell { + // name = "Test Docker Image" + // scriptMode = script { + // content = """ + // docker run --rm chocolatey/choco:latest-windows choco.exe --version + // exit ${'$'}LastExitCode + // """.trimIndent() + // } + // } + + dockerCommand { + name = "Push Docker Image" + commandType = push { + namesAndTags = "chocolatey/choco:latest-windows" + removeImageAfterPush = false + } + } + + dockerCommand { + name = "Tag Docker Image with Version" + commandType = other { + subCommand = "tag" + commandArgs = "chocolatey/choco:latest-windows chocolatey/choco:v%env.CHOCOLATEY_VERSION%-windows" + } + } + + dockerCommand { + name = "Push Versioned Tag" + commandType = push { + namesAndTags = "chocolatey/choco:v%env.CHOCOLATEY_VERSION%-windows" + } + } + } + + triggers { + finishBuildTrigger { + buildType = "Chocolatey" + successfulOnly = true + branchFilter = """ + +:release/* + +:hotfix/* + +:tags/* + """.trimIndent() + } + } + + dependencies { + dependency(AbsoluteId("Chocolatey")) { + snapshot { + onDependencyFailure = FailureAction.FAIL_TO_START + synchronizeRevisions = false + } + + artifacts { + artifactRules = "chocolatey.%env.CHOCOLATEY_VERSION%.nupkg=>%system.teamcity.build.checkoutDir%\\code_drop\\Packages\\Chocolatey" + } + } + } +}) + +object ChocolateyPosix : BuildType({ + id = AbsoluteId("ChocolateyPosix") + name = "Docker (Linux)" + + params { + param("env.CHOCOLATEY_VERSION", "%dep.Chocolatey.build.number%") + param("env.CHOCOLATEY_OFFICIAL_KEY", "%system.teamcity.build.checkoutDir%/chocolatey.official.snk") + password("env.GITHUB_PAT", "%system.GitHubPAT%", display = ParameterDisplay.HIDDEN, readOnly = true) + param("env.vcsroot.branch", "%vcsroot.branch%") + param("env.Git_Branch", "%teamcity.build.vcs.branch.Chocolatey_ChocolateyVcsRoot%") + param("teamcity.git.fetchAllHeads", "true") + } + + vcs { + root(DslContext.settingsRoot) + } + + artifactRules = """ + chocolatey.*.tar.gz + """.trimIndent() + + steps { + step { + name = "Load Key" + type = "StrongNameKeyLinux" + } + + step { + name = "Login Docker" + type = "DockerLogin" + } + + script { + name = "Install Prerequisites" + scriptContent = """ + sudo amazon-linux-extras install mono + """.trimIndent() + } + + script { + name = "Build Chocolatey" + scriptContent = """ + ./build.official.sh + cd ./code_drop/chocolatey/console + tar -czvf ../../../chocolatey.v%env.CHOCOLATEY_VERSION%.tar.gz . + """.trimIndent() + } + + // Please note that this method will need to be changed to some form of CD after we lock agents down + script { + name = "Publish TarGz to GitHub Release" + scriptContent = """ + curl \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer %env.GITHUB_PAT%"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Content-Type: application/octet-stream" \ + https://uploads.github.com/repos/chocolatey/choco/releases/%env.CHOCOLATEY_VERSION%/assets?name=chocolatey.v%env.CHOCOLATEY_VERSION%.tar.gz \ + --data-binary "@chocolatey.v%env.CHOCOLATEY_VERSION%.tar.gz" + """.trimIndent() + } + + dockerCommand { + name = "Build Docker Image" + commandType = build { + source = file { + path = "docker/Dockerfile.linux" + } + contextDir = "." + platform = DockerCommandStep.ImagePlatform.Linux + namesAndTags = "chocolatey/choco:latest-linux" + commandArgs = "--build-arg buildscript=build.official.sh" + } + } + + dockerCommand { + name = "Push Docker Image" + commandType = push { + namesAndTags = "chocolatey/choco:latest-linux" + removeImageAfterPush = false + } + } + + dockerCommand { + name = "Tag Docker Image with Version" + commandType = other { + subCommand = "tag" + commandArgs = "chocolatey/choco:latest-linux chocolatey/choco:v%env.CHOCOLATEY_VERSION%-linux" + } + } + + dockerCommand { + name = "Push Versioned Tag" + commandType = push { + namesAndTags = "chocolatey/choco:v%env.CHOCOLATEY_VERSION%-linux" + } + } + } + + triggers { + finishBuildTrigger { + buildType = "Chocolatey" + successfulOnly = true + branchFilter = """ + +:release/* + +:hotfix/* + +:tags/* + """.trimIndent() + } + } + + dependencies { + snapshot(AbsoluteId("Chocolatey")) { + onDependencyFailure = FailureAction.FAIL_TO_START + synchronizeRevisions = false + } + } +}) + +object ChocolateyDockerManifest : BuildType({ + id = AbsoluteId("ChocolateyDockerManifest") + name = "Docker Manifest" + + params { + param("env.CHOCOLATEY_VERSION", "%dep.Chocolatey.build.number%") + } + + vcs { + root(DslContext.settingsRoot) + } + + steps { + step { + name = "Login Docker" + type = "DockerLogin" + } + + dockerCommand { + name = "Create Combined Manifest" + commandType = other { + subCommand = "manifest" + commandArgs = "create chocolatey/choco:latest chocolatey/choco:latest-linux chocolatey/choco:latest-windows" + } + } + + dockerCommand { + name = "Push Combined Manifest" + commandType = other { + subCommand = "manifest" + commandArgs = "push chocolatey/choco:latest" + } + } + + dockerCommand { + name = "Create Versioned Manifest" + commandType = other { + subCommand = "manifest" + commandArgs = "create chocolatey/choco:v%env.CHOCOLATEY_VERSION% chocolatey/choco:v%env.CHOCOLATEY_VERSION%-linux chocolatey/choco:v%env.CHOCOLATEY_VERSION%-windows" + } + } + + dockerCommand { + name = "Push Versioned Manifest" + commandType = other { + subCommand = "manifest" + commandArgs = "push chocolatey/choco:v%env.CHOCOLATEY_VERSION%" + } + } + + } + + triggers { + finishBuildTrigger { + buildType = "Chocolatey" + successfulOnly = true + branchFilter = """ + +:release/* + +:hotfix/* + +:tags/* + """.trimIndent() + } + } + + dependencies { + snapshot(AbsoluteId("ChocolateyDockerWin")) { + onDependencyFailure = FailureAction.FAIL_TO_START + synchronizeRevisions = false + } + snapshot(AbsoluteId("ChocolateyPosix")) { + onDependencyFailure = FailureAction.FAIL_TO_START + synchronizeRevisions = false + } + } }) \ No newline at end of file