mirror of
https://github.com/docker/login-action.git
synced 2025-11-11 20:46:20 +08:00
Compare commits
7 Commits
3891f5f1e9
...
98b2971c0d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98b2971c0d | ||
|
|
327cd5a69d | ||
|
|
e217ef3a2d | ||
|
|
087884b3d2 | ||
|
|
ca362a507b | ||
|
|
162c32cf05 | ||
|
|
8479e9040e |
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -15,12 +15,9 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Test
|
||||
uses: docker/bake-action@v5
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
targets: test
|
||||
-
|
||||
|
||||
16
.github/workflows/validate.yml
vendored
16
.github/workflows/validate.yml
vendored
@@ -15,16 +15,17 @@ jobs:
|
||||
prepare:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.matrix }}
|
||||
targets: ${{ steps.generate.outputs.targets }}
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Targets matrix
|
||||
id: targets
|
||||
run: |
|
||||
echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
|
||||
name: List targets
|
||||
id: generate
|
||||
uses: docker/bake-action/subaction/list-targets@v6
|
||||
with:
|
||||
target: validate
|
||||
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -35,11 +36,8 @@ jobs:
|
||||
matrix:
|
||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Validate
|
||||
uses: docker/bake-action@v5
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
@@ -24,6 +24,10 @@ inputs:
|
||||
description: 'Log out from the Docker registry at the end of a job'
|
||||
default: 'true'
|
||||
required: false
|
||||
attempts:
|
||||
description: 'Number of attempts to try in case of server-side errors'
|
||||
default: '1'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node20'
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
target "_common" {
|
||||
args = {
|
||||
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
|
||||
}
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["build"]
|
||||
}
|
||||
@@ -11,42 +17,49 @@ group "validate" {
|
||||
}
|
||||
|
||||
target "build" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "build-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "build-validate" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "build-validate"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "format" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "format-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "lint" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "lint"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "vendor" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "vendor-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "vendor-validate" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "vendor-validate"
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["_common"]
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "test-coverage"
|
||||
output = ["./coverage"]
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface Inputs {
|
||||
password: string;
|
||||
ecr: string;
|
||||
logout: boolean;
|
||||
attempts: number;
|
||||
}
|
||||
|
||||
export function getInputs(): Inputs {
|
||||
@@ -14,6 +15,7 @@ export function getInputs(): Inputs {
|
||||
username: core.getInput('username'),
|
||||
password: core.getInput('password'),
|
||||
ecr: core.getInput('ecr'),
|
||||
logout: core.getBooleanInput('logout')
|
||||
logout: core.getBooleanInput('logout'),
|
||||
attempts: Number.parseInt(core.getInput('attempts'))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import * as core from '@actions/core';
|
||||
|
||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||
|
||||
export async function login(registry: string, username: string, password: string, ecr: string): Promise<void> {
|
||||
export async function login(registry: string, username: string, password: string, ecr: string, attempts: number): Promise<void> {
|
||||
if (/true/i.test(ecr) || (ecr == 'auto' && aws.isECR(registry))) {
|
||||
await loginECR(registry, username, password);
|
||||
} else {
|
||||
await loginStandard(registry, username, password);
|
||||
await loginStandard(registry, username, password, attempts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function logout(registry: string): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function loginStandard(registry: string, username: string, password: string): Promise<void> {
|
||||
export async function loginStandard(registry: string, username: string, password: string, attempts: number): Promise<void> {
|
||||
if (!username && !password) {
|
||||
throw new Error('Username and password required');
|
||||
}
|
||||
@@ -41,16 +41,29 @@ export async function loginStandard(registry: string, username: string, password
|
||||
} else {
|
||||
core.info(`Logging into Docker Hub...`);
|
||||
}
|
||||
await Docker.getExecOutput(loginArgs, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true,
|
||||
input: Buffer.from(password)
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
let attempt: number = 1
|
||||
let succeeded: boolean = false
|
||||
for (let attempt = 1; (attempt <= attempts) && (!succeeded); attempt++) {
|
||||
await Docker.getExecOutput(loginArgs, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true,
|
||||
input: Buffer.from(password)
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
let isRetriable: boolean
|
||||
isRetriable = res.stderr.trim().endsWith("502 Bad Gateway")
|
||||
if (!isRetriable || (attempt >= attempts) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
} else {
|
||||
core.info(`Login Succeeded!`);
|
||||
succeeded = true;
|
||||
}
|
||||
});
|
||||
if ((attempt < attempts) && !succeeded) {
|
||||
await new Promise(r => setTimeout(r, 10000))
|
||||
}
|
||||
core.info(`Login Succeeded!`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function loginECR(registry: string, username: string, password: string): Promise<void> {
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function main(): Promise<void> {
|
||||
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);
|
||||
await docker.login(input.registry, input.username, input.password, input.ecr, input.attempts);
|
||||
}
|
||||
|
||||
async function post(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user