mirror of
https://github.com/docker/login-action.git
synced 2025-04-27 17:16:35 +02:00
Handle Amazon ECR registries associated with other accounts
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
3b14bab101
commit
d3160f671f
4 changed files with 77 additions and 54 deletions
12
src/aws.ts
12
src/aws.ts
|
@ -45,15 +45,19 @@ export const parseCLIVersion = async (stdout: string): Promise<string> => {
|
|||
return semver.clean(matches[1]);
|
||||
};
|
||||
|
||||
export const getDockerLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
|
||||
export const getDockerLoginCmds = async (cliVersion: string, registry: string, region: string): Promise<string[]> => {
|
||||
let ecrCmd = (await isPubECR(registry)) ? 'ecr-public' : 'ecr';
|
||||
if (semver.satisfies(cliVersion, '>=2.0.0')) {
|
||||
return execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
|
||||
return `docker login --username AWS --password ${pwd} ${registry}`;
|
||||
return [`docker login --username AWS --password ${pwd} ${registry}`];
|
||||
});
|
||||
} else {
|
||||
return execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return dockerLoginCmd;
|
||||
let args: Array<string> = [ecrCmd, 'get-login', '--region', region, '--no-include-email'];
|
||||
if (process.env.AWS_ECR_REGISTRY_IDS) {
|
||||
args.push('--registry-ids', process.env.AWS_ECR_REGISTRY_IDS);
|
||||
}
|
||||
return execCLI(args).then(dockerLoginCmds => {
|
||||
return dockerLoginCmds.trim().split(`\n`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -55,13 +55,19 @@ export async function loginECR(registry: string, username: string, password: str
|
|||
process.env.AWS_SECRET_ACCESS_KEY = password || process.env.AWS_SECRET_ACCESS_KEY;
|
||||
|
||||
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
|
||||
const loginCmd = await aws.getDockerLoginCmd(cliVersion, registry, region);
|
||||
const loginCmds = await aws.getDockerLoginCmds(cliVersion, registry, region);
|
||||
|
||||
core.info(`🔑 Logging into ${registry}...`);
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
core.info('🎉 Login Succeeded!');
|
||||
loginCmds.forEach((loginCmd, index) => {
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
if (loginCmds.length > 1) {
|
||||
core.info(`🎉 Login Succeeded! (${index}/${loginCmds.length})`);
|
||||
} else {
|
||||
core.info('🎉 Login Succeeded!');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue