From 0818f634dc310ecbbe9d18bcf67ed9f9318b6314 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Mon, 2 Feb 2026 07:46:39 +0100 Subject: [PATCH] Fixed failing build. --- Dockerfile | 5 +++- package.json | 2 +- scripts/build-image.mjs | 24 +++++++++++------ scripts/version.mjs | 60 ++++++++++++++++++++++++++++++----------- 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index c645369..d6f7a34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,9 @@ ARG IS_RELEASE="false" # Set working directory WORKDIR /app +# Install git for version generation +RUN apk add --no-cache git + # Copy package files COPY package*.json ./ @@ -53,4 +56,4 @@ ENV LISTEN_ADDR=0.0.0.0 ENV LISTEN_PORT=3000 # Start the integrated server -ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./entrypoint.sh"] diff --git a/package.json b/package.json index d378ccc..cb239ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jmespath-playground", - "version": "1.4.2", + "version": "1.4.3", "description": "A React-based web application for testing JMESPath expressions against JSON data", "main": "index.js", "scripts": { diff --git a/scripts/build-image.mjs b/scripts/build-image.mjs index 906a63e..9bd3378 100755 --- a/scripts/build-image.mjs +++ b/scripts/build-image.mjs @@ -108,6 +108,7 @@ Usage: Options: --all-arch Build for both arm64 and amd64 (default: build for host architecture only) --arch Target architecture (arm64 or amd64). Can be specified multiple times. + --registry Image registry (default: docker.io). Can also set JMESPATH_REGISTRY. --help, -h Show this help message and exit Examples: @@ -115,6 +116,7 @@ Examples: build-image.mjs --all-arch # Builds for both arm64 and amd64 build-image.mjs --arch arm64 # Builds for arm64 only build-image.mjs --arch arm64 --arch amd64 # Explicitly specify both + build-image.mjs --registry docker.io # Use Docker Hub registry explicitly build-image.mjs -h # Show help`); } @@ -134,6 +136,10 @@ async function main() { type: 'string', multiple: true, description: 'Target architecture (arm64 or amd64)' + }, + registry: { + type: 'string', + description: 'Image registry (default: docker.io)' } }, strict: true, @@ -173,14 +179,16 @@ async function main() { console.log(`Target architectures: ${architectures.join(', ')}`); // Build container image + const registry = values.registry || process.env.JMESPATH_REGISTRY || 'docker.io'; + const imageName = `${registry.replace(/\/$/, '')}/skoszewski/jmespath-playground`; const tags = isRelease ? [ - `-t skoszewski/jmespath-playground:${version}`, - `-t skoszewski/jmespath-playground:latest` + `-t ${imageName}:${version}`, + `-t ${imageName}:latest` ].join(' ') : [ - `-t skoszewski/jmespath-playground:dev`, - `-t skoszewski/jmespath-playground:latest` + `-t ${imageName}:dev`, + `-t ${imageName}:latest` ].join(' '); const archFlags = architectures.map(arch => `--arch ${arch}`).join(' '); @@ -200,15 +208,15 @@ async function main() { if (isRelease) { console.log(`\nTo run the container:`); - console.log(` ${containerTool} run --arch arm64 --name jmespathpg -p 3000:3000 skoszewski/jmespath-playground:${version}`); + console.log(` ${containerTool} run --arch arm64 --name jmespathpg -p 3000:3000 ${imageName}:${version}`); if (containerTool === 'docker') { console.log(`\nTo push to Docker Hub:`); - console.log(` docker push skoszewski/jmespath-playground:${version}`); - console.log(` docker push skoszewski/jmespath-playground:latest`); + console.log(` docker push ${imageName}:${version}`); + console.log(` docker push ${imageName}:latest`); } } else { console.log(`\nTo run the container:`); - console.log(` ${containerTool} run --arch arm64 --name jmespathpg -p 3000:3000 skoszewski/jmespath-playground:dev`); + console.log(` ${containerTool} run --arch arm64 --name jmespathpg -p 3000:3000 ${imageName}:dev`); } } diff --git a/scripts/version.mjs b/scripts/version.mjs index 7248940..ec1e453 100644 --- a/scripts/version.mjs +++ b/scripts/version.mjs @@ -2,6 +2,24 @@ import { readFileSync, write, writeFileSync } from "fs"; import { execSync } from "child_process"; import semver from "semver"; +export function isGitAvailable() { + try { + execSync("git --version", { stdio: "ignore" }); + return true; + } catch (e) { + return false; + } +} + +export function isGitRepo() { + try { + execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" }); + return true; + } catch (e) { + return false; + } +} + export function getGitVersion() { let rawGitVersion; let gitVersion; @@ -28,26 +46,38 @@ export function getGitVersion() { } export function generateVersionFile(versionFilePath) { + if (!isGitAvailable()) { + throw new Error("Git is required to generate version info."); + } + // Read package.json version const packageVersion = JSON.parse( readFileSync("package.json", { encoding: "utf-8" }), ).version; - // Get version from git repository - const gitVersion = getGitVersion(); - const gitBaseVersion = semver.coerce(gitVersion)?.version; + let gitVersion = packageVersion; + let gitBaseVersion = packageVersion; + let isRelease = true; - // if git returned malformed version, throw error - if (!gitBaseVersion || gitBaseVersion === "0.0.0") { - throw new Error( - "Cannot determine git version. Make sure the script is run in a git repository with tags.", - ); - } + if (isGitRepo()) { + // Get version from git repository + gitVersion = getGitVersion(); + gitBaseVersion = semver.coerce(gitVersion)?.version; - // Compare git version with package.json version - if (semver.neq(gitBaseVersion, packageVersion)) { - throw new Error( - `Version mismatch: package.json version is ${packageVersion}, but git version is ${gitBaseVersion}`, - ); + // if git returned malformed version, throw error + if (!gitBaseVersion || gitBaseVersion === "0.0.0") { + throw new Error( + "Cannot determine git version. Make sure the script is run in a git repository with tags.", + ); + } + + // Compare git version with package.json version + if (semver.neq(gitBaseVersion, packageVersion)) { + throw new Error( + `Version mismatch: package.json version is ${packageVersion}, but git version is ${gitBaseVersion}`, + ); + } + + isRelease = gitVersion === packageVersion; } // Generate version file @@ -58,7 +88,7 @@ export function generateVersionFile(versionFilePath) { // Generated at: ${buildDate} export const VERSION = '${packageVersion}'; -export const IS_RELEASE = ${gitVersion === packageVersion}; +export const IS_RELEASE = ${isRelease}; export const BUILD_TIME = '${buildDate}'; `, );