From 48101e710ea207e0bc3c8a7b7c060f2f317b7ad1 Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 07:05:27 +0100 Subject: [PATCH 01/10] Add github test case --- tests/githubtest/customContent/test.txt | 3 +++ tests/githubtest/test.sh | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/githubtest/customContent/test.txt create mode 100644 tests/githubtest/test.sh diff --git a/tests/githubtest/customContent/test.txt b/tests/githubtest/customContent/test.txt new file mode 100644 index 0000000..ce7fc18 --- /dev/null +++ b/tests/githubtest/customContent/test.txt @@ -0,0 +1,3 @@ +Hello world + +This is an integration test \ No newline at end of file diff --git a/tests/githubtest/test.sh b/tests/githubtest/test.sh new file mode 100644 index 0000000..f0ac686 --- /dev/null +++ b/tests/githubtest/test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e +if [[ -z "$GITHUB_TOKEN" ]]; then + echo "ERROR: GITHUB_TOKEN not set (see https://github.com/settings/tokens/new?scopes=write:packages for running locally)" + exit 1 +fi + +printf "* Running containerify to pull from and push result to the local containerify test registry...\n" +../../lib/cli.js --verbose --fromImage docker-mirror/node:alpine --registry https://ghcr.io/v2/ --toImage eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" From a24cdb1d4e021a3951d89b36032ca37acecef8c6 Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 09:21:10 +0100 Subject: [PATCH 02/10] Some more stuff --- tests/githubtest/customContent/test.txt | 3 --- tests/githubtest/test.sh | 10 ---------- 2 files changed, 13 deletions(-) delete mode 100644 tests/githubtest/customContent/test.txt delete mode 100644 tests/githubtest/test.sh diff --git a/tests/githubtest/customContent/test.txt b/tests/githubtest/customContent/test.txt deleted file mode 100644 index ce7fc18..0000000 --- a/tests/githubtest/customContent/test.txt +++ /dev/null @@ -1,3 +0,0 @@ -Hello world - -This is an integration test \ No newline at end of file diff --git a/tests/githubtest/test.sh b/tests/githubtest/test.sh deleted file mode 100644 index f0ac686..0000000 --- a/tests/githubtest/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -set -e -if [[ -z "$GITHUB_TOKEN" ]]; then - echo "ERROR: GITHUB_TOKEN not set (see https://github.com/settings/tokens/new?scopes=write:packages for running locally)" - exit 1 -fi - -printf "* Running containerify to pull from and push result to the local containerify test registry...\n" -../../lib/cli.js --verbose --fromImage docker-mirror/node:alpine --registry https://ghcr.io/v2/ --toImage eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" From e8a5a054345f7478852b4bee2fee081d4118a67f Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 17:41:49 +0100 Subject: [PATCH 03/10] Support --to and --from as shorthands for specifying both registry and image --- src/cli.ts | 36 +++++++-- src/registry.ts | 74 ++++++++----------- src/types.ts | 2 + tests/external-registries/github-ghcr-test.sh | 2 +- 4 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 5baeb9a..dc344b2 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -6,7 +6,7 @@ import * as path from "path"; import * as fse from "fs-extra"; import * as fs from "fs"; -import { createRegistry, createDockerRegistry } from "./registry"; +import { DEFAULT_DOCKER_REGISTRY, createRegistry, processToken, parseFullImageUrl } from "./registry"; import appLayerCreator from "./appLayerCreator"; import dockerExporter from "./dockerExporter"; import tarExporter from "./tarExporter"; @@ -18,6 +18,8 @@ import { ensureEmptyDir } from "./fileutil"; import { VERSION } from "./version"; const possibleArgs = { + "--from ": "Shorthand to specify fromRegistry and fromImage in one argument", + "--to ": "Shorthand to specify toRegistry and toImage in one argument", "--fromImage ": "Required: Image name of base image - [path/]image:tag", "--toImage ": "Required: Image name of target image - [path/]image:tag", "--folder ": "Required: Base folder of node application (contains package.json)", @@ -181,13 +183,31 @@ function exitWithErrorIf(check: boolean, error: string) { if (options.verbose) logger.enableDebug(); exitWithErrorIf(!!options.registry && !!options.fromRegistry, "Do not set both --registry and --fromRegistry"); +exitWithErrorIf(!!options.from && !!options.fromRegistry, "Do not set both --from and --fromRegistry"); +exitWithErrorIf(!!options.registry && !!options.from, "Do not set both --registry and --from"); + exitWithErrorIf(!!options.registry && !!options.toRegistry, "Do not set both --registry and --toRegistry"); +exitWithErrorIf(!!options.to && !!options.toRegistry, "Do not set both --toRegistry and --to"); +exitWithErrorIf(!!options.registry && !!options.to, "Do not set both --registry and --to"); +console.log(options); +console.log("MOADHAO", options.from, options.to); +if (options.from) { + const { registry, image } = parseFullImageUrl(options.from); + options.fromRegistry = registry; + options.fromImage = image; +} +if (options.to) { + const { registry, image } = parseFullImageUrl(options.to); + options.toRegistry = registry; + options.toImage = image; +} + exitWithErrorIf(!!options.token && !!options.fromToken, "Do not set both --token and --fromToken"); exitWithErrorIf(!!options.token && !!options.toToken, "Do not set both --token and --toToken"); exitWithErrorIf( !!options.doCrossMount && options.toRegistry != options.fromRegistry, - "Cross mounting only works if fromRegistry and toRegistry are the same", + `Cross mounting only works if fromRegistry and toRegistry are the same (${options.fromRegistry} != ${options.toRegistry})`, ); if (options.setTimeStamp) { @@ -263,10 +283,12 @@ async function run(options: Options) { const fromdir = await ensureEmptyDir(path.join(tmpdir, "from")); const todir = await ensureEmptyDir(path.join(tmpdir, "to")); const allowInsecure = options.allowInsecureRegistries ? InsecureRegistrySupport.YES : InsecureRegistrySupport.NO; - - const fromRegistry = options.fromRegistry - ? createRegistry(options.fromRegistry, options.fromToken ?? "", allowInsecure) - : createDockerRegistry(allowInsecure, options.fromToken); + const fromRegistryUrl = options.fromRegistry ?? DEFAULT_DOCKER_REGISTRY; + const fromRegistry = createRegistry( + fromRegistryUrl, + await processToken(fromRegistryUrl, allowInsecure, options.fromImage, options.fromToken), + allowInsecure, + ); const originalManifest = await fromRegistry.download( options.fromImage, fromdir, @@ -290,7 +312,7 @@ async function run(options: Options) { if (options.toRegistry) { const toRegistry = createRegistry( options.toRegistry, - options.toToken ?? "", + await processToken(options.toRegistry, allowInsecure, options.toImage, options.toToken), allowInsecure, options.optimisticToRegistryCheck, ); diff --git a/src/registry.ts b/src/registry.ts index 29e7caa..a379329 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -231,12 +231,6 @@ function uploadContent( }); } -function prepareToken(token: string) { - if (token.startsWith("Basic ")) return token; - if (token.startsWith("ghp_")) return "Bearer " + Buffer.from(token).toString("base64"); - return "Bearer " + token; -} - type Registry = { download: (imageStr: string, folder: string, preferredPlatform: Platform, cacheFolder?: string) => Promise; upload: ( @@ -259,7 +253,7 @@ export function createRegistry( allowInsecure: InsecureRegistrySupport, optimisticToRegistryCheck = false, ): Registry { - const auth = prepareToken(token); + const auth = token; async function exists(image: Image, layer: Layer) { const url = `${registryBaseUrl}${image.path}/blobs/${layer.digest}`; @@ -505,49 +499,39 @@ export function createRegistry( }; } -export function createDockerRegistry(allowInsecure: InsecureRegistrySupport, auth?: string): Registry { - const registryBaseUrl = "https://registry-1.docker.io/v2/"; +export const DEFAULT_DOCKER_REGISTRY = "https://registry-1.docker.io/v2/"; + +export function parseFullImageUrl(imageStr: string): { registry: string; image: string } { + const [registry, ...rest] = imageStr.split("/"); + if (registry == "docker.io") { + return { + registry: DEFAULT_DOCKER_REGISTRY, + image: rest.join("/"), + }; + } + return { + registry: `https://${registry}/v2/`, + image: rest.join("/"), + }; +} - async function getToken(image: Image) { +export async function processToken( + registryBaseUrl: string, + allowInsecure: InsecureRegistrySupport, + imagePath: string, + token?: string, +): Promise { + const { hostname } = URL.parse(registryBaseUrl); + if (hostname?.endsWith("docker.io") && !token) { const resp = await dlJson<{ token: string }>( - `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image.path}:pull`, + `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${imagePath}:pull`, {}, allowInsecure, ); return resp.token; } - - async function download( - imageStr: string, - folder: string, - platform: Platform, - cacheFolder?: string, - ): Promise { - const image = parseImage(imageStr); - if (!auth) auth = await getToken(image); - return await createRegistry(registryBaseUrl, auth, allowInsecure).download(imageStr, folder, platform, cacheFolder); - } - - async function upload( - imageStr: string, - folder: string, - doCrossMount: boolean, - originalManifest: Manifest, - originalRepository: string, - ) { - if (!auth) throw new Error("Need auth token to upload to Docker"); - await createRegistry(registryBaseUrl, auth, allowInsecure).upload( - imageStr, - folder, - doCrossMount, - originalManifest, - originalRepository, - ); - } - - return { - download: download, - upload: upload, - registryBaseUrl, - }; + if (!token) throw new Error("Need auth token to upload to " + registryBaseUrl); + if (token.startsWith("Basic ")) return token; + if (token.startsWith("ghp_")) return "Bearer " + Buffer.from(token).toString("base64"); + return "Bearer " + token; } diff --git a/src/types.ts b/src/types.ts index 9a4e05c..fbfc632 100644 --- a/src/types.ts +++ b/src/types.ts @@ -66,6 +66,8 @@ export type HistoryLine = { }; export type Options = { + from?: string; + to?: string; fromImage: string; toImage: string; folder: string; diff --git a/tests/external-registries/github-ghcr-test.sh b/tests/external-registries/github-ghcr-test.sh index c72b846..0bc1840 100755 --- a/tests/external-registries/github-ghcr-test.sh +++ b/tests/external-registries/github-ghcr-test.sh @@ -7,4 +7,4 @@ if [[ -z "$GITHUB_TOKEN" ]]; then fi printf "* Running containerify to pull from and push result to gchr.io ...\n" -../../lib/cli.js --verbose --fromImage docker-mirror/node:alpine --registry https://ghcr.io/v2/ --toImage eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" +../../lib/cli.js --verbose --doCrossMount true --from ghcr.io/docker-mirror/node:alpine --to ghcr.io/eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" From cad49a17bf3e24fdc27a22214c2b540a654b06eb Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 17:43:59 +0100 Subject: [PATCH 04/10] Update readme --- README.md | 4 +++- src/cli.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d4fce9e..28f48ae 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,13 @@ This will take the `nginx:alpine` image, and copy the files from `./dist/` into Usage: containerify [options] Options: + --from Optional: Shorthand to specify fromRegistry and fromImage in one argument + --to Optional: Shorthand to specify toRegistry and toImage in one argument --fromImage Required: Image name of base image - [path/]image:tag --toImage Required: Image name of target image - [path/]image:tag --folder Required: Base folder of node application (contains package.json) --file Optional: Name of configuration file (defaults to containerify.json if found on path) - --doCrossMount Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false) + --doCrossMount Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false) --fromRegistry Optional: URL of registry to pull base image from - Default: https://registry-1.docker.io/v2/ --fromToken Optional: Authentication token for from registry --toRegistry Optional: URL of registry to push base image to - Default: https://registry-1.docker.io/v2/ diff --git a/src/cli.ts b/src/cli.ts index dc344b2..a97c7ba 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,14 +18,14 @@ import { ensureEmptyDir } from "./fileutil"; import { VERSION } from "./version"; const possibleArgs = { - "--from ": "Shorthand to specify fromRegistry and fromImage in one argument", - "--to ": "Shorthand to specify toRegistry and toImage in one argument", + "--from ": "Optional: Shorthand to specify fromRegistry and fromImage in one argument", + "--to ": "Optional: Shorthand to specify toRegistry and toImage in one argument", "--fromImage ": "Required: Image name of base image - [path/]image:tag", "--toImage ": "Required: Image name of target image - [path/]image:tag", "--folder ": "Required: Base folder of node application (contains package.json)", "--file ": "Optional: Name of configuration file (defaults to containerify.json if found on path)", "--doCrossMount ": - "Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false)", + "Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false)", "--fromRegistry ": "Optional: URL of registry to pull base image from - Default: https://registry-1.docker.io/v2/", "--fromToken ": "Optional: Authentication token for from registry", From 332b3de60f26a8882d01f3ed213e772be621a237 Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 21:40:30 +0100 Subject: [PATCH 05/10] Removing debug, fixing typos and script --- src/cli.ts | 2 -- src/registry.ts | 23 ++++++----------------- src/types.ts | 11 +++++++++++ tests/localtest/test.sh | 4 ++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index a97c7ba..e2d9b32 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -189,8 +189,6 @@ exitWithErrorIf(!!options.registry && !!options.from, "Do not set both --registr exitWithErrorIf(!!options.registry && !!options.toRegistry, "Do not set both --registry and --toRegistry"); exitWithErrorIf(!!options.to && !!options.toRegistry, "Do not set both --toRegistry and --to"); exitWithErrorIf(!!options.registry && !!options.to, "Do not set both --registry and --to"); -console.log(options); -console.log("MOADHAO", options.from, options.to); if (options.from) { const { registry, image } = parseFullImageUrl(options.from); options.fromRegistry = registry; diff --git a/src/registry.ts b/src/registry.ts index a379329..c5423bf 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -18,6 +18,7 @@ import { Manifest, PartialManifestConfig, Platform, + Registry, } from "./types"; import { DockerV2, OCI } from "./MIMETypes"; import { getLayerTypeFileEnding } from "./utils"; @@ -231,18 +232,6 @@ function uploadContent( }); } -type Registry = { - download: (imageStr: string, folder: string, preferredPlatform: Platform, cacheFolder?: string) => Promise; - upload: ( - imageStr: string, - folder: string, - doCrossMount: boolean, - originalManifest: Manifest, - originalRepository: string, - ) => Promise; - registryBaseUrl: string; -}; - type Mount = { mount: string; from: string }; type UploadURL = { uploadUrl: string }; type UploadURLorMounted = UploadURL | { mountSuccess: true }; @@ -268,10 +257,10 @@ export function createRegistry( async function getUploadUrl( image: Image, - mountParamters: Mount | undefined = undefined, + mountParameters: Mount | undefined = undefined, ): Promise { return new Promise((resolve, reject) => { - const parameters = new URLSearchParams(mountParamters); + const parameters = new URLSearchParams(mountParameters); const url = `${registryBaseUrl}${image.path}/blobs/uploads/${parameters.size > 0 ? "?" + parameters : ""}`; const options: https.RequestOptions = URL.parse(url); options.method = "POST"; @@ -291,11 +280,11 @@ export function createRegistry( } } reject("Missing location for 202"); - } else if (mountParamters && res.statusCode == 201) { + } else if (mountParameters && res.statusCode == 201) { const returnedDigest = res.headers["docker-content-digest"]; - if (returnedDigest && returnedDigest != mountParamters.mount) { + if (returnedDigest && returnedDigest != mountParameters.mount) { reject( - `ERROR: Layer mounted with wrong digest: Expected ${mountParamters.mount} but got ${returnedDigest}`, + `ERROR: Layer mounted with wrong digest: Expected ${mountParameters.mount} but got ${returnedDigest}`, ); } resolve({ mountSuccess: true }); diff --git a/src/types.ts b/src/types.ts index fbfc632..9df27c3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -107,3 +107,14 @@ export enum InsecureRegistrySupport { NO, YES, } +export type Registry = { + download: (imageStr: string, folder: string, preferredPlatform: Platform, cacheFolder?: string) => Promise; + upload: ( + imageStr: string, + folder: string, + doCrossMount: boolean, + originalManifest: Manifest, + originalRepository: string, + ) => Promise; + registryBaseUrl: string; +}; diff --git a/tests/localtest/test.sh b/tests/localtest/test.sh index f47e567..5e672de 100755 --- a/tests/localtest/test.sh +++ b/tests/localtest/test.sh @@ -47,9 +47,13 @@ docker pull node:alpine &> /dev/null printf "* Pushing base image to local containerify test registry...\n" docker tag node:alpine localhost:5443/node > /dev/null +echo -n $TESTPASSWORD | docker login -u $TESTUSER --password-stdin localhost:5443 docker push localhost:5443/node > /dev/null printf "* Running containerify to pull from and push result to the local containerify test registry...\n" +cd ../integration/app +npm install +cd ../../localtest ../../lib/cli.js --fromImage node --doCrossMount true --registry https://localhost:5443/v2/ --toImage containerify-integration-test:localtest --folder ../integration/app --setTimeStamp "2023-03-07T12:53:10.471Z" --allowInsecureRegistries --token "Basic $BASICAUTH" From b58fa8a955188585aa569a143021e21d40e66fc1 Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 22:02:19 +0100 Subject: [PATCH 06/10] Fixup stuff --- README.md | 2 +- src/cli.ts | 2 +- tests/external-registries/github-ghcr-test.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 28f48ae..4eae3f3 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Options: --toImage Required: Image name of target image - [path/]image:tag --folder Required: Base folder of node application (contains package.json) --file Optional: Name of configuration file (defaults to containerify.json if found on path) - --doCrossMount Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false) + --doCrossMount Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false) --fromRegistry Optional: URL of registry to pull base image from - Default: https://registry-1.docker.io/v2/ --fromToken Optional: Authentication token for from registry --toRegistry Optional: URL of registry to push base image to - Default: https://registry-1.docker.io/v2/ diff --git a/src/cli.ts b/src/cli.ts index e2d9b32..e2f0558 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -24,7 +24,7 @@ const possibleArgs = { "--toImage ": "Required: Image name of target image - [path/]image:tag", "--folder ": "Required: Base folder of node application (contains package.json)", "--file ": "Optional: Name of configuration file (defaults to containerify.json if found on path)", - "--doCrossMount ": + "--doCrossMount": "Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false)", "--fromRegistry ": "Optional: URL of registry to pull base image from - Default: https://registry-1.docker.io/v2/", diff --git a/tests/external-registries/github-ghcr-test.sh b/tests/external-registries/github-ghcr-test.sh index 0bc1840..618bb2d 100755 --- a/tests/external-registries/github-ghcr-test.sh +++ b/tests/external-registries/github-ghcr-test.sh @@ -7,4 +7,4 @@ if [[ -z "$GITHUB_TOKEN" ]]; then fi printf "* Running containerify to pull from and push result to gchr.io ...\n" -../../lib/cli.js --verbose --doCrossMount true --from ghcr.io/docker-mirror/node:alpine --to ghcr.io/eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" +../../lib/cli.js --verbose --doCrossMount --from ghcr.io/docker-mirror/node:alpine --to ghcr.io/eoftedal/containerify-integrationtest:latest --folder . --customContent customContent --setTimeStamp "2024-01-15T20:00:00.000Z" --token "$GITHUB_TOKEN" From ac377cd6a2a5d05e677cda4b0d658d061eec8d57 Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 22:07:58 +0100 Subject: [PATCH 07/10] Fix test --- src/registry.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/registry.ts b/src/registry.ts index c5423bf..96f6093 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -512,12 +512,13 @@ export async function processToken( ): Promise { const { hostname } = URL.parse(registryBaseUrl); if (hostname?.endsWith("docker.io") && !token) { + const image = parseImage(imagePath); const resp = await dlJson<{ token: string }>( - `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${imagePath}:pull`, + `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image.path}:pull`, {}, allowInsecure, ); - return resp.token; + return `Bearer ${resp.token}`; } if (!token) throw new Error("Need auth token to upload to " + registryBaseUrl); if (token.startsWith("Basic ")) return token; From 91a5830c9fa0309406403a26c2f04ee2a897febb Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 22:15:31 +0100 Subject: [PATCH 08/10] Fix CodeQL finding --- src/registry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registry.ts b/src/registry.ts index 96f6093..6ae7e9c 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -511,7 +511,7 @@ export async function processToken( token?: string, ): Promise { const { hostname } = URL.parse(registryBaseUrl); - if (hostname?.endsWith("docker.io") && !token) { + if (hostname?.endsWith(".docker.io") && !token) { const image = parseImage(imagePath); const resp = await dlJson<{ token: string }>( `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image.path}:pull`, From 89ce59bba243004a5c63986250876f3ab91a355c Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 22:21:25 +0100 Subject: [PATCH 09/10] Fix test --- tests/localtest/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/localtest/test.sh b/tests/localtest/test.sh index 5e672de..5ade410 100755 --- a/tests/localtest/test.sh +++ b/tests/localtest/test.sh @@ -54,7 +54,7 @@ printf "* Running containerify to pull from and push result to the local contain cd ../integration/app npm install cd ../../localtest -../../lib/cli.js --fromImage node --doCrossMount true --registry https://localhost:5443/v2/ --toImage containerify-integration-test:localtest --folder ../integration/app --setTimeStamp "2023-03-07T12:53:10.471Z" --allowInsecureRegistries --token "Basic $BASICAUTH" +../../lib/cli.js --fromImage node --doCrossMount --registry https://localhost:5443/v2/ --toImage containerify-integration-test:localtest --folder ../integration/app --setTimeStamp "2023-03-07T12:53:10.471Z" --allowInsecureRegistries --token "Basic $BASICAUTH" printf "\n* Pulling image from registry to local docker daemon...\n" From c6df6ac81b2399caf472ce0493d78d4b19a1e81d Mon Sep 17 00:00:00 2001 From: Erlend Oftedal Date: Tue, 16 Jan 2024 22:22:19 +0100 Subject: [PATCH 10/10] Move parsing line --- src/registry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registry.ts b/src/registry.ts index 6ae7e9c..e7cf1ff 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -511,8 +511,8 @@ export async function processToken( token?: string, ): Promise { const { hostname } = URL.parse(registryBaseUrl); + const image = parseImage(imagePath); if (hostname?.endsWith(".docker.io") && !token) { - const image = parseImage(imagePath); const resp = await dlJson<{ token: string }>( `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image.path}:pull`, {},