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

Add example for Azure Container Registry (ACR)

This commit is contained in:
CrazyMax 2020-08-21 16:29:54 +02:00
parent 1bd3567034
commit e56233ce43
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
5 changed files with 52 additions and 20 deletions

View file

@ -14,7 +14,7 @@ export const getCLI = async (): Promise<string> => {
return io.which('aws', true);
};
export const getCLICmdOutput = async (args: string[]): Promise<string> => {
export const execCLI = async (args: string[]): Promise<string> => {
return execm.exec(await getCLI(), args, true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
@ -27,7 +27,7 @@ export const getCLICmdOutput = async (args: string[]): Promise<string> => {
};
export const getCLIVersion = async (): Promise<string> => {
return parseCLIVersion(await getCLICmdOutput(['--version']));
return parseCLIVersion(await execCLI(['--version']));
};
export const parseCLIVersion = async (stdout: string): Promise<string> => {
@ -38,13 +38,13 @@ export const parseCLIVersion = async (stdout: string): Promise<string> => {
return semver.clean(matches[1]);
};
export const getECRLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
export const getDockerLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
if (semver.satisfies(cliVersion, '>=2.0.0')) {
return getCLICmdOutput(['ecr', 'get-login-password', '--region', region]).then(pwd => {
return execCLI(['ecr', 'get-login-password', '--region', region]).then(pwd => {
return `docker login --username AWS --password ${pwd} ${registry}`;
});
} else {
return getCLICmdOutput(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return execCLI(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return dockerLoginCmd;
});
}

View file

@ -1,4 +1,3 @@
import * as exec from '@actions/exec';
import * as core from '@actions/core';
import * as aws from './aws';
import * as execm from './exec';
@ -43,13 +42,13 @@ 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 registry detected with ${region} region`);
core.info(`💡 AWS ECR detected with ${region} region`);
process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password;
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
const loginCmd = await aws.getECRLoginCmd(cliVersion, registry, region);
const loginCmd = await aws.getDockerLoginCmd(cliVersion, registry, region);
core.info(`🔑 Logging into ${registry}...`);
execm.exec(loginCmd, [], true).then(res => {