Skip to content

Commit

Permalink
Publish docker images to ghcr.io (#5311)
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam authored Nov 5, 2024
1 parent 5864c6d commit 5bcde56
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
15 changes: 7 additions & 8 deletions extra/release/beta.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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();

Expand Down
14 changes: 7 additions & 7 deletions extra/release/final.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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();

Expand Down
23 changes: 16 additions & 7 deletions extra/release/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];
}

/**
Expand All @@ -42,15 +49,15 @@ 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
* @param {string} dockerfile Path to Dockerfile
* @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",
Expand All @@ -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 = [
Expand Down
8 changes: 4 additions & 4 deletions extra/release/nightly.mjs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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");

0 comments on commit 5bcde56

Please sign in to comment.