Enhance version management and Docker build system

- Add Docker build args for proper version detection in containers
- Update build.sh script with smart version detection for Docker builds
- Add --message option to new-version.js for custom commit messages
- Fix Docker builds showing incorrect '-dev' suffix for release builds
- Improve versioning workflow with comprehensive --check analysis
This commit is contained in:
2026-01-21 21:48:45 +01:00
parent 4d6efe791b
commit d027459678
4 changed files with 65 additions and 15 deletions

View File

@@ -1,6 +1,10 @@
# Build stage
FROM node:24-alpine AS builder
# Accept build arguments for version info
ARG VERSION=""
ARG IS_RELEASE="false"
# Set working directory
WORKDIR /app
@@ -16,6 +20,17 @@ COPY public/ ./public/
COPY scripts/ ./scripts/
COPY server.js ./server.js
# Generate version.js if version info provided, otherwise run normal build
RUN if [ -n "$VERSION" ]; then \
echo "// Auto-generated version file - do not edit manually" > src/version.js && \
echo "// Generated at: $(date -Iseconds)" >> src/version.js && \
echo "" >> src/version.js && \
echo "export const VERSION = '$VERSION';" >> src/version.js && \
echo "export const IS_RELEASE = $IS_RELEASE;" >> src/version.js && \
echo "export const BUILD_TIME = '$(date -Iseconds)';" >> src/version.js && \
echo "📝 Generated version.js with VERSION=$VERSION, IS_RELEASE=$IS_RELEASE"; \
fi
# Build the application
RUN npm run build

View File

@@ -1,6 +1,6 @@
{
"name": "jmespath-playground",
"version": "1.1.2",
"version": "1.1.3",
"description": "A React-based web application for testing JMESPath expressions against JSON data",
"main": "index.js",
"scripts": {

View File

@@ -33,7 +33,31 @@ npm run build
# Optional container build with Docker
if command -v docker &> /dev/null; then
echo "🐳 Building Docker container (optional)..."
docker build -t jmespath-playground .
# Determine version information for Docker build
VERSION=$(git tag --points-at HEAD 2>/dev/null | sed 's/^v//' | head -n 1)
if [ -n "$VERSION" ]; then
# We're at a tagged commit - release build
echo "📦 Building release version: $VERSION"
docker build \
--build-arg VERSION="$VERSION" \
--build-arg IS_RELEASE="true" \
-t jmespath-playground:$VERSION \
-t jmespath-playground:latest .
echo "✅ Built Docker images: jmespath-playground:$VERSION, jmespath-playground:latest"
else
# Development build
PACKAGE_VERSION=$(grep '"version"' package.json | cut -d'"' -f4)
DEV_VERSION="${PACKAGE_VERSION}-dev"
echo "📦 Building development version: $DEV_VERSION"
docker build \
--build-arg VERSION="$DEV_VERSION" \
--build-arg IS_RELEASE="false" \
-t jmespath-playground:dev \
-t jmespath-playground:latest .
echo "✅ Built Docker images: jmespath-playground:dev, jmespath-playground:latest"
fi
else
echo "💡 Docker not found. Container build is optional."
echo " Install Docker if you want to build containers."
@@ -42,8 +66,13 @@ fi
echo "✅ Build completed successfully!"
echo ""
echo "To run the application:"
echo " npm run serve # Serve production build locally"
echo " docker run -p 3000:3000 jmespath-playground # Run container (if built)"
echo " npm run server # Run integrated server locally"
if command -v docker &> /dev/null; then
echo " docker run -p 3000:3000 jmespath-playground # Run with Docker"
VERSION=$(git tag --points-at HEAD 2>/dev/null | sed 's/^v//' | head -n 1)
if [ -n "$VERSION" ]; then
echo " docker run -p 3000:3000 jmespath-playground:$VERSION # Run release container"
else
echo " docker run -p 3000:3000 jmespath-playground:dev # Run dev container"
fi
echo " docker run -p 3000:3000 jmespath-playground:latest # Run latest container"
fi

View File

@@ -4,18 +4,20 @@ const fs = require('fs');
const { execSync } = require('child_process');
function showUsage() {
console.log('Usage: node scripts/new-version.js <version> [--force]');
console.log('Usage: node scripts/new-version.js <version> [--force] [-m|--message "commit message"]');
console.log(' node scripts/new-version.js --check <version>');
console.log('');
console.log('Creates a new version by tagging the current commit.');
console.log('');
console.log('Options:');
console.log(' --force Force version creation even with dirty repo or package.json mismatch');
console.log(' --check Analyze repository status and report what would happen for specified version');
console.log(' --force Force version creation even with dirty repo or package.json mismatch');
console.log(' --check Analyze repository status and report what would happen for specified version');
console.log(' -m, --message TEXT Custom commit message (only used when commit is needed)');
console.log('');
console.log('Example:');
console.log(' node scripts/new-version.js 1.2.0');
console.log(' node scripts/new-version.js 1.2.0 --force');
console.log(' node scripts/new-version.js 1.2.0 -m "Add new feature XYZ"');
console.log(' node scripts/new-version.js --check 1.3.0');
}
@@ -178,10 +180,17 @@ function main() {
const isCheck = args.includes('--check');
const isForce = args.includes('--force');
// Parse custom commit message
let customMessage = null;
const messageIndex = args.findIndex(arg => arg === '-m' || arg === '--message');
if (messageIndex !== -1 && messageIndex + 1 < args.length) {
customMessage = args[messageIndex + 1];
}
let newVersion;
if (isCheck) {
// For --check, version is required
newVersion = args.find(arg => !arg.startsWith('--'));
newVersion = args.find(arg => !arg.startsWith('--') && arg !== '-m' && arg !== customMessage);
if (!newVersion) {
console.error('Error: Version argument required for --check');
showUsage();
@@ -189,11 +198,8 @@ function main() {
}
} else {
// For normal operation, version is required
newVersion = args[0];
if (!newVersion || newVersion.startsWith('-')) {
console.error('Error: Version argument required');
showUsage();
process.exit(1);
newVersion = args.find(arg => !arg.startsWith('--') && arg !== '-m' && arg !== customMessage);
if (!newVersion) {
}
}
@@ -268,7 +274,7 @@ function main() {
execSync('git add .', { stdio: 'inherit' });
// Commit
const commitMessage = needsPackageUpdate ? `Version ${newVersion}` : `Prepare for version ${newVersion}`;
const commitMessage = customMessage || (needsPackageUpdate ? `Version ${newVersion}` : `Prepare for version ${newVersion}`);
execSync(`git commit -m "${commitMessage}"`, { stdio: 'inherit' });
console.log(`✅ Committed changes`);
} else {