Revised Docker image build process.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { pathToFileURL } = require('url');
|
||||
const { parseArgs } = require('util');
|
||||
|
||||
function execCommand(command, description) {
|
||||
@@ -31,20 +33,27 @@ function getContainerTool() {
|
||||
}
|
||||
}
|
||||
|
||||
function getVersion() {
|
||||
try {
|
||||
// Try to get version from git tag
|
||||
const gitTag = execSync('git tag --points-at HEAD', { encoding: 'utf8' }).trim();
|
||||
if (gitTag) {
|
||||
return { version: gitTag.replace(/^v/, ''), isRelease: true };
|
||||
}
|
||||
} catch (error) {
|
||||
// Git command failed, ignore
|
||||
async function generateVersionFile() {
|
||||
const versionModuleUrl = pathToFileURL(path.join(__dirname, 'version.mjs')).href;
|
||||
const { generateVersionFile: generate } = await import(versionModuleUrl);
|
||||
const versionFilePath = path.join(__dirname, '..', 'src', 'version.js');
|
||||
generate(versionFilePath);
|
||||
return versionFilePath;
|
||||
}
|
||||
|
||||
function readVersionFile(versionFilePath) {
|
||||
const contents = fs.readFileSync(versionFilePath, 'utf8');
|
||||
const versionMatch = contents.match(/export const VERSION = '([^']+)';/);
|
||||
const releaseMatch = contents.match(/export const IS_RELEASE = (true|false);/);
|
||||
|
||||
if (!versionMatch || !releaseMatch) {
|
||||
throw new Error(`Could not parse version file at ${versionFilePath}`);
|
||||
}
|
||||
|
||||
// Development build - use package.json version with -dev suffix
|
||||
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||
return { version: `${packageJson.version}-dev`, isRelease: false };
|
||||
return {
|
||||
version: versionMatch[1],
|
||||
isRelease: releaseMatch[1] === 'true'
|
||||
};
|
||||
}
|
||||
|
||||
function getHostArchitecture() {
|
||||
@@ -77,7 +86,7 @@ Examples:
|
||||
build-image.js -h # Show help`);
|
||||
}
|
||||
|
||||
function main() {
|
||||
async function main() {
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
help: {
|
||||
@@ -105,7 +114,8 @@ function main() {
|
||||
}
|
||||
|
||||
const containerTool = getContainerTool();
|
||||
const { version, isRelease } = getVersion();
|
||||
const versionFilePath = await generateVersionFile();
|
||||
const { version, isRelease } = readVersionFile(versionFilePath);
|
||||
|
||||
let architectures;
|
||||
if (values['all-arch']) {
|
||||
@@ -160,5 +170,8 @@ function main() {
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
main().catch((error) => {
|
||||
console.error(`Error: ${error.message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user