Handle AWS CLI v2

This commit is contained in:
CrazyMax 2020-08-21 15:27:22 +02:00
parent 16d491f0ca
commit d833f7c2ad
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 58 additions and 30 deletions

@ -8,10 +8,14 @@ on:
jobs: jobs:
dockerhub: dockerhub:
runs-on: ubuntu-latest runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os:
- ubuntu-20.04
- ubuntu-18.04
- ubuntu-16.04
logout: logout:
- true - true
- false - false

@ -1,5 +1,6 @@
[![GitHub release](https://img.shields.io/github/release/crazy-max/ghaction-docker-login.svg?style=flat-square)](https://github.com/crazy-max/ghaction-docker-login/releases/latest) [![GitHub release](https://img.shields.io/github/release/crazy-max/ghaction-docker-login.svg?style=flat-square)](https://github.com/crazy-max/ghaction-docker-login/releases/latest)
[![GitHub marketplace](https://img.shields.io/badge/marketplace-docker--login-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/docker-login) [![GitHub marketplace](https://img.shields.io/badge/marketplace-docker--login-blue?logo=github&style=flat-square)](https://github.com/marketplace/actions/docker-login)
[![CI workflow](https://img.shields.io/github/workflow/status/crazy-max/ghaction-docker-login/test?label=ci&logo=github&style=flat-square)](https://github.com/crazy-max/ghaction-docker-login/actions?workflow=ci)
[![Test workflow](https://img.shields.io/github/workflow/status/crazy-max/ghaction-docker-login/test?label=test&logo=github&style=flat-square)](https://github.com/crazy-max/ghaction-docker-login/actions?workflow=test) [![Test workflow](https://img.shields.io/github/workflow/status/crazy-max/ghaction-docker-login/test?label=test&logo=github&style=flat-square)](https://github.com/crazy-max/ghaction-docker-login/actions?workflow=test)
[![Codecov](https://img.shields.io/codecov/c/github/crazy-max/ghaction-docker-login?logo=codecov&style=flat-square)](https://codecov.io/gh/crazy-max/ghaction-docker-login) [![Codecov](https://img.shields.io/codecov/c/github/crazy-max/ghaction-docker-login?logo=codecov&style=flat-square)](https://codecov.io/gh/crazy-max/ghaction-docker-login)
[![Become a sponsor](https://img.shields.io/badge/sponsor-crazy--max-181717.svg?logo=github&style=flat-square)](https://github.com/sponsors/crazy-max) [![Become a sponsor](https://img.shields.io/badge/sponsor-crazy--max-181717.svg?logo=github&style=flat-square)](https://github.com/sponsors/crazy-max)

29
dist/index.js generated vendored

@ -3019,21 +3019,20 @@ function loginECR(registry, username, password) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const cliPath = yield aws.getCLI(); const cliPath = yield aws.getCLI();
const cliVersion = yield aws.getCLIVersion(); const cliVersion = yield aws.getCLIVersion();
const ecrRegion = yield aws.getRegion(registry); const region = yield aws.getRegion(registry);
core.info(`💡 AWS ECR registry detected with ${ecrRegion} region`); core.info(`💡 AWS ECR registry detected with ${region} region`);
process.env.AWS_ACCESS_KEY_ID = username; process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password; process.env.AWS_SECRET_ACCESS_KEY = password;
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`); core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
aws.getCLICmdOutput(['ecr', 'get-login', '--region', ecrRegion, '--no-include-email']).then(stdout => { const loginCmd = yield aws.getECRLoginCmd(cliVersion, registry, region);
core.info(`🔑 Logging into ${registry}...`); core.info(`🔑 Logging into ${registry}...`);
execm.exec(stdout, [], true).then(res => { execm.exec(loginCmd, [], true).then(res => {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(res.stderr); throw new Error(res.stderr);
} }
core.info('🎉 Login Succeeded!'); core.info('🎉 Login Succeeded!');
}); });
}); });
});
} }
exports.loginECR = loginECR; exports.loginECR = loginECR;
//# sourceMappingURL=docker.js.map //# sourceMappingURL=docker.js.map
@ -4099,7 +4098,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCLIVersion = exports.getCLIVersion = exports.getCLICmdOutput = exports.getCLI = exports.getRegion = exports.isECR = void 0; exports.getECRLoginCmd = exports.parseCLIVersion = exports.getCLIVersion = exports.getCLICmdOutput = exports.getCLI = exports.getRegion = exports.isECR = void 0;
const semver = __importStar(__webpack_require__(383)); const semver = __importStar(__webpack_require__(383));
const io = __importStar(__webpack_require__(436)); const io = __importStar(__webpack_require__(436));
const execm = __importStar(__webpack_require__(757)); const execm = __importStar(__webpack_require__(757));
@ -4130,10 +4129,22 @@ exports.getCLIVersion = () => __awaiter(void 0, void 0, void 0, function* () {
}); });
exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function* () { exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function* () {
const matches = /aws-cli\/([0-9.]+)/.exec(stdout); const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
if (matches) { if (!matches) {
return semver.clean(matches[1]); throw new Error(`Cannot parse AWS CLI version`);
}
return semver.clean(matches[1]);
});
exports.getECRLoginCmd = (cliVersion, registry, region) => __awaiter(void 0, void 0, void 0, function* () {
if (semver.satisfies(cliVersion, '>=2.0.0')) {
return exports.getCLICmdOutput(['ecr', 'get-login-password', '--region', region]).then(pwd => {
return `docker login --username AWS --password ${pwd} ${registry}`;
});
}
else {
return exports.getCLICmdOutput(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return dockerLoginCmd;
});
} }
return undefined;
}); });
//# sourceMappingURL=aws.js.map //# sourceMappingURL=aws.js.map

@ -26,14 +26,26 @@ export const getCLICmdOutput = async (args: string[]): Promise<string> => {
}); });
}; };
export const getCLIVersion = async (): Promise<string | undefined> => { export const getCLIVersion = async (): Promise<string> => {
return parseCLIVersion(await getCLICmdOutput(['--version'])); return parseCLIVersion(await getCLICmdOutput(['--version']));
}; };
export const parseCLIVersion = async (stdout: string): Promise<string | undefined> => { export const parseCLIVersion = async (stdout: string): Promise<string> => {
const matches = /aws-cli\/([0-9.]+)/.exec(stdout); const matches = /aws-cli\/([0-9.]+)/.exec(stdout);
if (matches) { if (!matches) {
return semver.clean(matches[1]); throw new Error(`Cannot parse AWS CLI version`);
}
return semver.clean(matches[1]);
};
export const getECRLoginCmd = 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 `docker login --username AWS --password ${pwd} ${registry}`;
});
} else {
return getCLICmdOutput(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return dockerLoginCmd;
});
} }
return undefined;
}; };

@ -42,20 +42,20 @@ export async function loginStandard(registry: string, username: string, password
export async function loginECR(registry: string, username: string, password: string): Promise<void> { export async function loginECR(registry: string, username: string, password: string): Promise<void> {
const cliPath = await aws.getCLI(); const cliPath = await aws.getCLI();
const cliVersion = await aws.getCLIVersion(); const cliVersion = await aws.getCLIVersion();
const ecrRegion = await aws.getRegion(registry); const region = await aws.getRegion(registry);
core.info(`💡 AWS ECR registry detected with ${ecrRegion} region`); core.info(`💡 AWS ECR registry detected with ${region} region`);
process.env.AWS_ACCESS_KEY_ID = username; process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password; process.env.AWS_SECRET_ACCESS_KEY = password;
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`); core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
aws.getCLICmdOutput(['ecr', 'get-login', '--region', ecrRegion, '--no-include-email']).then(stdout => { const loginCmd = await aws.getECRLoginCmd(cliVersion, registry, region);
core.info(`🔑 Logging into ${registry}...`); core.info(`🔑 Logging into ${registry}...`);
execm.exec(stdout, [], true).then(res => { execm.exec(loginCmd, [], true).then(res => {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(res.stderr); throw new Error(res.stderr);
} }
core.info('🎉 Login Succeeded!'); core.info('🎉 Login Succeeded!');
}); });
});
} }