mirror of
https://github.com/docker/login-action.git
synced 2024-11-09 23:33:24 +01:00
ecr input to specify whether the given registry is ECR
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
b20b9f5e31
commit
b9a4d91ee5
8 changed files with 29 additions and 15 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -3,7 +3,7 @@ name: ci
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 10 * * *' # everyday at 10am
|
- cron: '0 10 * * *'
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
|
|
|
@ -379,6 +379,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 |
|
| `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 |
|
| `username` | String | | Username used to log against the Docker registry |
|
||||||
| `password` | String | | Password or personal access token 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 |
|
| `logout` | Bool | `true` | Log out from the Docker registry at the end of a job |
|
||||||
|
|
||||||
## Keep up-to-date with GitHub Dependabot
|
## Keep up-to-date with GitHub Dependabot
|
||||||
|
|
|
@ -34,6 +34,9 @@ test('successful with username and password', async () => {
|
||||||
const password: string = 'groundcontrol';
|
const password: string = 'groundcontrol';
|
||||||
process.env[`INPUT_PASSWORD`] = password;
|
process.env[`INPUT_PASSWORD`] = password;
|
||||||
|
|
||||||
|
const ecr: string = 'auto';
|
||||||
|
process.env['INPUT_ECR'] = ecr;
|
||||||
|
|
||||||
const logout: boolean = false;
|
const logout: boolean = false;
|
||||||
process.env['INPUT_LOGOUT'] = String(logout);
|
process.env['INPUT_LOGOUT'] = String(logout);
|
||||||
|
|
||||||
|
@ -41,7 +44,7 @@ test('successful with username and password', async () => {
|
||||||
|
|
||||||
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
expect(setRegistrySpy).toHaveBeenCalledWith('');
|
||||||
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
||||||
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
|
expect(dockerSpy).toHaveBeenCalledWith('', username, password, ecr);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calls docker login', async () => {
|
test('calls docker login', async () => {
|
||||||
|
@ -62,6 +65,9 @@ test('calls docker login', async () => {
|
||||||
const registry: string = 'ghcr.io';
|
const registry: string = 'ghcr.io';
|
||||||
process.env[`INPUT_REGISTRY`] = registry;
|
process.env[`INPUT_REGISTRY`] = registry;
|
||||||
|
|
||||||
|
const ecr: string = 'auto';
|
||||||
|
process.env['INPUT_ECR'] = ecr;
|
||||||
|
|
||||||
const logout: boolean = true;
|
const logout: boolean = true;
|
||||||
process.env['INPUT_LOGOUT'] = String(logout);
|
process.env['INPUT_LOGOUT'] = String(logout);
|
||||||
|
|
||||||
|
@ -69,5 +75,5 @@ test('calls docker login', async () => {
|
||||||
|
|
||||||
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
|
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
|
||||||
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
|
||||||
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password);
|
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password, ecr);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,10 @@ inputs:
|
||||||
password:
|
password:
|
||||||
description: 'Password or personal access token used to log against the Docker registry'
|
description: 'Password or personal access token used to log against the Docker registry'
|
||||||
required: false
|
required: false
|
||||||
|
ecr:
|
||||||
|
description: 'Specifies whether the given registry is ECR (auto, true or false)'
|
||||||
|
default: 'auto'
|
||||||
|
required: false
|
||||||
logout:
|
logout:
|
||||||
description: 'Log out from the Docker registry at the end of a job'
|
description: 'Log out from the Docker registry at the end of a job'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
|
|
13
dist/index.js
generated
vendored
13
dist/index.js
generated
vendored
|
@ -160,6 +160,7 @@ function getInputs() {
|
||||||
registry: core.getInput('registry'),
|
registry: core.getInput('registry'),
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
|
ecr: core.getInput('ecr'),
|
||||||
logout: core.getBooleanInput('logout')
|
logout: core.getBooleanInput('logout')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -206,9 +207,9 @@ exports.loginECR = exports.loginStandard = exports.logout = exports.login = void
|
||||||
const aws = __importStar(__nccwpck_require__(35981));
|
const aws = __importStar(__nccwpck_require__(35981));
|
||||||
const core = __importStar(__nccwpck_require__(42186));
|
const core = __importStar(__nccwpck_require__(42186));
|
||||||
const exec = __importStar(__nccwpck_require__(71514));
|
const exec = __importStar(__nccwpck_require__(71514));
|
||||||
function login(registry, username, password) {
|
function login(registry, username, password, ecr) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (aws.isECR(registry)) {
|
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
|
||||||
yield loginECR(registry, username, password);
|
yield loginECR(registry, username, password);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -328,10 +329,10 @@ const stateHelper = __importStar(__nccwpck_require__(88647));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const { registry, username, password, logout } = context.getInputs();
|
const input = context.getInputs();
|
||||||
stateHelper.setRegistry(registry);
|
stateHelper.setRegistry(input.registry);
|
||||||
stateHelper.setLogout(logout);
|
stateHelper.setLogout(input.logout);
|
||||||
yield docker.login(registry, username, password);
|
yield docker.login(input.registry, input.username, input.password, input.ecr);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
|
|
@ -4,6 +4,7 @@ export interface Inputs {
|
||||||
registry: string;
|
registry: string;
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
ecr: string;
|
||||||
logout: boolean;
|
logout: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ export function getInputs(): Inputs {
|
||||||
registry: core.getInput('registry'),
|
registry: core.getInput('registry'),
|
||||||
username: core.getInput('username'),
|
username: core.getInput('username'),
|
||||||
password: core.getInput('password'),
|
password: core.getInput('password'),
|
||||||
|
ecr: core.getInput('ecr'),
|
||||||
logout: core.getBooleanInput('logout')
|
logout: core.getBooleanInput('logout')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ import * as aws from './aws';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export async function login(registry: string, username: string, password: string): Promise<void> {
|
export async function login(registry: string, username: string, password: string, ecr: string): Promise<void> {
|
||||||
if (aws.isECR(registry)) {
|
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
|
||||||
await loginECR(registry, username, password);
|
await loginECR(registry, username, password);
|
||||||
} else {
|
} else {
|
||||||
await loginStandard(registry, username, password);
|
await loginStandard(registry, username, password);
|
||||||
|
|
|
@ -5,10 +5,10 @@ import * as stateHelper from './state-helper';
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const {registry, username, password, logout} = context.getInputs();
|
const input: context.Inputs = context.getInputs();
|
||||||
stateHelper.setRegistry(registry);
|
stateHelper.setRegistry(input.registry);
|
||||||
stateHelper.setLogout(logout);
|
stateHelper.setLogout(input.logout);
|
||||||
await docker.login(registry, username, password);
|
await docker.login(input.registry, input.username, input.password, input.ecr);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue