mirror of
https://github.com/docker/login-action.git
synced 2024-11-15 16:13:51 +08:00
Handle Amazon ECR registries associated with other accounts
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
3b14bab101
commit
d3160f671f
68
README.md
68
README.md
@ -251,6 +251,33 @@ jobs:
|
||||
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
```
|
||||
|
||||
If you need to log in to Amazon ECR registries associated with other accounts, you can use the `AWS_ECR_REGISTRY_IDS`
|
||||
environment variable:
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: master
|
||||
|
||||
jobs:
|
||||
login:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Login to ECR
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com
|
||||
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
env:
|
||||
AWS_ECR_REGISTRY_IDS: "012345678910 023456789012"
|
||||
```
|
||||
|
||||
> Only available with [AWS CLI version 1](https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login.html)
|
||||
|
||||
You can also use the [Configure AWS Credentials](https://github.com/aws-actions/configure-aws-credentials) action in
|
||||
combination with this action:
|
||||
|
||||
@ -311,41 +338,15 @@ jobs:
|
||||
|
||||
> Replace `<region>` with its respective value (default `us-east-1`).
|
||||
|
||||
You can also use the [Configure AWS Credentials](https://github.com/aws-actions/configure-aws-credentials) action in
|
||||
combination with this action:
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: master
|
||||
|
||||
jobs:
|
||||
login:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws-region: <region>
|
||||
-
|
||||
name: Login to Public ECR
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: public.ecr.aws
|
||||
```
|
||||
|
||||
> Replace `<region>` with its respective value.
|
||||
|
||||
### OCI Oracle Cloud Infrastructure Registry (OCIR)
|
||||
|
||||
To push into OCIR in specific tenancy the [username](https://www.oracle.com/webfolder/technetwork/tutorials/obe/oci/registry/index.html#LogintoOracleCloudInfrastructureRegistryfromtheDockerCLI)
|
||||
must be placed in format `<tenancy>/<username>` (in case of federated tenancy use the format `<tenancy-namespace>/oracleidentitycloudservice/<username>`).
|
||||
For password [create an auth token](https://www.oracle.com/webfolder/technetwork/tutorials/obe/oci/registry/index.html#GetanAuthToken). Save username and token
|
||||
[as a secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository) in your GitHub repo.
|
||||
must be placed in format `<tenancy>/<username>` (in case of federated tenancy use the format
|
||||
`<tenancy-namespace>/oracleidentitycloudservice/<username>`).
|
||||
|
||||
For password [create an auth token](https://www.oracle.com/webfolder/technetwork/tutorials/obe/oci/registry/index.html#GetanAuthToken).
|
||||
Save username and token [as a secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository)
|
||||
in your GitHub repo.
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
@ -366,6 +367,7 @@ jobs:
|
||||
username: ${{ secrets.OCI_USERNAME }}
|
||||
password: ${{ secrets.OCI_TOKEN }}
|
||||
```
|
||||
|
||||
> Replace `<region>` with their respective values from [availability regions](https://docs.cloud.oracle.com/iaas/Content/Registry/Concepts/registryprerequisites.htm#Availab)
|
||||
|
||||
## Customizing
|
||||
|
33
dist/index.js
generated
vendored
33
dist/index.js
generated
vendored
@ -3097,13 +3097,20 @@ function loginECR(registry, username, password) {
|
||||
process.env.AWS_ACCESS_KEY_ID = username || process.env.AWS_ACCESS_KEY_ID;
|
||||
process.env.AWS_SECRET_ACCESS_KEY = password || process.env.AWS_SECRET_ACCESS_KEY;
|
||||
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
|
||||
const loginCmd = yield aws.getDockerLoginCmd(cliVersion, registry, region);
|
||||
const loginCmds = yield aws.getDockerLoginCmds(cliVersion, registry, region);
|
||||
core.info(`🔑 Logging into ${registry}...`);
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
core.info('🎉 Login Succeeded!');
|
||||
loginCmds.forEach((loginCmd, index) => {
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
if (loginCmds.length > 1) {
|
||||
core.info(`🎉 Login Succeeded! (${index}/${loginCmds.length})`);
|
||||
}
|
||||
else {
|
||||
core.info('🎉 Login Succeeded!');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -4160,7 +4167,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDockerLoginCmd = exports.parseCLIVersion = exports.getCLIVersion = exports.execCLI = exports.getCLI = exports.getRegion = exports.isPubECR = exports.isECR = void 0;
|
||||
exports.getDockerLoginCmds = exports.parseCLIVersion = exports.getCLIVersion = exports.execCLI = exports.getCLI = exports.getRegion = exports.isPubECR = exports.isECR = void 0;
|
||||
const semver = __importStar(__webpack_require__(383));
|
||||
const io = __importStar(__webpack_require__(436));
|
||||
const execm = __importStar(__webpack_require__(757));
|
||||
@ -4202,16 +4209,20 @@ exports.parseCLIVersion = (stdout) => __awaiter(void 0, void 0, void 0, function
|
||||
}
|
||||
return semver.clean(matches[1]);
|
||||
});
|
||||
exports.getDockerLoginCmd = (cliVersion, registry, region) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
exports.getDockerLoginCmds = (cliVersion, registry, region) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let ecrCmd = (yield exports.isPubECR(registry)) ? 'ecr-public' : 'ecr';
|
||||
if (semver.satisfies(cliVersion, '>=2.0.0')) {
|
||||
return exports.execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
|
||||
return `docker login --username AWS --password ${pwd} ${registry}`;
|
||||
return [`docker login --username AWS --password ${pwd} ${registry}`];
|
||||
});
|
||||
}
|
||||
else {
|
||||
return exports.execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return dockerLoginCmd;
|
||||
let args = [ecrCmd, 'get-login', '--region', region, '--no-include-email'];
|
||||
if (process.env.AWS_ECR_REGISTRY_IDS) {
|
||||
args.push('--registry-ids', process.env.AWS_ECR_REGISTRY_IDS);
|
||||
}
|
||||
return exports.execCLI(args).then(dockerLoginCmds => {
|
||||
return dockerLoginCmds.trim().split(`\n`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
12
src/aws.ts
12
src/aws.ts
@ -45,15 +45,19 @@ export const parseCLIVersion = async (stdout: string): Promise<string> => {
|
||||
return semver.clean(matches[1]);
|
||||
};
|
||||
|
||||
export const getDockerLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
|
||||
export const getDockerLoginCmds = async (cliVersion: string, registry: string, region: string): Promise<string[]> => {
|
||||
let ecrCmd = (await isPubECR(registry)) ? 'ecr-public' : 'ecr';
|
||||
if (semver.satisfies(cliVersion, '>=2.0.0')) {
|
||||
return execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
|
||||
return `docker login --username AWS --password ${pwd} ${registry}`;
|
||||
return [`docker login --username AWS --password ${pwd} ${registry}`];
|
||||
});
|
||||
} else {
|
||||
return execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
|
||||
return dockerLoginCmd;
|
||||
let args: Array<string> = [ecrCmd, 'get-login', '--region', region, '--no-include-email'];
|
||||
if (process.env.AWS_ECR_REGISTRY_IDS) {
|
||||
args.push('--registry-ids', process.env.AWS_ECR_REGISTRY_IDS);
|
||||
}
|
||||
return execCLI(args).then(dockerLoginCmds => {
|
||||
return dockerLoginCmds.trim().split(`\n`);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -55,13 +55,19 @@ export async function loginECR(registry: string, username: string, password: str
|
||||
process.env.AWS_SECRET_ACCESS_KEY = password || process.env.AWS_SECRET_ACCESS_KEY;
|
||||
|
||||
core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
|
||||
const loginCmd = await aws.getDockerLoginCmd(cliVersion, registry, region);
|
||||
const loginCmds = await aws.getDockerLoginCmds(cliVersion, registry, region);
|
||||
|
||||
core.info(`🔑 Logging into ${registry}...`);
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
core.info('🎉 Login Succeeded!');
|
||||
loginCmds.forEach((loginCmd, index) => {
|
||||
execm.exec(loginCmd, [], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
if (loginCmds.length > 1) {
|
||||
core.info(`🎉 Login Succeeded! (${index}/${loginCmds.length})`);
|
||||
} else {
|
||||
core.info('🎉 Login Succeeded!');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user