Skip to content

Commit 454a99d

Browse files
committed
feat: add support for HTTP(s) proxy
1 parent 62f4f87 commit 454a99d

File tree

7 files changed

+2258
-220
lines changed

7 files changed

+2258
-220
lines changed

README.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ Logs in the local Docker client to one or more Amazon ECR Private registries or
77
<!-- toc -->
88

99
- [Example of Usage](#examples-of-usage)
10-
- [Credentials and Region](#credentials-and-region)
10+
- [Building and pushing an image](#building-and-pushing-an-image)
11+
- [Using an image as a service](#using-an-image-as-a-service)
12+
- [Credentials](#credentials)
13+
- [AWS credentials](#aws-credentials)
14+
- [Docker credentials](#docker-credentials)
15+
- [Self-Hosted Runners](#self-hosted-runners)
16+
- [Proxy configuration](#proxy-configuration)
1117
- [Permissions](#permissions)
18+
- [ECR Private](#ecr-private)
19+
- [ECR Public](#ecr-public)
1220
- [Troubleshooting](#troubleshooting)
1321
- [License Summary](#license-summary)
1422
- [Security Disclosures](#security-disclosures)
@@ -164,7 +172,7 @@ jobs:
164172

165173
See [action.yml](action.yml) for the full documentation for this action's inputs and outputs.
166174

167-
## Credentials and Region
175+
## Credentials
168176

169177
### AWS Credentials
170178

@@ -204,6 +212,29 @@ If using ECR Public:
204212

205213
To push Helm charts, you can also login through Docker. By default, Helm can authenticate with the same credentials that you use for Docker.
206214

215+
## Self-Hosted Runners
216+
217+
### Proxy Configuration
218+
219+
If you run in self-hosted environments and/or in secured environments where you need to use a specific proxy, you can set it in the action manually.
220+
221+
Additionally, this action will always consider an already configured proxy in the environment.
222+
223+
Proxy configured via action input:
224+
```yaml
225+
uses: aws-actions/[email protected]
226+
with:
227+
http-proxy: "http://companydomain.com:3128"
228+
````
229+
230+
Proxy configured via an environment variable:
231+
```shell
232+
# Your environment configuration
233+
HTTP_PROXY="http://companydomain.com:3128"
234+
```
235+
236+
The action will read the underlying proxy configuration from the environment, and you don't need to configure it in the action.
237+
207238
## Permissions
208239

209240
### ECR Private

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
Options: [private, public]
2525
required: false
2626
default: private
27+
http-proxy:
28+
description: >-
29+
Proxy to use for the AWS SDK agent.
30+
required: false
2731
outputs:
2832
registry:
2933
description: >-

dist/index.js

+1,959-97
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const core = require('@actions/core');
22
const exec = require('@actions/exec');
33
const aws = require('aws-sdk');
4+
const proxy = require('https-proxy-agent');
45

56
const ECR_LOGIN_GITHUB_ACTION_USER_AGENT = 'amazon-ecr-login-for-github-actions';
67
const ECR_PUBLIC_REGISTRY_URI = 'public.ecr.aws';
78

89
const INPUTS = {
910
skipLogout: 'skip-logout',
1011
registries: 'registries',
11-
registryType: 'registry-type'
12+
registryType: 'registry-type',
13+
httpProxy: 'http-proxy'
1214
};
1315

1416
const OUTPUTS = {
@@ -27,8 +29,24 @@ const REGISTRY_TYPES = {
2729
};
2830

2931

30-
function replaceSpecialCharacters(registryUri) {
31-
return registryUri.replace(/[^a-zA-Z0-9_]+/g, '_');
32+
function configureProxy(httpProxy) {
33+
const proxyFromEnv = process.env.HTTP_PROXY || process.env.http_proxy;
34+
35+
if (httpProxy || proxyFromEnv) {
36+
let proxyToSet;
37+
38+
if (httpProxy){
39+
core.info(`Setting proxy from action input: ${httpProxy}`);
40+
proxyToSet = httpProxy;
41+
} else {
42+
core.info(`Setting proxy from environment: ${proxyFromEnv}`);
43+
proxyToSet = proxyFromEnv;
44+
}
45+
46+
aws.config.update({
47+
httpOptions: { agent: proxy(proxyToSet) }
48+
});
49+
}
3250
}
3351

3452
async function getEcrAuthTokenWrapper(authTokenRequest) {
@@ -70,11 +88,16 @@ async function getEcrPublicAuthTokenWrapper(authTokenRequest) {
7088
};
7189
}
7290

91+
function replaceSpecialCharacters(registryUri) {
92+
return registryUri.replace(/[^a-zA-Z0-9_]+/g, '_');
93+
}
94+
7395
async function run() {
7496
// Get inputs
7597
const skipLogout = core.getInput(INPUTS.skipLogout, { required: false }).toLowerCase() === 'true';
7698
const registries = core.getInput(INPUTS.registries, { required: false });
7799
const registryType = core.getInput(INPUTS.registryType, { required: false }).toLowerCase() || REGISTRY_TYPES.private;
100+
const httpProxy = core.getInput(INPUTS.httpProxy, { required: false });
78101

79102
const registryUriState = [];
80103

@@ -83,6 +106,9 @@ async function run() {
83106
throw new Error(`Invalid input for '${INPUTS.registryType}', possible options are [${REGISTRY_TYPES.private}, ${REGISTRY_TYPES.public}]`);
84107
}
85108

109+
// Configures proxy
110+
configureProxy(httpProxy);
111+
86112
// Get the ECR/ECR Public authorization token(s)
87113
const authTokenRequest = {};
88114
if (registryType === REGISTRY_TYPES.private && registries) {

0 commit comments

Comments
 (0)