From 5bcde56a0f98735dbe76b1e0c5f70556dfda39b7 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 5 Nov 2024 20:26:26 +0800 Subject: [PATCH] Publish docker images to ghcr.io (#5311) --- extra/release/beta.mjs | 15 +++++++-------- extra/release/final.mjs | 14 +++++++------- extra/release/lib.mjs | 23 ++++++++++++++++------- extra/release/nightly.mjs | 8 ++++---- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/extra/release/beta.mjs b/extra/release/beta.mjs index ec3be7c6..7ea13b9b 100644 --- a/extra/release/beta.mjs +++ b/extra/release/beta.mjs @@ -6,14 +6,13 @@ import { checkDocker, checkTagExists, checkVersionFormat, - dryRun, - getRepoName, + getRepoNames, pressAnyKey, execSync, uploadArtifacts, } from "./lib.mjs"; import semver from "semver"; -const repoName = getRepoName(); +const repoNames = getRepoNames(); const version = process.env.RELEASE_BETA_VERSION; const githubToken = process.env.RELEASE_GITHUB_TOKEN; @@ -39,7 +38,7 @@ if (semverIdentifier[0] !== "beta") { checkDocker(); // Check if the tag exists -await checkTagExists(repoName, version); +await checkTagExists(repoNames, version); // node extra/beta/update-version.js execSync("node ./extra/beta/update-version.js"); @@ -48,16 +47,16 @@ execSync("node ./extra/beta/update-version.js"); buildDist(); // Build slim image (rootless) -buildImage(repoName, [ "beta-slim-rootless", ver(version, "slim-rootless") ], "rootless", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); +buildImage(repoNames, [ "beta-slim-rootless", ver(version, "slim-rootless") ], "rootless", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); // Build full image (rootless) -buildImage(repoName, [ "beta-rootless", ver(version, "rootless") ], "rootless"); +buildImage(repoNames, [ "beta-rootless", ver(version, "rootless") ], "rootless"); // Build slim image -buildImage(repoName, [ "beta-slim", ver(version, "slim") ], "release", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); +buildImage(repoNames, [ "beta-slim", ver(version, "slim") ], "release", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); // Build full image -buildImage(repoName, [ "beta", version ], "release"); +buildImage(repoNames, [ "beta", version ], "release"); await pressAnyKey(); diff --git a/extra/release/final.mjs b/extra/release/final.mjs index b4435064..bf0ec2b0 100644 --- a/extra/release/final.mjs +++ b/extra/release/final.mjs @@ -6,11 +6,11 @@ import { checkDocker, checkTagExists, checkVersionFormat, - getRepoName, + getRepoNames, pressAnyKey, execSync, uploadArtifacts } from "./lib.mjs"; -const repoName = getRepoName(); +const repoNames = getRepoNames(); const version = process.env.RELEASE_VERSION; const githubToken = process.env.RELEASE_GITHUB_TOKEN; @@ -28,7 +28,7 @@ checkVersionFormat(version); checkDocker(); // Check if the tag exists -await checkTagExists(repoName, version); +await checkTagExists(repoNames, version); // node extra/beta/update-version.js execSync("node extra/update-version.js"); @@ -37,16 +37,16 @@ execSync("node extra/update-version.js"); buildDist(); // Build slim image (rootless) -buildImage(repoName, [ "2-slim-rootless", ver(version, "slim-rootless") ], "rootless", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); +buildImage(repoNames, [ "2-slim-rootless", ver(version, "slim-rootless") ], "rootless", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); // Build full image (rootless) -buildImage(repoName, [ "2-rootless", ver(version, "rootless") ], "rootless"); +buildImage(repoNames, [ "2-rootless", ver(version, "rootless") ], "rootless"); // Build slim image -buildImage(repoName, [ "next-slim", "2-slim", ver(version, "slim") ], "release", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); +buildImage(repoNames, [ "next-slim", "2-slim", ver(version, "slim") ], "release", "BASE_IMAGE=louislam/uptime-kuma:base2-slim"); // Build full image -buildImage(repoName, [ "next", "2", version ], "release"); +buildImage(repoNames, [ "next", "2", version ], "release"); await pressAnyKey(); diff --git a/extra/release/lib.mjs b/extra/release/lib.mjs index 49391900..cd06cd37 100644 --- a/extra/release/lib.mjs +++ b/extra/release/lib.mjs @@ -24,8 +24,15 @@ export function checkDocker() { /** * Get Docker Hub repository name */ -export function getRepoName() { - return process.env.RELEASE_REPO_NAME || "louislam/uptime-kuma"; +export function getRepoNames() { + if (process.env.RELEASE_REPO_NAMES) { + // Split by comma + return process.env.RELEASE_REPO_NAMES.split(",").map((name) => name.trim()); + } + return [ + "louislam/uptime-kuma", + "ghcr.io/louislam/uptime-kuma", + ]; } /** @@ -42,7 +49,7 @@ export function buildDist() { /** * Build docker image and push to Docker Hub - * @param {string} repoName Docker Hub repository name + * @param {string[]} repoNames Docker Hub repository names * @param {string[]} tags Docker image tags * @param {string} target Dockerfile's target name * @param {string} buildArgs Docker build args @@ -50,7 +57,7 @@ export function buildDist() { * @param {string} platform Build platform * @returns {void} */ -export function buildImage(repoName, tags, target, buildArgs = "", dockerfile = "docker/dockerfile", platform = "linux/amd64,linux/arm64,linux/arm/v7") { +export function buildImage(repoNames, tags, target, buildArgs = "", dockerfile = "docker/dockerfile", platform = "linux/amd64,linux/arm64,linux/arm/v7") { let args = [ "buildx", "build", @@ -60,9 +67,11 @@ export function buildImage(repoName, tags, target, buildArgs = "", dockerfile = platform, ]; - // Add tags - for (let tag of tags) { - args.push("-t", `${repoName}:${tag}`); + for (let repoName of repoNames) { + // Add tags + for (let tag of tags) { + args.push("-t", `${repoName}:${tag}`); + } } args = [ diff --git a/extra/release/nightly.mjs b/extra/release/nightly.mjs index c6641bad..54951ac4 100644 --- a/extra/release/nightly.mjs +++ b/extra/release/nightly.mjs @@ -1,7 +1,7 @@ -import { buildDist, buildImage, checkDocker, getRepoName } from "./lib.mjs"; +import { buildDist, buildImage, checkDocker, getRepoNames } from "./lib.mjs"; // Docker Hub repository name -const repoName = getRepoName(); +const repoNames = getRepoNames(); // Check if docker is running checkDocker(); @@ -10,7 +10,7 @@ checkDocker(); buildDist(); // Build full image (rootless) -buildImage(repoName, [ "nightly2-rootless" ], "nightly-rootless"); +buildImage(repoNames, [ "nightly2-rootless" ], "nightly-rootless"); // Build full image -buildImage(repoName, [ "nightly2" ], "nightly"); +buildImage(repoNames, [ "nightly2" ], "nightly");