From 1472fcc712aa45d4a0571d69f43cff32de9894f7 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Mon, 24 Feb 2025 09:58:02 +0100 Subject: [PATCH] build(docker): use channel for computing docker tags (#34436) --- .releaserc.json | 4 ++-- tools/docker/bake.hcl | 23 +++++++++++++++++------ tools/prepare-release.ts | 1 + tools/publish-release.ts | 1 + tools/utils/docker.ts | 5 +++++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.releaserc.json b/.releaserc.json index d19e5f541f..81f2fd02f1 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -19,8 +19,8 @@ [ "@semantic-release/exec", { - "prepareCmd": "pnpm release:prepare --version=${nextRelease.version} --sha=${nextRelease.gitHead} --tries=3 --platform=linux/amd64,linux/arm64 --exit-on-error=true", - "publishCmd": "pnpm release:publish --version=${nextRelease.version} --sha=${nextRelease.gitHead} --platform=linux/amd64,linux/arm64 --exit-on-error=true" + "prepareCmd": "pnpm release:prepare --version=${nextRelease.version} --channel='${branch.channel ?? ''}' --sha=${nextRelease.gitHead} --tries=3 --platform=linux/amd64,linux/arm64 --exit-on-error=true", + "publishCmd": "pnpm release:publish --version=${nextRelease.version} --channel='${branch.channel ?? ''}' --sha=${nextRelease.gitHead} --platform=linux/amd64,linux/arm64 --exit-on-error=true" } ] ], diff --git a/tools/docker/bake.hcl b/tools/docker/bake.hcl index b57ec7f20e..d961ce1a94 100644 --- a/tools/docker/bake.hcl +++ b/tools/docker/bake.hcl @@ -13,6 +13,9 @@ variable "RENOVATE_MAJOR_VERSION" { variable "RENOVATE_MAJOR_MINOR_VERSION" { default = "" } +variable "CHANNEL" { + default = "" +} variable "APT_HTTP_PROXY" { default = "" @@ -62,8 +65,12 @@ target "slim" { # "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}", # ] tags = [ - "ghcr.io/${OWNER}/${FILE}", - "${FILE}/${FILE}", + notequal("", CHANNEL) + ? "ghcr.io/${OWNER}/${FILE}:${CHANNEL}" + : "ghcr.io/${OWNER}/${FILE}", + notequal("", CHANNEL) + ? "${FILE}/${FILE}:${CHANNEL}" + : "${FILE}/${FILE}", // GitHub versioned tags notequal("", RENOVATE_VERSION) ? "ghcr.io/${OWNER}/${FILE}:${RENOVATE_VERSION}": "", @@ -86,8 +93,8 @@ target "full" { # "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}-full", # ] tags = [ - "ghcr.io/${OWNER}/${FILE}:full", - "${FILE}/${FILE}:full", + notequal("", CHANNEL) ? "ghcr.io/${OWNER}/${FILE}:${CHANNEL}-full" : "ghcr.io/${OWNER}/${FILE}:full", + notequal("", CHANNEL) ? "${FILE}/${FILE}:${CHANNEL}-full" : "${FILE}/${FILE}:full", // GitHub versioned tags notequal("", RENOVATE_VERSION) ? "ghcr.io/${OWNER}/${FILE}:${RENOVATE_VERSION}-full": "", @@ -113,7 +120,9 @@ target "push-slim" { inherits = ["build-slim"] output = ["type=registry"] cache-to = [ - "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE},mode=max,image-manifest=true,ignore-error=true", + notequal("", CHANNEL) + ? "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}-${CHANNEL},mode=max,image-manifest=true,ignore-error=true" + : "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE},mode=max,image-manifest=true,ignore-error=true", ] } @@ -121,6 +130,8 @@ target "push-full" { inherits = ["build-full"] output = ["type=registry"] cache-to = [ - "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}-full,mode=max,image-manifest=true,ignore-error=true", + notequal("", CHANNEL) + ? "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}-${CHANNEL}-full,mode=max,image-manifest=true,ignore-error=true" + : "type=registry,ref=ghcr.io/${OWNER}/docker-build-cache:${FILE}-full,mode=max,image-manifest=true,ignore-error=true", ] } diff --git a/tools/prepare-release.ts b/tools/prepare-release.ts index 00ffaf60f9..18d7e129d0 100644 --- a/tools/prepare-release.ts +++ b/tools/prepare-release.ts @@ -15,6 +15,7 @@ const program = new Command('pnpm release:prepare') .description('Build docker images') .option('--platform <type>', 'docker platforms to build') .option('--version <version>', 'version to use as tag', parseVersion) + .option('--channel <channel>', 'channel to use as tag') .option('--sha <type>', 'git sha') .option('--tries <tries>', 'number of tries for docker build', parseInt) .option( diff --git a/tools/publish-release.ts b/tools/publish-release.ts index 590ef44aab..c16fcb591d 100644 --- a/tools/publish-release.ts +++ b/tools/publish-release.ts @@ -13,6 +13,7 @@ const program = new Command('pnpm release:prepare') .description('Build docker images') .option('--platform <type>', 'docker platforms to build') .option('--version <version>', 'version to use as tag', parseVersion) + .option('--channel <channel>', 'channel to use as tag') .option('--sha <type>', 'git sha') .option('--exit-on-error <boolean>', 'exit on docker error', (s) => s ? s !== 'false' : undefined, diff --git a/tools/utils/docker.ts b/tools/utils/docker.ts index c7869752f3..fbfa5d5390 100644 --- a/tools/utils/docker.ts +++ b/tools/utils/docker.ts @@ -27,6 +27,7 @@ export async function bake( delay?: string; exitOnError?: boolean; tries?: number; + channel?: string; }, ): Promise<MetaData | null> { if (opts.version) { @@ -38,6 +39,10 @@ export async function bake( } } + if (opts.channel) { + process.env.CHANNEL = opts.channel; + } + const metadataFile = path.join(await tmp, 'metadata.json'); const args = [ 'buildx', -- GitLab