1
1
const core = require ( '@actions/core' ) ;
2
2
const exec = require ( '@actions/exec' ) ;
3
3
const aws = require ( 'aws-sdk' ) ;
4
+ const proxy = require ( 'https-proxy-agent' ) ;
4
5
5
6
const ECR_LOGIN_GITHUB_ACTION_USER_AGENT = 'amazon-ecr-login-for-github-actions' ;
6
7
const ECR_PUBLIC_REGISTRY_URI = 'public.ecr.aws' ;
7
8
8
9
const INPUTS = {
9
10
skipLogout : 'skip-logout' ,
10
11
registries : 'registries' ,
11
- registryType : 'registry-type'
12
+ registryType : 'registry-type' ,
13
+ httpProxy : 'http-proxy'
12
14
} ;
13
15
14
16
const OUTPUTS = {
@@ -27,8 +29,24 @@ const REGISTRY_TYPES = {
27
29
} ;
28
30
29
31
30
- function replaceSpecialCharacters ( registryUri ) {
31
- return registryUri . replace ( / [ ^ a - z A - Z 0 - 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
+ }
32
50
}
33
51
34
52
async function getEcrAuthTokenWrapper ( authTokenRequest ) {
@@ -70,11 +88,16 @@ async function getEcrPublicAuthTokenWrapper(authTokenRequest) {
70
88
} ;
71
89
}
72
90
91
+ function replaceSpecialCharacters ( registryUri ) {
92
+ return registryUri . replace ( / [ ^ a - z A - Z 0 - 9 _ ] + / g, '_' ) ;
93
+ }
94
+
73
95
async function run ( ) {
74
96
// Get inputs
75
97
const skipLogout = core . getInput ( INPUTS . skipLogout , { required : false } ) . toLowerCase ( ) === 'true' ;
76
98
const registries = core . getInput ( INPUTS . registries , { required : false } ) ;
77
99
const registryType = core . getInput ( INPUTS . registryType , { required : false } ) . toLowerCase ( ) || REGISTRY_TYPES . private ;
100
+ const httpProxy = core . getInput ( INPUTS . httpProxy , { required : false } ) ;
78
101
79
102
const registryUriState = [ ] ;
80
103
@@ -83,6 +106,9 @@ async function run() {
83
106
throw new Error ( `Invalid input for '${ INPUTS . registryType } ', possible options are [${ REGISTRY_TYPES . private } , ${ REGISTRY_TYPES . public } ]` ) ;
84
107
}
85
108
109
+ // Configures proxy
110
+ configureProxy ( httpProxy ) ;
111
+
86
112
// Get the ECR/ECR Public authorization token(s)
87
113
const authTokenRequest = { } ;
88
114
if ( registryType === REGISTRY_TYPES . private && registries ) {
0 commit comments