mirror of
https://github.com/docker/login-action.git
synced 2024-12-27 19:34:32 +08:00
Merge 087884b3d26e0ea9f5fac62cfefae4831c7b96dc into 7ca345011ac4304463197fac0e56eab1bc7e6af0
This commit is contained in:
commit
3891f5f1e9
@ -24,6 +24,10 @@ inputs:
|
|||||||
description: 'Log out from the Docker registry at the end of a job'
|
description: 'Log out from the Docker registry at the end of a job'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
required: false
|
required: false
|
||||||
|
attempts:
|
||||||
|
description: 'Number of attempts to try in case of server-side errors'
|
||||||
|
default: '1'
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
|
@ -6,6 +6,7 @@ export interface Inputs {
|
|||||||
password: string;
|
password: string;
|
||||||
ecr: string;
|
ecr: string;
|
||||||
logout: boolean;
|
logout: boolean;
|
||||||
|
attempts: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInputs(): Inputs {
|
export function getInputs(): Inputs {
|
||||||
@ -14,6 +15,7 @@ export function getInputs(): Inputs {
|
|||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
ecr: core.getInput('ecr'),
|
ecr: core.getInput('ecr'),
|
||||||
logout: core.getBooleanInput('logout')
|
logout: core.getBooleanInput('logout'),
|
||||||
|
attempts: Number.parseInt(core.getInput('attempts'))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ import * as core from '@actions/core';
|
|||||||
|
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||||
|
|
||||||
export async function login(registry: string, username: string, password: string, ecr: string): Promise<void> {
|
export async function login(registry: string, username: string, password: string, ecr: string, attempts: number): Promise<void> {
|
||||||
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
|
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
|
||||||
await loginECR(registry, username, password);
|
await loginECR(registry, username, password);
|
||||||
} else {
|
} else {
|
||||||
await loginStandard(registry, username, password);
|
await loginStandard(registry, username, password, attempts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ export async function logout(registry: string): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginStandard(registry: string, username: string, password: string): Promise<void> {
|
export async function loginStandard(registry: string, username: string, password: string, attempts: number): Promise<void> {
|
||||||
if (!username && !password) {
|
if (!username && !password) {
|
||||||
throw new Error('Username and password required');
|
throw new Error('Username and password required');
|
||||||
}
|
}
|
||||||
@ -41,16 +41,29 @@ export async function loginStandard(registry: string, username: string, password
|
|||||||
} else {
|
} else {
|
||||||
core.info(`Logging into Docker Hub...`);
|
core.info(`Logging into Docker Hub...`);
|
||||||
}
|
}
|
||||||
await Docker.getExecOutput(loginArgs, {
|
let attempt: number = 1
|
||||||
ignoreReturnCode: true,
|
let succeeded: boolean = false
|
||||||
silent: true,
|
for (let attempt = 1; (attempt <= attempts) && (!succeeded); attempt++) {
|
||||||
input: Buffer.from(password)
|
await Docker.getExecOutput(loginArgs, {
|
||||||
}).then(res => {
|
ignoreReturnCode: true,
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
silent: true,
|
||||||
throw new Error(res.stderr.trim());
|
input: Buffer.from(password)
|
||||||
|
}).then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
let isRetriable: boolean
|
||||||
|
isRetriable = res.stderr.trim().endsWith("502 Bad Gateway")
|
||||||
|
if (!isRetriable || (attempt >= attempts) {
|
||||||
|
throw new Error(res.stderr.trim());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.info(`Login Succeeded!`);
|
||||||
|
succeeded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if ((attempt < attempts) && !succeeded) {
|
||||||
|
await new Promise(r => setTimeout(r, 10000))
|
||||||
}
|
}
|
||||||
core.info(`Login Succeeded!`);
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginECR(registry: string, username: string, password: string): Promise<void> {
|
export async function loginECR(registry: string, username: string, password: string): Promise<void> {
|
||||||
|
@ -8,7 +8,7 @@ export async function main(): Promise<void> {
|
|||||||
const input: context.Inputs = context.getInputs();
|
const input: context.Inputs = context.getInputs();
|
||||||
stateHelper.setRegistry(input.registry);
|
stateHelper.setRegistry(input.registry);
|
||||||
stateHelper.setLogout(input.logout);
|
stateHelper.setLogout(input.logout);
|
||||||
await docker.login(input.registry, input.username, input.password, input.ecr);
|
await docker.login(input.registry, input.username, input.password, input.ecr, input.attempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function post(): Promise<void> {
|
async function post(): Promise<void> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user