From 171956673cac4440420984d9e298f72a91168579 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Fri, 3 Jun 2022 06:52:06 -0700 Subject: [PATCH] Handle empty registry property in input --- packages/docker/src/dockerCommands/container.ts | 13 +++++++------ packages/docker/src/hooks/run-container-step.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/docker/src/dockerCommands/container.ts b/packages/docker/src/dockerCommands/container.ts index 0a4904e..f35ddf8 100644 --- a/packages/docker/src/dockerCommands/container.ts +++ b/packages/docker/src/dockerCommands/container.ts @@ -3,6 +3,7 @@ import * as fs from 'fs' import { ContainerInfo, JobContainerInfo, + Registry, RunContainerStepArgs, ServiceContainerInfo, StepContainerInfo @@ -266,19 +267,19 @@ export async function containerPorts(id: string): Promise { return portMappings.split('\n') } -export async function registryLogin(args): Promise { - if (!args.registry) { +export async function registryLogin(registry?: Registry): Promise { + if (!registry) { return '' } const credentials = { - username: args.registry.username, - password: args.registry.password + username: registry.username, + password: registry.password } const configLocation = `${env.RUNNER_TEMP}/.docker_${uuidv4()}` fs.mkdirSync(configLocation) try { - await dockerLogin(configLocation, args.registry.serverUrl, credentials) + await dockerLogin(configLocation, registry.serverUrl, credentials) } catch (error) { fs.rmdirSync(configLocation, { recursive: true }) throw error @@ -296,7 +297,7 @@ export async function registryLogout(configLocation: string): Promise { async function dockerLogin( configLocation: string, registry: string, - credentials: { username: string; password: string } + credentials: { username?: string; password?: string } ): Promise { const credentialsArgs = credentials.username && credentials.password diff --git a/packages/docker/src/hooks/run-container-step.ts b/packages/docker/src/hooks/run-container-step.ts index 02555dc..76cdec9 100644 --- a/packages/docker/src/hooks/run-container-step.ts +++ b/packages/docker/src/hooks/run-container-step.ts @@ -15,7 +15,7 @@ export async function runContainerStep( ): Promise { const tag = generateBuildTag() // for docker build if (args.image) { - const configLocation = await registryLogin(args) + const configLocation = await registryLogin(args.registry) try { await containerPull(args.image, configLocation) } finally {