File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,19 @@ 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 5m ;
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
+ end
33
+ }
23
34
24
35
#https://docs.docker.com/registry/recipes/nginx/#setting-things-up
25
36
map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
@@ -29,6 +40,10 @@ http {
29
40
server {
30
41
listen PORT SSL_LISTEN default_server ;
31
42
43
+ set_by_lua_block $http_authorization {
44
+ return ngx.shared.token_dict:get("ecr_token" )
45
+ }
46
+
32
47
SSL_INCLUDE
33
48
34
49
# Cache
Original file line number Diff line number Diff line change 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
+ set +x
9
10
# retry till new get new token
10
11
while true ; do
11
12
TOKEN=$( aws ecr get-login --no-include-email | awk ' {print $6}' )
17
18
18
19
AUTH_N=$( echo AWS:${TOKEN} | base64 | tr -d " [:space:]" )
19
20
20
- sed -i " s|${AUTH% ??} |${AUTH_N} |g" $CONFIG
21
+ echo $AUTH_N > /usr/local/openresty/nginx/token.txt
22
+ set -x
21
23
22
24
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
83
TOKEN=$( aws ecr get-login --no-include-email | awk ' {print $6}' )
83
84
AUTH_N=$( echo AWS:${TOKEN} | base64 | tr -d " [:space:]" )
84
- sed -i " s| ${AUTH % ??} | ${ AUTH_N} |g " $CONFIG
85
+ echo $ AUTH_N > /usr/local/openresty/nginx/token.txt
85
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