mirror of
https://github.com/docker/login-action.git
synced 2025-04-19 01:26:45 +00:00
Add support for public ECR
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
7c9afe235c
commit
1e75de0e0e
6 changed files with 121 additions and 23 deletions
14
src/aws.ts
14
src/aws.ts
|
@ -3,10 +3,17 @@ import * as io from '@actions/io';
|
|||
import * as execm from './exec';
|
||||
|
||||
export const isECR = async (registry: string): Promise<boolean> => {
|
||||
return registry.includes('amazonaws');
|
||||
return registry.includes('amazonaws') || (await isPubECR(registry));
|
||||
};
|
||||
|
||||
export const isPubECR = async (registry: string): Promise<boolean> => {
|
||||
return registry === 'public.ecr.aws';
|
||||
};
|
||||
|
||||
export const getRegion = async (registry: string): Promise<string> => {
|
||||
if (await isPubECR(registry)) {
|
||||
return process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';
|
||||
}
|
||||
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
|
||||
};
|
||||
|
||||
|
@ -39,12 +46,13 @@ export const parseCLIVersion = async (stdout: string): Promise<string> => {
|
|||
};
|
||||
|
||||
export const getDockerLoginCmd = 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(['ecr', 'get-login-password', '--region', region]).then(pwd => {
|
||||
return execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
|
||||
return `docker login --username AWS --password ${pwd} ${registry}`;
|
||||
});
|
||||
} else {
|
||||
return execCLI(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return dockerLoginCmd;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export async function loginStandard(registry: string, username: string, password
|
|||
if (registry) {
|
||||
core.info(`🔑 Logging into ${registry}...`);
|
||||
} else {
|
||||
core.info(`🔑 Logging into DockerHub...`);
|
||||
core.info(`🔑 Logging into Docker Hub...`);
|
||||
}
|
||||
await execm.exec('docker', loginArgs, true, password).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
|
@ -44,7 +44,12 @@ export async function loginECR(registry: string, username: string, password: str
|
|||
const cliPath = await aws.getCLI();
|
||||
const cliVersion = await aws.getCLIVersion();
|
||||
const region = await aws.getRegion(registry);
|
||||
core.info(`💡 AWS ECR detected with ${region} region`);
|
||||
|
||||
if (await aws.isPubECR(registry)) {
|
||||
core.info(`💡 AWS Public ECR detected with ${region} region`);
|
||||
} else {
|
||||
core.info(`💡 AWS ECR detected with ${region} region`);
|
||||
}
|
||||
|
||||
process.env.AWS_ACCESS_KEY_ID = username || process.env.AWS_ACCESS_KEY_ID;
|
||||
process.env.AWS_SECRET_ACCESS_KEY = password || process.env.AWS_SECRET_ACCESS_KEY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue