File tree 3 files changed +28
-9
lines changed
3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,21 @@ http {
18
18
# this is necessary for us to be able to disable request buffering in all cases
19
19
proxy_http_version 1.1 ;
20
20
21
+ lua_shared_dict token_dict 1m ;
22
+
21
23
# will run before forking out nginx worker processes
22
- init_by_lua_block { require "cjson" }
24
+ init_by_lua_block {
25
+ require "cjson"
26
+
27
+ local token_file = io.open('/usr/local/openresty/nginx/token.txt' , 'r' )
28
+ if token_file then
29
+ local data = token_file:read()
30
+ ngx.shared.token_dict:set ("ecr_token" , data)
31
+ token_file:close()
32
+ else
33
+ ngx.log(ngx.ERR, "Failed to open token file: /usr/local/openresty/nginx/token.txt" )
34
+ end
35
+ }
23
36
24
37
#https://docs.docker.com/registry/recipes/nginx/#setting-things-up
25
38
map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
@@ -29,6 +42,10 @@ http {
29
42
server {
30
43
listen PORT SSL_LISTEN default_server ;
31
44
45
+ set_by_lua_block $http_authorization {
46
+ return ngx.shared.token_dict:get("ecr_token" )
47
+ }
48
+
32
49
SSL_INCLUDE
33
50
34
51
# Cache
Original file line number Diff line number Diff line change @@ -6,17 +6,17 @@ set -xe
6
6
CONFIG=/usr/local/openresty/nginx/conf/nginx.conf
7
7
AUTH=$( grep X-Forwarded-User $CONFIG | awk ' {print $4}' | uniq| tr -d " \n\r" )
8
8
9
+
9
10
# retry till new get new token
10
11
while true ; do
11
- TOKEN=$( aws ecr get-login --no-include-email | awk ' {print $6} ' )
12
+ TOKEN=$( aws ecr get-authorization-token --query ' authorizationData[*].authorizationToken ' --output text )
12
13
[ ! -z " ${TOKEN} " ] && break
13
14
echo " Warn: Unable to get new token, wait and retry!"
14
15
sleep 30
15
16
done
16
17
17
-
18
- AUTH_N=$( echo AWS:${TOKEN} | base64 | tr -d " [:space:]" )
19
-
20
- sed -i " s|${AUTH% ??} |${AUTH_N} |g" $CONFIG
18
+ set +x
19
+ echo $TOKEN > /usr/local/openresty/nginx/token.txt
20
+ set -x
21
21
22
22
nginx -s reload
Original file line number Diff line number Diff line change @@ -77,12 +77,14 @@ if [ -z "$AWS_USE_EC2_ROLE_FOR_AUTH" ] || [ "$AWS_USE_EC2_ROLE_FOR_AUTH" != "tru
77
77
fi
78
78
chmod 600 -R ${AWS_FOLDER}
79
79
80
+ set +x
80
81
# add the auth token in default.conf
81
82
AUTH=$( grep X-Forwarded-User $CONFIG | awk ' {print $4}' | uniq| tr -d " \n\r" )
82
- TOKEN=$( aws ecr get-login --no-include-email | awk ' {print $6}' )
83
- AUTH_N=$( echo AWS:${TOKEN} | base64 | tr -d " [:space:]" )
84
- sed -i " s|${AUTH% ??} |${AUTH_N} |g" $CONFIG
83
+ TOKEN=$( aws ecr get-authorization-token --query ' authorizationData[*].authorizationToken' --output text)
85
84
85
+ echo $TOKEN > /usr/local/openresty/nginx/token.txt
86
+
87
+ set -x
86
88
# make sure cache directory has correct ownership
87
89
chown -R nginx:nginx /cache
88
90
You can’t perform that action at this time.
0 commit comments