diff --git a/CHANGELOG.md b/CHANGELOG.md index 3599bd9..9a16fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [1.0.4] - 2023-02-07 + +### Fixed + +- Don't add extra trailing slash if already present in `fromRegisty` or `toRegistry` +- Clarify error message with label defined with both `--label` and `--labels` +- Create parent directory for tar-image if not existing +- Trim whitespace around labels and env-variables + ## [1.0.3] - 2022-02-06 ### Improvement diff --git a/package.json b/package.json index 8da7acd..5d7da8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "doqr", - "version": "1.0.3", + "version": "1.0.4", "description": "Build node.js docker images without docker", "main": "./lib/cli.js", "scripts": { diff --git a/src/cli.ts b/src/cli.ts index 1f631e6..55a3f03 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -55,12 +55,12 @@ function setKeyValue(target: Record, keyValue: string) { const cliLabels = {} as Record; program.on("option:label", (ops: string) => { - setKeyValue(cliLabels, ops); + setKeyValue(cliLabels, ops.trim()); }); const cliEnv = {} as Record; program.on("option:env", (ops: string) => { - setKeyValue(cliEnv, ops); + setKeyValue(cliEnv, ops.trim()); }); const cliOptions = Object.entries(possibleArgs) @@ -97,17 +97,17 @@ Object.keys(configFromFile).forEach((k) => { }); const labelsOpt: Record = {}; -cliOptions.labels?.split(",")?.forEach((x: string) => setKeyValue(labelsOpt, x)); +cliOptions.labels?.split(",")?.forEach((x: string) => setKeyValue(labelsOpt, x.trim())); Object.keys(labelsOpt) .filter((l) => Object.keys(cliLabels).includes(l)) .forEach((l) => { - exitWithErrorIf(true, `Label ${l} specified both with --label and --label`); + exitWithErrorIf(true, `Label ${l} specified both with --labels and --label`); }); const labels = { ...configFromFile.labels, ...labelsOpt, ...cliLabels }; //Let cli arguments override file const envOpt: Record = {}; -cliOptions.envs?.split(",")?.forEach((x: string) => setKeyValue(envOpt, x)); +cliOptions.envs?.split(",")?.forEach((x: string) => setKeyValue(envOpt, x.trim())); Object.keys(envOpt) .filter((l) => Object.keys(cliEnv).includes(l)) .forEach((l) => { @@ -186,8 +186,8 @@ exitWithErrorIf( "A token must be given when uploading to docker hub", ); -if (options.toRegistry && options.toRegistry.substring(-1) != "/") options.toRegistry += "/"; -if (options.fromRegistry && options.fromRegistry.substring(-1) != "/") options.fromRegistry += "/"; +if (options.toRegistry && !options.toRegistry.endsWith("/")) options.toRegistry += "/"; +if (options.fromRegistry && !options.fromRegistry.endsWith("/")) options.fromRegistry += "/"; if (!options.fromRegistry && !options.fromImage?.split(":")?.[0]?.includes("/")) { options.fromImage = "library/" + options.fromImage; diff --git a/src/tarExporter.ts b/src/tarExporter.ts index 3aa86c9..7dc0aa8 100644 --- a/src/tarExporter.ts +++ b/src/tarExporter.ts @@ -14,6 +14,9 @@ const tarDefaultConfig = { async function saveToTar(fromdir: string, tmpdir: string, toPath: string, repoTags: string[], options: Options) { logger.info("Creating " + toPath + " ..."); + const targetFolder = path.dirname(toPath); + await fs.access(targetFolder).catch(async () => await fs.mkdir(targetFolder, {recursive: true})); + const manifestFile = path.join(fromdir, "manifest.json"); const manifest = (await fse.readJson(manifestFile)) as Manifest; const configFile = path.join(fromdir, manifest.config.digest.split(":")[1] + ".json");