Publish docker images to ghcr.io (#5311)

This commit is contained in:
Louis Lam 2024-11-05 20:26:26 +08:00 committed by GitHub
parent 5864c6dd88
commit 5bcde56a0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 26 deletions

View File

@ -6,14 +6,13 @@ import {
checkDocker, checkDocker,
checkTagExists, checkTagExists,
checkVersionFormat, checkVersionFormat,
dryRun, getRepoNames,
getRepoName,
pressAnyKey, pressAnyKey,
execSync, uploadArtifacts, execSync, uploadArtifacts,
} from "./lib.mjs"; } from "./lib.mjs";
import semver from "semver"; import semver from "semver";
const repoName = getRepoName(); const repoNames = getRepoNames();
const version = process.env.RELEASE_BETA_VERSION; const version = process.env.RELEASE_BETA_VERSION;
const githubToken = process.env.RELEASE_GITHUB_TOKEN; const githubToken = process.env.RELEASE_GITHUB_TOKEN;
@ -39,7 +38,7 @@ if (semverIdentifier[0] !== "beta") {
checkDocker(); checkDocker();
// Check if the tag exists // Check if the tag exists
await checkTagExists(repoName, version); await checkTagExists(repoNames, version);
// node extra/beta/update-version.js // node extra/beta/update-version.js
execSync("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(); buildDist();
// Build slim image (rootless) // 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) // Build full image (rootless)
buildImage(repoName, [ "beta-rootless", ver(version, "rootless") ], "rootless"); buildImage(repoNames, [ "beta-rootless", ver(version, "rootless") ], "rootless");
// Build slim image // 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 // Build full image
buildImage(repoName, [ "beta", version ], "release"); buildImage(repoNames, [ "beta", version ], "release");
await pressAnyKey(); await pressAnyKey();

View File

@ -6,11 +6,11 @@ import {
checkDocker, checkDocker,
checkTagExists, checkTagExists,
checkVersionFormat, checkVersionFormat,
getRepoName, getRepoNames,
pressAnyKey, execSync, uploadArtifacts pressAnyKey, execSync, uploadArtifacts
} from "./lib.mjs"; } from "./lib.mjs";
const repoName = getRepoName(); const repoNames = getRepoNames();
const version = process.env.RELEASE_VERSION; const version = process.env.RELEASE_VERSION;
const githubToken = process.env.RELEASE_GITHUB_TOKEN; const githubToken = process.env.RELEASE_GITHUB_TOKEN;
@ -28,7 +28,7 @@ checkVersionFormat(version);
checkDocker(); checkDocker();
// Check if the tag exists // Check if the tag exists
await checkTagExists(repoName, version); await checkTagExists(repoNames, version);
// node extra/beta/update-version.js // node extra/beta/update-version.js
execSync("node extra/update-version.js"); execSync("node extra/update-version.js");
@ -37,16 +37,16 @@ execSync("node extra/update-version.js");
buildDist(); buildDist();
// Build slim image (rootless) // 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) // Build full image (rootless)
buildImage(repoName, [ "2-rootless", ver(version, "rootless") ], "rootless"); buildImage(repoNames, [ "2-rootless", ver(version, "rootless") ], "rootless");
// Build slim image // 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 // Build full image
buildImage(repoName, [ "next", "2", version ], "release"); buildImage(repoNames, [ "next", "2", version ], "release");
await pressAnyKey(); await pressAnyKey();

View File

@ -24,8 +24,15 @@ export function checkDocker() {
/** /**
* Get Docker Hub repository name * Get Docker Hub repository name
*/ */
export function getRepoName() { export function getRepoNames() {
return process.env.RELEASE_REPO_NAME || "louislam/uptime-kuma"; 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 * 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[]} tags Docker image tags
* @param {string} target Dockerfile's target name * @param {string} target Dockerfile's target name
* @param {string} buildArgs Docker build args * @param {string} buildArgs Docker build args
@ -50,7 +57,7 @@ export function buildDist() {
* @param {string} platform Build platform * @param {string} platform Build platform
* @returns {void} * @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 = [ let args = [
"buildx", "buildx",
"build", "build",
@ -60,9 +67,11 @@ export function buildImage(repoName, tags, target, buildArgs = "", dockerfile =
platform, platform,
]; ];
// Add tags for (let repoName of repoNames) {
for (let tag of tags) { // Add tags
args.push("-t", `${repoName}:${tag}`); for (let tag of tags) {
args.push("-t", `${repoName}:${tag}`);
}
} }
args = [ args = [

View File

@ -1,7 +1,7 @@
import { buildDist, buildImage, checkDocker, getRepoName } from "./lib.mjs"; import { buildDist, buildImage, checkDocker, getRepoNames } from "./lib.mjs";
// Docker Hub repository name // Docker Hub repository name
const repoName = getRepoName(); const repoNames = getRepoNames();
// Check if docker is running // Check if docker is running
checkDocker(); checkDocker();
@ -10,7 +10,7 @@ checkDocker();
buildDist(); buildDist();
// Build full image (rootless) // Build full image (rootless)
buildImage(repoName, [ "nightly2-rootless" ], "nightly-rootless"); buildImage(repoNames, [ "nightly2-rootless" ], "nightly-rootless");
// Build full image // Build full image
buildImage(repoName, [ "nightly2" ], "nightly"); buildImage(repoNames, [ "nightly2" ], "nightly");