Compare commits

..

22 Commits

Author SHA1 Message Date
CrazyMax
dd4fa0671b Merge pull request #160 from crazy-max/node12
Revert to Node 12 as default runtime
2022-03-01 20:54:30 +01:00
CrazyMax
4e3538592e Revert to Node 12 as default runtime
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-03-01 20:51:18 +01:00
CrazyMax
bb984efc56 Merge pull request #156 from docker/dependabot/npm_and_yarn/aws-sdk/client-ecr-public-3.53.0
Bump @aws-sdk/client-ecr-public from 3.45.0 to 3.53.0
2022-02-28 09:04:17 +01:00
CrazyMax
722888132b Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-28 08:54:17 +01:00
dependabot[bot]
17780b56b7 Bump @aws-sdk/client-ecr-public from 3.45.0 to 3.53.0
Bumps [@aws-sdk/client-ecr-public](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/clients/client-ecr-public) from 3.45.0 to 3.53.0.
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
- [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-ecr-public/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.53.0/clients/client-ecr-public)

---
updated-dependencies:
- dependency-name: "@aws-sdk/client-ecr-public"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-28 07:53:18 +00:00
CrazyMax
39857b3b45 Merge pull request #157 from docker/dependabot/npm_and_yarn/aws-sdk/client-ecr-3.53.0
Bump @aws-sdk/client-ecr from 3.45.0 to 3.53.0
2022-02-28 08:51:21 +01:00
CrazyMax
5fcc728422 Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-28 08:49:13 +01:00
dependabot[bot]
9fb8721eb9 Bump @aws-sdk/client-ecr from 3.45.0 to 3.53.0
Bumps [@aws-sdk/client-ecr](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/clients/client-ecr) from 3.45.0 to 3.53.0.
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
- [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-ecr/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.53.0/clients/client-ecr)

---
updated-dependencies:
- dependency-name: "@aws-sdk/client-ecr"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-28 07:45:26 +00:00
CrazyMax
4e3c9375bb Merge pull request #158 from crazy-max/node-16
update to node 16
2022-02-28 08:43:40 +01:00
CrazyMax
4b59a429db update to node 16
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-28 08:29:00 +01:00
CrazyMax
6af3c118c8 Merge pull request #152 from crazy-max/aws-sdk-proxy
handle proxy settings for aws-sdk
2022-02-17 11:30:34 +01:00
CrazyMax
caca3368ce handle proxy settings for aws-sdk
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-16 13:53:16 +01:00
CrazyMax
17f28ab24d Merge pull request #112 from dineshba/workload-identity-gcr-gar
Update readme with workload identity based authentication for GCR and GAR
2022-02-03 17:48:36 +01:00
Dinesh B
a875dd0e21 Update readme with workload identity based authentication for GCR and GAR
Signed-off-by: Dinesh B <dineshudt17@gmail.com>
Signed-off-by: Dinesh <dineshb@thoughtworks.com>
2022-02-03 20:57:42 +05:30
CrazyMax
7948fffc49 Merge pull request #49 from crazy-max/e2e-acr
Test login against ACR
2022-01-27 13:07:02 +01:00
CrazyMax
5fcefb941d Merge pull request #131 from docker/dependabot/npm_and_yarn/aws-sdk/client-ecr-public-3.45.0
Bump @aws-sdk/client-ecr-public from 3.43.0 to 3.45.0
2021-12-30 20:49:49 +01:00
CrazyMax
3bb2d084df Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-12-30 20:43:44 +01:00
dependabot[bot]
242fb9a356 Bump @aws-sdk/client-ecr-public from 3.43.0 to 3.45.0
Bumps [@aws-sdk/client-ecr-public](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/clients/client-ecr-public) from 3.43.0 to 3.45.0.
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
- [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-ecr-public/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.45.0/clients/client-ecr-public)

