From 913e9b2934417ac58f3ef13902472b907697a7c9 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Wed, 7 Aug 2024 11:34:44 +0200 Subject: [PATCH] Don't fail on missing `~/.docker` dir This is a follow-up to 8828a2343efc255ad6682f4cd9db89ad021b6de9 / #39 --- src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 38a35af..fc52510 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,8 @@ import { Inputs } from "./generated/inputs-outputs"; let podmanPath: string | undefined; let registry: string; -const dockerConfigPath = path.join(os.homedir(), ".docker", "config.json"); +const dockerConfigDir = path.join(os.homedir(), ".docker"); +const dockerConfigPath = path.join(dockerConfigDir, "config.json"); async function getPodmanPath(): Promise { if (podmanPath == null) { @@ -91,7 +92,8 @@ async function run(): Promise { dockerConfig.auths[registry] = generatedAuth; - await fs.writeFile(dockerConfigPath, JSON.stringify(dockerConfig, undefined, 8), "utf-8"); + await fs.mkdir(dockerConfigDir, { recursive: true }) + .then(() => fs.writeFile(dockerConfigPath, JSON.stringify(dockerConfig, undefined, 8), "utf-8")); } async function registryLogout(): Promise {