mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-15 01:06:43 +00:00
Handle empty registry property in input
This commit is contained in:
@@ -3,6 +3,7 @@ import * as fs from 'fs'
|
|||||||
import {
|
import {
|
||||||
ContainerInfo,
|
ContainerInfo,
|
||||||
JobContainerInfo,
|
JobContainerInfo,
|
||||||
|
Registry,
|
||||||
RunContainerStepArgs,
|
RunContainerStepArgs,
|
||||||
ServiceContainerInfo,
|
ServiceContainerInfo,
|
||||||
StepContainerInfo
|
StepContainerInfo
|
||||||
@@ -266,19 +267,19 @@ export async function containerPorts(id: string): Promise<string[]> {
|
|||||||
return portMappings.split('\n')
|
return portMappings.split('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registryLogin(args): Promise<string> {
|
export async function registryLogin(registry?: Registry): Promise<string> {
|
||||||
if (!args.registry) {
|
if (!registry) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
const credentials = {
|
const credentials = {
|
||||||
username: args.registry.username,
|
username: registry.username,
|
||||||
password: args.registry.password
|
password: registry.password
|
||||||
}
|
}
|
||||||
|
|
||||||
const configLocation = `${env.RUNNER_TEMP}/.docker_${uuidv4()}`
|
const configLocation = `${env.RUNNER_TEMP}/.docker_${uuidv4()}`
|
||||||
fs.mkdirSync(configLocation)
|
fs.mkdirSync(configLocation)
|
||||||
try {
|
try {
|
||||||
await dockerLogin(configLocation, args.registry.serverUrl, credentials)
|
await dockerLogin(configLocation, registry.serverUrl, credentials)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
fs.rmdirSync(configLocation, { recursive: true })
|
fs.rmdirSync(configLocation, { recursive: true })
|
||||||
throw error
|
throw error
|
||||||
@@ -296,7 +297,7 @@ export async function registryLogout(configLocation: string): Promise<void> {
|
|||||||
async function dockerLogin(
|
async function dockerLogin(
|
||||||
configLocation: string,
|
configLocation: string,
|
||||||
registry: string,
|
registry: string,
|
||||||
credentials: { username: string; password: string }
|
credentials: { username?: string; password?: string }
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const credentialsArgs =
|
const credentialsArgs =
|
||||||
credentials.username && credentials.password
|
credentials.username && credentials.password
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function runContainerStep(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const tag = generateBuildTag() // for docker build
|
const tag = generateBuildTag() // for docker build
|
||||||
if (args.image) {
|
if (args.image) {
|
||||||
const configLocation = await registryLogin(args)
|
const configLocation = await registryLogin(args.registry)
|
||||||
try {
|
try {
|
||||||
await containerPull(args.image, configLocation)
|
await containerPull(args.image, configLocation)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user