Compare commits

..

2 Commits

Author SHA1 Message Date
CrazyMax
508c654904
chore: update generated content
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-09-11 14:38:22 +02:00
CrazyMax
38e5bc6168
multiple logins support
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-09-11 14:38:22 +02:00
11 changed files with 89 additions and 121 deletions

View File

@ -19,7 +19,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Stop docker
run: |
@ -43,7 +43,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to GitHub Container Registry
uses: ./
@ -60,7 +60,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to GitHub Container Registry
uses: ./
@ -85,7 +85,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to ACR
uses: ./
@ -105,7 +105,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to Docker Hub
uses: ./
@ -124,7 +124,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to ECR
uses: ./
@ -144,10 +144,10 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@ -169,7 +169,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to Public ECR
continue-on-error: ${{ matrix.os == 'windows-latest' }}
@ -192,10 +192,10 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v5
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@ -218,7 +218,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to GitHub Container Registry
uses: ./
@ -238,7 +238,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to GitLab
uses: ./
@ -258,7 +258,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to Google Artifact Registry
uses: ./
@ -278,7 +278,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to Google Container Registry
uses: ./
@ -287,17 +287,40 @@ jobs:
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
registry-auth:
multi:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to registries
uses: ./
with:
registry-auth: |
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logins: |
- username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- registry: registry.gitlab.com
username: ${{ secrets.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_TOKEN }}
multi-logins-only:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Login to registries
uses: ./
with:
logins: |
- username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- registry: ghcr.io
@ -310,17 +333,17 @@ jobs:
username: ${{ secrets.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_TOKEN }}
registry-auth-dup:
multi-dup:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Login to registries
uses: ./
with:
registry-auth: |
logins: |
- registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
@ -330,29 +353,3 @@ jobs:
- registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry-auth-exclusive:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v5
-
name: Login to registries
id: login
continue-on-error: true
uses: ./
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry-auth: |
- username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Check
run: |
if [ "${{ steps.login.outcome }}" != "failure" ] || [ "${{ steps.login.conclusion }}" != "success" ]; then
echo "::error::Should have failed"
exit 1
fi

View File

@ -31,7 +31,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Initialize CodeQL
uses: github/codeql-action/init@v3

View File

@ -15,7 +15,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Publish
uses: actions/publish-immutable-action@v0.0.4

View File

@ -17,7 +17,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: Test
uses: docker/bake-action@v6

View File

@ -19,7 +19,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v4
-
name: List targets
id: generate

View File

@ -497,42 +497,9 @@ jobs:
### Authenticate to multiple registries
To authenticate against multiple registries, you can specify the login-action
step multiple times in your workflow:
```yaml
name: ci
on:
push:
branches: main
jobs:
login:
runs-on: ubuntu-latest
steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
```
You can also use the `registry-auth` input for raw authentication to
registries, defined as YAML objects. Each object can contain `registry`,
`username`, `password` and `ecr` keys similar to current inputs:
> [!WARNING]
> We don't recommend using this method, it's better to use the action multiple
> times as shown above.
You can authenticate to multiple registries by using the `logins` input. Define
the registries as YAML objects. Each object can contain `registry`, `username`,
`password` and `ecr` keys similar to current inputs:
```yaml
name: ci
@ -549,7 +516,7 @@ jobs:
name: Login to registries
uses: docker/login-action@v3
with:
registry-auth: |
logins: |
- username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- registry: ghcr.io
@ -563,18 +530,14 @@ jobs:
The following inputs can be used as `step.with` keys:
| Name | Type | Default | Description |
|-----------------|--------|-------------|-------------------------------------------------------------------------------|
| `registry` | String | `docker.io` | Server address of Docker registry. If not set then will default to Docker Hub |
| `username` | String | | Username for authenticating to the Docker registry |
| `password` | String | | Password or personal access token for authenticating 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 |
| `registry-auth` | YAML | | Raw authentication to registries, defined as YAML objects |
> [!NOTE]
> The `registry-auth` input is mutually exclusive with `registry`, `username`,
> `password` and `ecr` inputs.
| Name | Type | Default | Description |
|------------|--------|---------|-------------------------------------------------------------------------------|
| `registry` | String | | Server address of Docker registry. If not set then will default to Docker Hub |
| `username` | String | | Username for authenticating to the Docker registry |
| `password` | String | | Password or personal access token for authenticating 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 |
| `logins` | YAML | | Add multiple registries to authenticate to, defined as YAML objects |
## Contributing

View File

@ -18,13 +18,14 @@ inputs:
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'
required: false
registry-auth:
description: 'Raw authentication to registries, defined as YAML objects'
logins:
description: 'Add multiple registries to authenticate to, defined as YAML objects'
required: false
runs:

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ export interface Inputs {
password: string;
ecr: string;
logout: boolean;
registryAuth: string;
logins: string;
}
export function getInputs(): Inputs {
@ -16,6 +16,6 @@ export function getInputs(): Inputs {
password: core.getInput('password'),
ecr: core.getInput('ecr'),
logout: core.getBooleanInput('logout'),
registryAuth: core.getInput('registry-auth')
logins: core.getInput('logins')
};
}

View File

@ -17,19 +17,19 @@ export async function main(): Promise<void> {
const inputs: context.Inputs = context.getInputs();
stateHelper.setLogout(inputs.logout);
if (inputs.registryAuth && (inputs.registry || inputs.username || inputs.password || inputs.ecr)) {
throw new Error('Cannot use registry-auth with other inputs');
const auths: Array<Auth> = [];
if (inputs.registry || inputs.username) {
auths.push({
registry: inputs.registry,
username: inputs.username,
password: inputs.password,
ecr: inputs.ecr
});
}
if (!inputs.registryAuth) {
stateHelper.setRegistries([inputs.registry || 'docker.io']);
await docker.login(inputs.registry || 'docker.io', inputs.username, inputs.password, inputs.ecr || 'auto');
return;
}
const auths = yaml.load(inputs.registryAuth) as Auth[];
if (auths.length == 0) {
throw new Error('No registry to login');
const logins = yaml.load(inputs.logins) as Auth[];
if (Array.isArray(logins)) {
auths.push(...logins);
}
const registries: string[] = [];
@ -42,10 +42,17 @@ export async function main(): Promise<void> {
}
stateHelper.setRegistries(registries.filter((value, index, self) => self.indexOf(value) === index));
for (const auth of auths) {
await core.group(`Login to ${auth.registry || 'docker.io'}`, async () => {
await docker.login(auth.registry || 'docker.io', auth.username, auth.password, auth.ecr || 'auto');
});
if (auths.length == 0) {
throw new Error('No registry to login');
}
if (auths.length === 1) {
await docker.login(auths[0].registry || 'docker.io', auths[0].username, auths[0].password, auths[0].ecr || 'auto');
} else {
for (const auth of auths) {
await core.group(`Login to ${auth.registry || 'docker.io'}`, async () => {
await docker.login(auth.registry || 'docker.io', auth.username, auth.password, auth.ecr || 'auto');
});
}
}
}