1
0
Fork 0
mirror of https://github.com/docker/login-action.git synced 2025-04-27 17:16:35 +02:00

Add support for AWS Elastic Container Registry (ECR)

Add example for Google Container Registry (GCR)
This commit is contained in:
CrazyMax 2020-08-20 15:59:36 +02:00
parent e6dc03b339
commit f37c715508
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
5 changed files with 169 additions and 23 deletions

7
src/ecr.ts Normal file
View file

@ -0,0 +1,7 @@
export const isECR = async (registry: string): Promise<boolean> => {
return registry.includes('amazonaws');
};
export const getRegion = async (registry: string): Promise<string> => {
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
};

View file

@ -1,5 +1,6 @@
import * as os from 'os';
import * as core from '@actions/core';
import * as ecr from './ecr';
import * as exec from './exec';
import * as stateHelper from './state-helper';
@ -17,18 +18,30 @@ async function run(): Promise<void> {
const username: string = core.getInput('username');
const password: string = core.getInput('password', {required: true});
let loginArgs: Array<string> = ['login', '--password', password];
if (username) {
loginArgs.push('--username', username);
}
loginArgs.push(registry);
await exec.exec('docker', loginArgs, true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
if (await ecr.isECR(registry)) {
const ecrRegion = await ecr.getRegion(registry);
process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password;
await exec.exec('aws', ['ecr', 'get-login', '--region', ecrRegion, '--no-include-email'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
core.info('🎉 Login Succeeded!');
});
} else {
let loginArgs: Array<string> = ['login', '--password', password];
if (username) {
loginArgs.push('--username', username);
}
core.info('🎉 Login Succeeded!');
});
loginArgs.push(registry);
await exec.exec('docker', loginArgs, true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
core.info('🎉 Login Succeeded!');
});
}
} catch (error) {
core.setFailed(error.message);
}