Compare commits

...

23 Commits

Author SHA1 Message Date
CrazyMax
7b79d7e834 Merge pull request #41 from crazy-max/fix-public-ecr
Fix public ECR login with AWS CLI v1
2020-12-17 07:52:03 +01:00
CrazyMax
f53ca527f7 Fix public ECR login with AWS CLI v1
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-17 07:49:50 +01:00
Chad Metcalf
3b14bab101 Merge pull request #37 from crazy-max/public-ecr
Add support for public ECR
2020-12-11 00:48:46 -08:00
CrazyMax
1e75de0e0e Add support for public ECR
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-11 07:15:35 +01:00
CrazyMax
7c9afe235c Merge pull request #35 from crazy-max/dind
Add example with DinD
2020-12-11 06:34:43 +01:00
CrazyMax
7dc3c3a70e Add example with DinD
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-08 19:12:44 +01:00
CrazyMax
12fd63324c Merge pull request #31 from crazy-max/master
Use major version of actions
2020-11-18 18:42:59 +01:00
CrazyMax
a3de3de177 Use major version of actions
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-11-18 18:41:33 +01:00
CrazyMax
9cbd4f95c4 Merge pull request #28 from pgressa/ocir
Extend documentation by OCI OCIR
2020-11-10 17:38:01 +01:00
Pavol Gressa
ad9eb3b250 Extend documentation by OCI OCIR 2020-11-10 17:24:49 +01:00
CrazyMax
71b3c789fa Merge pull request #23 from crazy-max/login-test
Test login against registries pt.1
2020-11-10 10:05:20 +01:00
CrazyMax
5e0bc83b38 Test login against registries
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-11-10 10:02:42 +01:00
CrazyMax
1f68ce02d7 Add workflow_dispatch event
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-28 17:03:42 +01:00
CrazyMax
767b2f4b7b Merge branch 'master' into login-test 2020-10-28 15:31:07 +01:00
Tõnis Tiigi
ddf06e1fed Merge pull request #22 from crazy-max/gar-example
Add example for Google Artifact Registry
2020-10-23 10:56:23 -07:00
CrazyMax
a5aa81adc8 Test login against registries
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-23 18:09:56 +02:00
CrazyMax
3b9e1f51cd Add example for Google Artifact Registry
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-23 16:30:05 +02:00
Tõnis Tiigi
adb73476b6 Merge pull request #21 from crazy-max/handle-aws-env
Handle AWS credentials
2020-10-20 09:14:56 -07:00
CrazyMax
5df5104555 Handle AWS credentials
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-20 14:42:02 +02:00
Tõnis Tiigi
39ef12fb7a Merge pull request #18 from crazy-max/username-required
Username required
2020-10-16 15:54:07 -07:00
CrazyMax
1c402b7c97 Fix tests
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-16 18:34:48 +02:00
CrazyMax
1c2cf9942d Username required
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-10-16 18:24:41 +02:00
Bryan Clark
4b15841c41 Mostly tests and some small changes (#16)
* Create docker.test.ts
* Add context tests
* test main
2020-10-09 10:30:45 +00:00
15 changed files with 528 additions and 152 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -1,93 +1,61 @@
name: ci
on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *' # everyday at 10am
push:
branches:
- master
- releases/v*
jobs:
# dockerhub:
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os:
# - ubuntu-20.04
# - ubuntu-18.04
# - ubuntu-16.04
# logout:
# - true
# - false
# steps:
# -
# name: Checkout
# uses: actions/checkout@v2.3.2
# -
# name: Login to DockerHub
# uses: ./
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME_TEST }}
# password: ${{ secrets.DOCKERHUB_PASSWORD_TEST }}
# logout: ${{ matrix.logout }}
# -
# name: Clear
# if: always()
# run: |
# rm -f ${HOME}/.docker/config.json
gpr:
dind:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
logout:
- true
- false
env:
DOCKER_CONFIG: $HOME/.docker
steps:
-
name: Checkout
uses: actions/checkout@v2.3.2
uses: actions/checkout@v2
-
name: Login to GitHub Package Registry
name: Login to GitHub Container Registry
uses: ./
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: ${{ matrix.logout }}
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_PAT }}
-
name: Clear
if: always()
name: DinD
uses: docker://docker
with:
entrypoint: docker
args: pull ghcr.io/docker-ghactiontest/test
-
name: Pull private image
run: |
rm -f ${HOME}/.docker/config.json
docker image prune -a -f >/dev/null 2>&1
docker pull ghcr.io/docker-ghactiontest/test
dockerhub:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-18.04
- ubuntu-16.04
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to Docker Hub
uses: ./
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# gitlab:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# logout:
# - true
# - false
# steps:
# -
# name: Checkout
# uses: actions/checkout@v2.3.2
# -
# name: Login to GitLab
# uses: ./
# with:
# registry: registry.gitlab.com
# username: ${{ secrets.GITLAB_USERNAME_TEST }}
# password: ${{ secrets.GITLAB_PASSWORD_TEST }}
# logout: ${{ matrix.logout }}
# -
# name: Clear
# if: always()
# run: |
# rm -f ${HOME}/.docker/config.json
#
# ecr:
# runs-on: ${{ matrix.os }}
# strategy:
@@ -97,13 +65,10 @@ jobs:
# - ubuntu-20.04
# - ubuntu-18.04
# - ubuntu-16.04
# logout:
# - true
# - false
# steps:
# -
# name: Checkout
# uses: actions/checkout@v2.3.1
# uses: actions/checkout@v2
# -
# name: Login to ECR
# uses: ./
@@ -111,9 +76,99 @@ jobs:
# registry: ${{ secrets.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
# username: ${{ secrets.AWS_ACCESS_KEY_ID }}
# password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# logout: ${{ matrix.logout }}
#
# ecr-aws-creds:
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os:
# - ubuntu-20.04
# - ubuntu-18.04
# - ubuntu-16.04
# steps:
# -
# name: Clear
# if: always()
# run: |
# rm -f ${HOME}/.docker/config.json
# name: Checkout
# uses: actions/checkout@v2
# -
# 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: ${{ secrets.AWS_REGION }}
# -
# name: Login to ECR
# uses: ./
# with:
# registry: ${{ secrets.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
github-package:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to GitHub Package Registry
uses: ./
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
github-container:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to GitHub Container Registry
uses: ./
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_PAT }}
gitlab:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to GitLab
uses: ./
with:
registry: registry.gitlab.com
username: ${{ secrets.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_TOKEN }}
# google-artifact:
# runs-on: ubuntu-latest
# steps:
# -
# name: Checkout
# uses: actions/checkout@v2
# -
# name: Login to Google Artifact Registry
# uses: ./
# with:
# registry: ${{ secrets.GAR_LOCATION }}-docker.pkg.dev
# username: _json_key
# password: ${{ secrets.GAR_JSON_KEY }}
#
# google-container:
# runs-on: ubuntu-latest
# steps:
# -
# name: Checkout
# uses: actions/checkout@v2
# -
# name: Login to Google Container Registry
# uses: ./
# with:
# registry: gcr.io
# username: _json_key
# password: ${{ secrets.GCR_JSON_KEY }}

View File

@@ -14,7 +14,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2.3.2
uses: actions/checkout@v2
-
name: Run Labeler
uses: crazy-max/ghaction-github-labeler@v3.0.0
uses: crazy-max/ghaction-github-labeler@v3

View File

@@ -24,7 +24,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2.3.2
uses: actions/checkout@v2
-
name: Install
run: yarn install
@@ -33,7 +33,7 @@ jobs:
run: yarn run test
-
name: Upload coverage
uses: codecov/codecov-action@v1.0.13
uses: codecov/codecov-action@v1
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}

161
README.md
View File

@@ -18,13 +18,16 @@ GitHub Action to login against a Docker registry.
___
* [Usage](#usage)
* [DockerHub](#dockerhub)
* [Docker Hub](#docker-hub)
* [GitHub Packages Docker Registry](#github-packages-docker-registry)
* [GitHub Container Registry](#github-container-registry)
* [GitLab](#gitlab)
* [Azure Container Registry (ACR)](#azure-container-registry-acr)
* [Google Container Registry (GCR)](#google-container-registry-gcr)
* [Google Artifact Registry (GAR)](#google-artifact-registry-gar)
* [AWS Elastic Container Registry (ECR)](#aws-elastic-container-registry-ecr)
* [AWS Public Elastic Container Registry (ECR)](#aws-public-elastic-container-registry-ecr)
* [OCI Oracle Cloud Infrastructure Registry (OCIR)](#oci-oracle-cloud-infrastructure-registry-ocir)
* [Customizing](#customizing)
* [inputs](#inputs)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
@@ -32,9 +35,9 @@ ___
## Usage
### DockerHub
### Docker Hub
To authenticate against [DockerHub](https://hub.docker.com) it's strongly recommended to create a
To authenticate against [Docker Hub](https://hub.docker.com) it's strongly recommended to create a
[personal access token](https://docs.docker.com/docker-hub/access-tokens/) as an alternative to your password.
```yaml
@@ -49,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
steps:
-
name: Login to DockerHub
name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
@@ -162,6 +165,11 @@ jobs:
### Google Container Registry (GCR)
> [Google Artifact Registry](#google-artifact-registry-gar) is the evolution of Google Container Registry. As a
> fully-managed service with support for both container images and non-container artifacts. If you currently use
> Google Container Registry, use the information [on this page](https://cloud.google.com/artifact-registry/docs/transition/transition-from-gcr)
> to learn about transitioning to Google Artifact Registry.
Use a service account with the ability to push to GCR and [configure access control](https://cloud.google.com/container-registry/docs/access-control).
Then create and download the JSON key for this service account and save content of `.json` file
[as a secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository)
@@ -187,6 +195,36 @@ jobs:
password: ${{ secrets.GCR_JSON_KEY }}
```
### Google Artifact Registry (GAR)
Use a service account with the ability to push to GAR and [configure access control](https://cloud.google.com/artifact-registry/docs/access-control).
Then create and download the JSON key for this service account and save content of `.json` file
[as a secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository)
called `GAR_JSON_KEY` in your GitHub repo. Ensure you set the username to `_json_key`.
```yaml
name: ci
on:
push:
branches: master
jobs:
login:
runs-on: ubuntu-latest
steps:
-
name: Login to GAR
uses: docker/login-action@v1
with:
registry: <location>-docker.pkg.dev
username: _json_key
password: ${{ secrets.GAR_JSON_KEY }}
```
> Replace `<location>` with the regional or multi-regional [location](https://cloud.google.com/artifact-registry/docs/repo-organize#locations)
> of the repository where the image is stored.
### AWS Elastic Container Registry (ECR)
Use an IAM user with the [ability to push to ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr_managed_policies.html).
@@ -213,8 +251,123 @@ jobs:
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
```
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 ECR
uses: docker/login-action@v1
with:
registry: <aws-account-number>.dkr.ecr.<region>.amazonaws.com
```
> Replace `<aws-account-number>` and `<region>` with their respective values.
### AWS Public Elastic Container Registry (ECR)
Use an IAM user with the [ability to push to ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/ecr_managed_policies.html).
Then create and download access keys and save `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [as 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
on:
push:
branches: master
jobs:
login:
runs-on: ubuntu-latest
steps:
-
name: Login to Public ECR
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
env:
AWS_REGION: <region>
```
> 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.
```yaml
name: ci
on:
push:
branches: master
jobs:
login:
runs-on: ubuntu-latest
steps:
-
name: Login to OCIR
uses: docker/login-action@v1
with:
registry: <region>.ocir.io
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
### inputs

View File

@@ -5,12 +5,24 @@ describe('isECR', () => {
test.each([
['registry.gitlab.com', false],
['gcr.io', false],
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', true]
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', true],
['public.ecr.aws', true]
])('given registry %p', async (registry, expected) => {
expect(await aws.isECR(registry)).toEqual(expected);
});
});
describe('isPubECR', () => {
test.each([
['registry.gitlab.com', false],
['gcr.io', false],
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', false],
['public.ecr.aws', true]
])('given registry %p', async (registry, expected) => {
expect(await aws.isPubECR(registry)).toEqual(expected);
});
});
describe('getCLI', () => {
it('exists', async () => {
const awsPath = await aws.getCLI();
@@ -45,10 +57,10 @@ describe('parseCLIVersion', () => {
});
describe('getRegion', () => {
test.each([['012345678901.dkr.ecr.eu-west-3.amazonaws.com', 'eu-west-3']])(
'given registry %p',
async (registry, expected) => {
expect(await aws.getRegion(registry)).toEqual(expected);
}
);
test.each([
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', 'eu-west-3'],
['public.ecr.aws', 'us-east-1']
])('given registry %p', async (registry, expected) => {
expect(await aws.getRegion(registry)).toEqual(expected);
});
});

11
__tests__/context.test.ts Normal file
View File

@@ -0,0 +1,11 @@
import osm = require('os');
import {getInputs} from '../src/context';
test('with password and username getInputs does not throw error', async () => {
process.env['INPUT_USERNAME'] = 'dbowie';
process.env['INPUT_PASSWORD'] = 'groundcontrol';
expect(() => {
getInputs();
}).not.toThrowError();
});

49
__tests__/docker.test.ts Normal file
View File

@@ -0,0 +1,49 @@
import {loginStandard, logout} from '../src/docker';
import * as path from 'path';
import * as exec from '@actions/exec';
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
test('loginStandard calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'exec');
// don't let exec try to actually run the commands
execSpy.mockImplementation(() => {});
const username: string = 'dbowie';
const password: string = 'groundcontrol';
const registry: string = 'https://ghcr.io';
await loginStandard(registry, username, password);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['login', '--password-stdin', '--username', username, registry], {
input: Buffer.from(password),
silent: true,
ignoreReturnCode: true,
listeners: expect.objectContaining({
stdout: expect.any(Function),
stderr: expect.any(Function)
})
});
});
test('logout calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'exec');
// don't let exec try to actually run the commands
execSpy.mockImplementation(() => {});
const registry: string = 'https://ghcr.io';
await logout(registry);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['logout', registry], {
silent: false,
ignoreReturnCode: true,
input: Buffer.from(''),
listeners: expect.objectContaining({
stdout: expect.any(Function),
stderr: expect.any(Function)
})
});
});

79
__tests__/main.test.ts Normal file
View File

@@ -0,0 +1,79 @@
import osm = require('os');
import {run} from '../src/main';
import * as docker from '../src/docker';
import * as stateHelper from '../src/state-helper';
import * as core from '@actions/core';
test('errors when not run on linux platform', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'netbsd');
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
await run();
expect(coreSpy).toHaveBeenCalledWith('Only supported on linux platform');
});
test('errors without username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
await run();
expect(coreSpy).toHaveBeenCalledWith('Username and password required');
});
test('successful with username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(() => {});
const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username;
const password: string = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;
await run();
expect(setRegistrySpy).toHaveBeenCalledWith('');
expect(setLogoutSpy).toHaveBeenCalledWith('');
expect(dockerSpy).toHaveBeenCalledWith('', username, password);
});
test('calls docker login', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(() => {});
const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username;
const password: string = 'groundcontrol';
process.env[`INPUT_PASSWORD`] = password;
const registry: string = 'ghcr.io';
process.env[`INPUT_REGISTRY`] = registry;
const logout: string = 'true';
process.env['INPUT_LOGOUT'] = logout;
await run();
expect(setRegistrySpy).toHaveBeenCalledWith(registry);
expect(setLogoutSpy).toHaveBeenCalledWith(logout);
expect(dockerSpy).toHaveBeenCalledWith(registry, username, password);
});

View File

@@ -15,7 +15,7 @@ inputs:
required: false
password:
description: 'Password or personal access token used to log against the Docker registry'
required: true
required: false
logout:
description: 'Log out from the Docker registry at the end of a job'
default: 'true'

73
dist/index.js generated vendored
View File

@@ -496,6 +496,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const os = __importStar(__webpack_require__(87));
const core = __importStar(__webpack_require__(186));
const context_1 = __webpack_require__(842);
@@ -505,19 +506,19 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
if (os.platform() !== 'linux') {
core.setFailed('Only supported on linux platform');
return;
throw new Error('Only supported on linux platform');
}
let inputs = yield context_1.getInputs();
stateHelper.setRegistry(inputs.registry);
stateHelper.setLogout(inputs.logout);
yield docker.login(inputs.registry, inputs.username, inputs.password);
const { registry, username, password, logout } = context_1.getInputs();
stateHelper.setRegistry(registry);
stateHelper.setLogout(logout);
yield docker.login(registry, username, password);
}
catch (error) {
core.setFailed(error.message);
}
});
}
exports.run = run;
function logout() {
return __awaiter(this, void 0, void 0, function* () {
if (!stateHelper.logout) {
@@ -3061,16 +3062,17 @@ function logout(registry) {
exports.logout = logout;
function loginStandard(registry, username, password) {
return __awaiter(this, void 0, void 0, function* () {
let loginArgs = ['login', '--password-stdin'];
if (username) {
loginArgs.push('--username', username);
if (!username || !password) {
throw new Error('Username and password required');
}
let loginArgs = ['login', '--password-stdin'];
loginArgs.push('--username', username);
loginArgs.push(registry);
if (registry) {
core.info(`🔑 Logging into ${registry}...`);
}
else {
core.info(`🔑 Logging into DockerHub...`);
core.info(`🔑 Logging into Docker Hub...`);
}
yield execm.exec('docker', loginArgs, true, password).then(res => {
if (res.stderr != '' && !res.success) {
@@ -3086,9 +3088,14 @@ function loginECR(registry, username, password) {
const cliPath = yield aws.getCLI();
const cliVersion = yield aws.getCLIVersion();
const region = yield aws.getRegion(registry);
core.info(`💡 AWS ECR detected with ${region} region`);
process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password;
if (yield aws.isPubECR(registry)) {
core.info(`💡 AWS Public ECR detected with ${region} region`);
}
else {
core.info(`💡 AWS ECR detected with ${region} region`);
}
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);
core.info(`🔑 Logging into ${registry}...`);
@@ -3640,27 +3647,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInputs = void 0;
const core = __importStar(__webpack_require__(186));
function getInputs() {
return __awaiter(this, void 0, void 0, function* () {
return {
registry: core.getInput('registry'),
username: core.getInput('username'),
password: core.getInput('password', { required: true }),
logout: core.getInput('logout')
};
});
return {
registry: core.getInput('registry'),
username: core.getInput('username'),
password: core.getInput('password'),
logout: core.getInput('logout')
};
}
exports.getInputs = getInputs;
//# sourceMappingURL=context.js.map
@@ -4164,14 +4160,20 @@ 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.isECR = void 0;
exports.getDockerLoginCmd = 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));
exports.isECR = (registry) => __awaiter(void 0, void 0, void 0, function* () {
return registry.includes('amazonaws');
return registry.includes('amazonaws') || (yield exports.isPubECR(registry));
});
exports.isPubECR = (registry) => __awaiter(void 0, void 0, void 0, function* () {
return registry === 'public.ecr.aws';
});
exports.getRegion = (registry) => __awaiter(void 0, void 0, void 0, function* () {
if (yield exports.isPubECR(registry)) {
return process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';
}
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
});
exports.getCLI = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -4201,13 +4203,14 @@ 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* () {
if (semver.satisfies(cliVersion, '>=2.0.0')) {
return exports.execCLI(['ecr', 'get-login-password', '--region', region]).then(pwd => {
let ecrCmd = (yield exports.isPubECR(registry)) ? 'ecr-public' : 'ecr';
if (semver.satisfies(cliVersion, '>=2.0.0') || (yield exports.isPubECR(registry))) {
return exports.execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
return `docker login --username AWS --password ${pwd} ${registry}`;
});
}
else {
return exports.execCLI(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return exports.execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return dockerLoginCmd;
});
}

View File

@@ -3,10 +3,17 @@ import * as io from '@actions/io';
import * as execm from './exec';
export const isECR = async (registry: string): Promise<boolean> => {
return registry.includes('amazonaws');
return registry.includes('amazonaws') || (await isPubECR(registry));
};
export const isPubECR = async (registry: string): Promise<boolean> => {
return registry === 'public.ecr.aws';
};
export const getRegion = async (registry: string): Promise<string> => {
if (await isPubECR(registry)) {
return process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || 'us-east-1';
}
return registry.substring(registry.indexOf('ecr.') + 4, registry.indexOf('.amazonaws'));
};
@@ -39,12 +46,13 @@ export const parseCLIVersion = async (stdout: string): Promise<string> => {
};
export const getDockerLoginCmd = async (cliVersion: string, registry: string, region: string): Promise<string> => {
if (semver.satisfies(cliVersion, '>=2.0.0')) {
return execCLI(['ecr', 'get-login-password', '--region', region]).then(pwd => {
let ecrCmd = (await isPubECR(registry)) ? 'ecr-public' : 'ecr';
if (semver.satisfies(cliVersion, '>=2.0.0') || (await isPubECR(registry))) {
return execCLI([ecrCmd, 'get-login-password', '--region', region]).then(pwd => {
return `docker login --username AWS --password ${pwd} ${registry}`;
});
} else {
return execCLI(['ecr', 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return execCLI([ecrCmd, 'get-login', '--region', region, '--no-include-email']).then(dockerLoginCmd => {
return dockerLoginCmd;
});
}

View File

@@ -7,11 +7,11 @@ export interface Inputs {
logout: string;
}
export async function getInputs(): Promise<Inputs> {
export function getInputs(): Inputs {
return {
registry: core.getInput('registry'),
username: core.getInput('username'),
password: core.getInput('password', {required: true}),
password: core.getInput('password'),
logout: core.getInput('logout')
};
}

View File

@@ -19,16 +19,18 @@ export async function logout(registry: string): Promise<void> {
}
export async function loginStandard(registry: string, username: string, password: string): Promise<void> {
let loginArgs: Array<string> = ['login', '--password-stdin'];
if (username) {
loginArgs.push('--username', username);
if (!username || !password) {
throw new Error('Username and password required');
}
let loginArgs: Array<string> = ['login', '--password-stdin'];
loginArgs.push('--username', username);
loginArgs.push(registry);
if (registry) {
core.info(`🔑 Logging into ${registry}...`);
} else {
core.info(`🔑 Logging into DockerHub...`);
core.info(`🔑 Logging into Docker Hub...`);
}
await execm.exec('docker', loginArgs, true, password).then(res => {
if (res.stderr != '' && !res.success) {
@@ -42,10 +44,15 @@ export async function loginECR(registry: string, username: string, password: str
const cliPath = await aws.getCLI();
const cliVersion = await aws.getCLIVersion();
const region = await aws.getRegion(registry);
core.info(`💡 AWS ECR detected with ${region} region`);
process.env.AWS_ACCESS_KEY_ID = username;
process.env.AWS_SECRET_ACCESS_KEY = password;
if (await aws.isPubECR(registry)) {
core.info(`💡 AWS Public ECR detected with ${region} region`);
} else {
core.info(`💡 AWS ECR detected with ${region} region`);
}
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 = await aws.getDockerLoginCmd(cliVersion, registry, region);

View File

@@ -4,17 +4,16 @@ import {getInputs, Inputs} from './context';
import * as docker from './docker';
import * as stateHelper from './state-helper';
async function run(): Promise<void> {
export async function run(): Promise<void> {
try {
if (os.platform() !== 'linux') {
core.setFailed('Only supported on linux platform');
return;
throw new Error('Only supported on linux platform');
}
let inputs: Inputs = await getInputs();
stateHelper.setRegistry(inputs.registry);
stateHelper.setLogout(inputs.logout);
await docker.login(inputs.registry, inputs.username, inputs.password);
const {registry, username, password, logout} = getInputs();
stateHelper.setRegistry(registry);
stateHelper.setLogout(logout);
await docker.login(registry, username, password);
} catch (error) {
core.setFailed(error.message);
}