Skip to content

Commit

Permalink
Merge pull request #20 from StatensPensjonskasse/hotfix/fixes
Browse files Browse the repository at this point in the history
Hotfix/fixes
  • Loading branch information
eoftedal authored Feb 27, 2023
2 parents 2ab5a57 + e25b198 commit 52399c2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 7 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ function setKeyValue(target: Record<string, string>, keyValue: string) {

const cliLabels = {} as Record<string, string>;
program.on("option:label", (ops: string) => {
setKeyValue(cliLabels, ops);
setKeyValue(cliLabels, ops.trim());
});

const cliEnv = {} as Record<string, string>;
program.on("option:env", (ops: string) => {
setKeyValue(cliEnv, ops);
setKeyValue(cliEnv, ops.trim());
});

const cliOptions = Object.entries(possibleArgs)
Expand Down Expand Up @@ -97,17 +97,17 @@ Object.keys(configFromFile).forEach((k) => {
});

const labelsOpt: Record<string, string> = {};
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<string, string> = {};
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) => {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/tarExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 52399c2

Please sign in to comment.