From 5fb46cdbfd19b579afba3f0c31bd4816ab43fcf2 Mon Sep 17 00:00:00 2001 From: Prabhu Subramanian Date: Sun, 19 Nov 2023 22:47:30 +0000 Subject: [PATCH] DOCKER_CONFIG env variable support Signed-off-by: Prabhu Subramanian --- docker.js | 12 +++++++++--- docs/ENV.md | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docker.js b/docker.js index 0211fc2c7..73e6b02d5 100644 --- a/docker.js +++ b/docker.js @@ -104,9 +104,12 @@ const getDefaultOptions = () => { mutableDefaults: true }; // Support for private registry - if (existsSync(join(homedir(), ".docker", "config.json"))) { + if ( + process.env.DOCKER_CONFIG || + existsSync(join(homedir(), ".docker", "config.json")) + ) { const configData = readFileSync( - join(homedir(), ".docker", "config.json"), + process.env.DOCKER_CONFIG || join(homedir(), ".docker", "config.json"), "utf-8" ); if (configData) { @@ -154,7 +157,10 @@ const getDefaultOptions = () => { const authPayload = { username: process.env.DOCKER_USER, email: process.env.DOCKER_EMAIL, - serveraddress: process.env.DOCKER_SERVER_ADDRESS + serveraddress: process.env.DOCKER_SERVER_ADDRESS.replace( + "http://", + "" + ).replace("https://", "") }; if (process.env.DOCKER_USER === "") { authPayload.IdentityToken = process.env.DOCKER_PASSWORD; diff --git a/docs/ENV.md b/docs/ENV.md index 1e0b82abb..bd45542e2 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -38,6 +38,7 @@ The following environment variables are available to configure the bom generatio | ASTGEN_IGNORE_DIRS | Comma separated list of directories to ignore while analyzing using babel. The environment variable is also used by atom and astgen. | | ASTGEN_IGNORE_FILE_PATTERN | Ignore regex to use | | PYPI_URL | Override pypi url. Default: https://pypi.org/pypi/ | +| DOCKER_CONFIG | Alternative path to $HOME/.docker/config.json | | DOCKER_AUTH_CONFIG | Perform docker login prior to invoking cdxgen. The file $HOME/.docker/config.json would be automatically read if available. Base64 encoded (json) with credentials: `{'username': string, 'password': string, 'email': string, 'serveraddress' : string}`. Alternatively, set the below 4 environment variables. | | DOCKER_USER | Docker username | | DOCKER_PASSWORD | Docker password |