From 4e02f2c08dfd04b3a02f8c6fc047e79ea3b4f0e0 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 16 Dec 2021 23:19:37 +0100 Subject: [PATCH] `ecr` input to specify whether the given registry is ECR Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 2 +- README.md | 1 + action.yml | 4 ++++ dist/index.js | 13 +++++++------ src/context.ts | 2 ++ src/docker.ts | 4 ++-- src/main.ts | 8 ++++---- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be1c0244..a7be4e01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: ci on: workflow_dispatch: schedule: - - cron: '0 10 * * *' # everyday at 10am + - cron: '0 10 * * *' push: branches: - 'master' diff --git a/README.md b/README.md index b98c8a88..381454e2 100644 --- a/README.md +++ b/README.md @@ -377,6 +377,7 @@ Following inputs can be used as `step.with` keys | `registry` | String | | Server address of Docker registry. If not set then will default to Docker Hub | | `username` | String | | Username used to log against the Docker registry | | `password` | String | | Password or personal access token used to log against the Docker registry | +| `ecr` | String | `auto` | Specifies whether the given registry is ECR (`auto`, `true` or `false`) | | `logout` | Bool | `true` | Log out from the Docker registry at the end of a job | ## Keep up-to-date with GitHub Dependabot diff --git a/action.yml b/action.yml index 039e609b..5e837acf 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: password: description: 'Password or personal access token used to log against the Docker registry' required: false + ecr: + description: 'Specifies whether the given registry is ECR (auto, true or false)' + default: 'auto' + required: false logout: description: 'Log out from the Docker registry at the end of a job' default: 'true' diff --git a/dist/index.js b/dist/index.js index 6e8d1983..0a254b78 100644 --- a/dist/index.js +++ b/dist/index.js @@ -150,6 +150,7 @@ function getInputs() { registry: core.getInput('registry'), username: core.getInput('username'), password: core.getInput('password'), + ecr: core.getInput('ecr'), logout: core.getBooleanInput('logout') }; } @@ -196,9 +197,9 @@ exports.loginECR = exports.loginStandard = exports.logout = exports.login = void const aws = __importStar(__nccwpck_require__(5981)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); -function login(registry, username, password) { +function login(registry, username, password, ecr) { return __awaiter(this, void 0, void 0, function* () { - if (yield aws.isECR(registry)) { + if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) { yield loginECR(registry, username, password); } else { @@ -338,10 +339,10 @@ const stateHelper = __importStar(__nccwpck_require__(8647)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - const { registry, username, password, logout } = context.getInputs(); - stateHelper.setRegistry(registry); - stateHelper.setLogout(logout); - yield docker.login(registry, username, password); + const input = context.getInputs(); + stateHelper.setRegistry(input.registry); + stateHelper.setLogout(input.logout); + yield docker.login(input.registry, input.username, input.password, input.ecr); } catch (error) { core.setFailed(error.message); diff --git a/src/context.ts b/src/context.ts index f5bdaa27..8a381688 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,6 +4,7 @@ export interface Inputs { registry: string; username: string; password: string; + ecr: string; logout: boolean; } @@ -12,6 +13,7 @@ export function getInputs(): Inputs { registry: core.getInput('registry'), username: core.getInput('username'), password: core.getInput('password'), + ecr: core.getInput('ecr'), logout: core.getBooleanInput('logout') }; } diff --git a/src/docker.ts b/src/docker.ts index 1178575b..5e10b68e 100644 --- a/src/docker.ts +++ b/src/docker.ts @@ -2,8 +2,8 @@ import * as aws from './aws'; import * as core from '@actions/core'; import * as exec from '@actions/exec'; -export async function login(registry: string, username: string, password: string): Promise { - if (await aws.isECR(registry)) { +export async function login(registry: string, username: string, password: string, ecr: string): Promise { + if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) { await loginECR(registry, username, password); } else { await loginStandard(registry, username, password); diff --git a/src/main.ts b/src/main.ts index f15082e6..9e03601d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,10 +5,10 @@ import * as stateHelper from './state-helper'; export async function run(): Promise { try { - const {registry, username, password, logout} = context.getInputs(); - stateHelper.setRegistry(registry); - stateHelper.setLogout(logout); - await docker.login(registry, username, password); + const input: context.Inputs = context.getInputs(); + stateHelper.setRegistry(input.registry); + stateHelper.setLogout(input.logout); + await docker.login(input.registry, input.username, input.password, input.ecr); } catch (error) { core.setFailed(error.message); }