---
updated-dependencies:
- dependency-name: "@aws-sdk/client-ecr-public"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-30 19:41:46 +00:00
CrazyMax
fa72313bc3 Merge pull request #132 from docker/dependabot/npm_and_yarn/aws-sdk/client-ecr-3.45.0
Bump @aws-sdk/client-ecr from 3.44.0 to 3.45.0
2021-12-30 20:39:56 +01:00
CrazyMax
088f62a4f2 Update generated content
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-12-30 19:35:40 +01:00
dependabot[bot]
7929ac7647 Bump @aws-sdk/client-ecr from 3.44.0 to 3.45.0
Bumps [@aws-sdk/client-ecr](https://github.com/aws/aws-sdk-js-v3/tree/HEAD/clients/client-ecr) from 3.44.0 to 3.45.0.
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
- [Changelog](https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-ecr/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-js-v3/commits/v3.45.0/clients/client-ecr)

---
updated-dependencies:
- dependency-name: "@aws-sdk/client-ecr"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-24 05:13:23 +00:00
CrazyMax
9376d24995 Test login against ACR
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-22 11:30:57 +01:00
15 changed files with 6650 additions and 6265 deletions

View File

@@ -76,6 +76,20 @@ jobs:
docker image prune -a -f >/dev/null 2>&1 docker image prune -a -f >/dev/null 2>&1
docker pull ghcr.io/docker-ghactiontest/test docker pull ghcr.io/docker-ghactiontest/test
acr:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Login to ACR
uses: ./
with:
registry: ${{ secrets.AZURE_REGISTRY_NAME }}.azurecr.io
username: ${{ secrets.AZURE_CLIENT_ID }}
password: ${{ secrets.AZURE_CLIENT_SECRET }}
dockerhub: dockerhub:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:

104
README.md
View File

@@ -39,7 +39,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -64,7 +64,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -92,7 +92,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -118,7 +118,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -142,6 +142,45 @@ jobs:
> Google Container Registry, use the information [on this page](https://cloud.google.com/artifact-registry/docs/transition/transition-from-gcr) > 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. > to learn about transitioning to Google Artifact Registry.
You can use either workload identity federation based keyless authentication or service account based authentication.
#### Workload identity federation based authentication
Configure the workload identity federation for github actions in gcloud (for steps, [refer here](https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)). In the steps, your service account should the ability to push to GCR. Then use google-github-actions/auth action for authentication using workload identity like below:
```yaml
name: ci
on:
push:
branches: main
jobs:
login:
runs-on: ubuntu-latest
steps:
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: '<workload_identity_provider>'
service_account: '<service_account>'
- name: Login to GCR
uses: docker/login-action@v1
with:
registry: gcr.io
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
```
> Replace `<workload_identity_provider>` with configured workload identity provider. For steps to configure, [refer here](https://github.com/google-github-actions/auth#setting-up-workload-identity-federation).
> Replace `<service_account>` with configured service account in workload identity provider which has access to push to GCR
#### Service account based authentication
Use a service account with the ability to push to GCR and [configure access control](https://cloud.google.com/container-registry/docs/access-control). 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 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) [as a secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository)
@@ -153,7 +192,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -170,6 +209,47 @@ jobs:
### Google Artifact Registry (GAR) ### Google Artifact Registry (GAR)
You can use either workload identity federation based keyless authentication or service account based authentication.
#### Workload identity federation based authentication
Configure the workload identity federation for github actions in gcloud (for steps, [refer here](https://github.com/google-github-actions/auth#setting-up-workload-identity-federation)). In the steps, your service account should the ability to push to GAR. Then use google-github-actions/auth action for authentication using workload identity like below:
```yaml
name: ci
on:
push:
branches: main
jobs:
login:
runs-on: ubuntu-latest
steps:
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v0'
with:
token_format: 'access_token'
workload_identity_provider: '<workload_identity_provider>'
service_account: '<service_account>'
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: <location>-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
```
> Replace `<workload_identity_provider>` with configured workload identity provider
> Replace `<service_account>` with configured service account in workload identity provider which has access to push to GCR
> 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.
#### Service account based authentication
Use a service account with the ability to push to GAR and [configure access control](https://cloud.google.com/artifact-registry/docs/access-control). 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 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) [as a secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository)
@@ -181,7 +261,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -210,7 +290,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -233,7 +313,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -260,7 +340,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -293,7 +373,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -327,7 +407,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:
@@ -353,7 +433,7 @@ name: ci
on: on:
push: push:
branches: master branches: main
jobs: jobs:
login: login:

View File

@@ -1,3 +1,4 @@
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
import {AuthorizationData} from '@aws-sdk/client-ecr'; import {AuthorizationData} from '@aws-sdk/client-ecr';
import * as aws from '../src/aws'; import * as aws from '../src/aws';

View File

@@ -1,3 +1,4 @@
import {expect, test} from '@jest/globals';
import {getInputs} from '../src/context'; import {getInputs} from '../src/context';
test('with password and username getInputs does not throw error', async () => { test('with password and username getInputs does not throw error', async () => {

View File

@@ -1,20 +1,19 @@
import {expect, jest, test} from '@jest/globals';
import {loginStandard, logout} from '../src/docker'; import {loginStandard, logout} from '../src/docker';
import * as path from 'path'; import * as path from 'path';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner'); process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
test('loginStandard calls exec', async () => { test('loginStandard calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput'); // @ts-ignore
execSpy.mockImplementation(() => const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
Promise.resolve({ return {
exitCode: expect.any(Number), exitCode: expect.any(Number),
stdout: expect.any(Function), stdout: expect.any(Function),
stderr: expect.any(Function) stderr: expect.any(Function)
}) };
); });
const username: string = 'dbowie'; const username: string = 'dbowie';
const password: string = 'groundcontrol'; const password: string = 'groundcontrol';
@@ -30,14 +29,14 @@ test('loginStandard calls exec', async () => {
}); });
test('logout calls exec', async () => { test('logout calls exec', async () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput'); // @ts-ignore
execSpy.mockImplementation(() => const execSpy = jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
Promise.resolve({ return {
exitCode: expect.any(Number), exitCode: expect.any(Number),
stdout: expect.any(Function), stdout: expect.any(Function),
stderr: expect.any(Function) stderr: expect.any(Function)
}) };
); });
const registry: string = 'https://ghcr.io'; const registry: string = 'https://ghcr.io';

View File

@@ -1,3 +1,4 @@
import {expect, jest, test} from '@jest/globals';
import osm = require('os'); import osm = require('os');
import {run} from '../src/main'; import {run} from '../src/main';
@@ -7,26 +8,20 @@ import * as stateHelper from '../src/state-helper';
import * as core from '@actions/core'; import * as core from '@actions/core';
test('errors without username and password', async () => { test('errors without username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform'); const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
platSpy.mockImplementation(() => 'linux');
process.env['INPUT_LOGOUT'] = 'true'; // default value process.env['INPUT_LOGOUT'] = 'true'; // default value
const coreSpy = jest.spyOn(core, 'setFailed');
const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');
await run(); await run();
expect(coreSpy).toHaveBeenCalledWith('Username and password required'); expect(coreSpy).toHaveBeenCalledWith('Username and password required');
}); });
test('successful with username and password', async () => { test('successful with username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform'); const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
platSpy.mockImplementation(() => 'linux'); const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry'); const dockerSpy = jest.spyOn(docker, 'login').mockImplementation(jest.fn());
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout');
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(() => {});
const username: string = 'dbowie'; const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username; process.env[`INPUT_USERNAME`] = username;
@@ -48,13 +43,11 @@ test('successful with username and password', async () => {
}); });
test('calls docker login', async () => { test('calls docker login', async () => {
const platSpy = jest.spyOn(osm, 'platform'); const platSpy = jest.spyOn(osm, 'platform').mockImplementation(() => 'linux');
platSpy.mockImplementation(() => 'linux'); const setRegistrySpy = jest.spyOn(stateHelper, 'setRegistry');
const setLogoutSpy = jest.spyOn(stateHelper, 'setLogout');
const setRegistrySpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setRegistry'); const dockerSpy = jest.spyOn(docker, 'login');
const setLogoutSpy: jest.SpyInstance = jest.spyOn(stateHelper, 'setLogout'); dockerSpy.mockImplementation(jest.fn());
const dockerSpy: jest.SpyInstance = jest.spyOn(docker, 'login');
dockerSpy.mockImplementation(() => {});
const username: string = 'dbowie'; const username: string = 'dbowie';
process.env[`INPUT_USERNAME`] = username; process.env[`INPUT_USERNAME`] = username;

View File

@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.3-labs # syntax=docker/dockerfile:1.3-labs
ARG NODE_VERSION ARG NODE_VERSION=12
ARG DOCKER_VERSION=20.10.10 ARG DOCKER_VERSION=20.10.10
ARG BUILDX_VERSION=0.7.0 ARG BUILDX_VERSION=0.7.0

9259
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,3 @@
variable "NODE_VERSION" {
default = "12"
}
target "node-version" {
args = {
NODE_VERSION = NODE_VERSION
}
}
group "default" { group "default" {
targets = ["build"] targets = ["build"]
} }
@@ -21,50 +11,43 @@ group "validate" {
} }
target "build" { target "build" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "build-update" target = "build-update"
output = ["."] output = ["."]
} }
target "build-validate" { target "build-validate" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "build-validate" target = "build-validate"
output = ["type=cacheonly"] output = ["type=cacheonly"]
} }
target "format" { target "format" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "format-update" target = "format-update"
output = ["."] output = ["."]
} }
target "format-validate" { target "format-validate" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "format-validate" target = "format-validate"
output = ["type=cacheonly"] output = ["type=cacheonly"]
} }
target "vendor-update" { target "vendor-update" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "vendor-update" target = "vendor-update"
output = ["."] output = ["."]
} }
target "vendor-validate" { target "vendor-validate" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "vendor-validate" target = "vendor-validate"
output = ["type=cacheonly"] output = ["type=cacheonly"]
} }
target "test" { target "test" {
inherits = ["node-version"] dockerfile = "dev.Dockerfile"
dockerfile = "./hack/build.Dockerfile"
target = "test-coverage" target = "test-coverage"
output = ["./coverage"] output = ["./coverage"]
} }

View File

@@ -2,9 +2,7 @@ module.exports = {
clearMocks: true, clearMocks: true,
moduleFileExtensions: ['js', 'ts'], moduleFileExtensions: ['js', 'ts'],
setupFiles: ["dotenv/config"], setupFiles: ["dotenv/config"],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'], testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: { transform: {
'^.+\\.ts$': 'ts-jest' '^.+\\.ts$': 'ts-jest'
}, },

View File

@@ -4,8 +4,8 @@
"main": "lib/main.js", "main": "lib/main.js",
"scripts": { "scripts": {
"build": "tsc && ncc build", "build": "tsc && ncc build",
"format": "prettier --write **/*.ts", "format": "prettier --write '**/*.ts'",
"format-check": "prettier --check **/*.ts", "format-check": "prettier --check '**/*.ts'",
"test": "jest --coverage", "test": "jest --coverage",
"pre-checkin": "yarn run format && yarn run build" "pre-checkin": "yarn run format && yarn run build"
}, },
@@ -30,20 +30,18 @@
"@actions/core": "^1.6.0", "@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1", "@actions/io": "^1.1.1",
"@aws-sdk/client-ecr": "^3.44.0", "@aws-sdk/client-ecr": "^3.53.0",
"@aws-sdk/client-ecr-public": "^3.43.0" "@aws-sdk/client-ecr-public": "^3.53.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/node": "^16.11.26",
"@types/node": "^14.17.4", "@vercel/ncc": "^0.33.3",
"@vercel/ncc": "^0.28.6", "dotenv": "^16.0.0",
"dotenv": "^8.6.0", "jest": "^27.2.5",
"jest": "^26.6.3", "prettier": "^2.5.1",
"jest-circus": "^26.6.3", "ts-jest": "^27.1.2",
"jest-runtime": "^26.6.3", "typescript": "^4.4.4"
"prettier": "^2.3.2",
"ts-jest": "^26.5.6",
"typescript": "^3.9.10",
"typescript-formatter": "^7.2.2"
} }
} }

View File

@@ -1,6 +1,9 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {ECR} from '@aws-sdk/client-ecr'; import {ECR} from '@aws-sdk/client-ecr';
import {ECRPUBLIC} from '@aws-sdk/client-ecr-public'; import {ECRPUBLIC} from '@aws-sdk/client-ecr-public';
import {NodeHttpHandler} from '@aws-sdk/node-http-handler';
import {HttpProxyAgent} from 'http-proxy-agent';
import {HttpsProxyAgent} from 'https-proxy-agent';
const ecrRegistryRegex = /^(([0-9]{12})\.dkr\.ecr\.(.+)\.amazonaws\.com(.cn)?)(\/([^:]+)(:.+)?)?$/; const ecrRegistryRegex = /^(([0-9]{12})\.dkr\.ecr\.(.+)\.amazonaws\.com(.cn)?)(\/([^:]+)(:.+)?)?$/;
@@ -54,6 +57,20 @@ export const getRegistriesData = async (registry: string, username?: string, pas
authTokenRequest['registryIds'] = accountIDs; authTokenRequest['registryIds'] = accountIDs;
} }
let httpProxyAgent: any = null;
const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || '';
if (httpProxy) {
core.debug(`Using http proxy ${httpProxy}`);
httpProxyAgent = new HttpProxyAgent(httpProxy);
}
let httpsProxyAgent: any = null;
const httpsProxy = process.env.https_proxy || process.env.HTTPS_PROXY || '';
if (httpsProxy) {
core.debug(`Using https proxy ${httpsProxy}`);
httpsProxyAgent = new HttpsProxyAgent(httpsProxy);
}
const credentials = const credentials =
username && password username && password
? { ? {
@@ -67,7 +84,11 @@ export const getRegistriesData = async (registry: string, username?: string, pas
const ecrPublic = new ECRPUBLIC({ const ecrPublic = new ECRPUBLIC({
customUserAgent: 'docker-login-action', customUserAgent: 'docker-login-action',
credentials, credentials,
region: region region: region,
requestHandler: new NodeHttpHandler({
httpAgent: httpProxyAgent,
httpsAgent: httpsProxyAgent
})
}); });
const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest); const authTokenResponse = await ecrPublic.getAuthorizationToken(authTokenRequest);
if (!authTokenResponse.authorizationData || !authTokenResponse.authorizationData.authorizationToken) { if (!authTokenResponse.authorizationData || !authTokenResponse.authorizationData.authorizationToken) {
@@ -87,7 +108,11 @@ export const getRegistriesData = async (registry: string, username?: string, pas
const ecr = new ECR({ const ecr = new ECR({
customUserAgent: 'docker-login-action', customUserAgent: 'docker-login-action',
credentials, credentials,
region: region region: region,
requestHandler: new NodeHttpHandler({
httpAgent: httpProxyAgent,
httpsAgent: httpsProxyAgent
})
}); });
const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest); const authTokenResponse = await ecr.getAuthorizationToken(authTokenRequest);
if (!Array.isArray(authTokenResponse.authorizationData) || !authTokenResponse.authorizationData.length) { if (!Array.isArray(authTokenResponse.authorizationData) || !authTokenResponse.authorizationData.length) {

View File

@@ -9,7 +9,7 @@ export async function run(): Promise<void> {
stateHelper.setRegistry(input.registry); stateHelper.setRegistry(input.registry);
stateHelper.setLogout(input.logout); 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);
} catch (error) { } catch (error: any) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }

View File

@@ -1,11 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "esnext",
"module": "commonjs", "module": "commonjs",
"lib": [
"es6",
"dom"
],
"newLine": "lf", "newLine": "lf",
"outDir": "./lib", "outDir": "./lib",
"rootDir": "./src", "rootDir": "./src",

3382
yarn.lock

File diff suppressed because it is too large Load Diff