|
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 | + # will run before forking out nginx worker processes |
| 22 | + init_by_lua_block { require "cjson" } |
| 23 | + |
21 | 24 | server {
|
22 | 25 | listen PORT default_server;
|
23 | 26 |
|
@@ -55,12 +58,6 @@ http {
|
55 | 58 | proxy_set_header Authorization "Basic $http_authorization";
|
56 | 59 | proxy_set_header X-Forwarded-Proto $scheme;
|
57 | 60 |
|
58 |
| - # make Link header relative by stripping the https://<host> part from it. |
59 |
| - header_filter_by_lua_block { |
60 |
| - if ngx.header["Link"] ~= nil then |
61 |
| - ngx.header["Link"] = ngx.header["Link"]:gsub("https?://[^/]+", "") |
62 |
| - end |
63 |
| - } |
64 | 61 | }
|
65 | 62 |
|
66 | 63 | # Content addressable files like blobs.
|
@@ -97,5 +94,48 @@ http {
|
97 | 94 | http_500 http_502 http_503 http_504;
|
98 | 95 | proxy_cache_lock on;
|
99 | 96 | }
|
| 97 | + |
| 98 | + location ~ ^/v2/.*/.*/tags/list+$ { |
| 99 | + # get paginated list of tags |
| 100 | + content_by_lua_block { |
| 101 | + local location, tags, cjson = ngx.var.uri, {}, require "cjson" |
| 102 | + while true do |
| 103 | + local res = ngx.location.capture("/get_tags", |
| 104 | + { args = { req_uri = location } } |
| 105 | + ) |
| 106 | + if res.status == ngx.HTTP_NOT_FOUND and table.getn(tags) == 0 then |
| 107 | + ngx.status = ngx.HTTP_NOT_FOUND |
| 108 | + ngx.print(res.body) |
| 109 | + ngx.exit(0) |
| 110 | + end |
| 111 | + local data = cjson.decode(res.body) |
| 112 | + for _,v in ipairs(data['tags']) do |
| 113 | + table.insert(tags, v) |
| 114 | + end |
| 115 | + if res.header["Link"] ~= nil then |
| 116 | + location = res.header["Link"]:match("/v2[^>]+") |
| 117 | + else |
| 118 | + ngx.print(cjson.encode{name = data['name'], tags = tags }) |
| 119 | + ngx.exit(ngx.HTTP_OK) |
| 120 | + end |
| 121 | + end |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + # Helper location for getting tags from upstream repository |
| 126 | + # used for getting paginated tags. |
| 127 | + location /get_tags { |
| 128 | + internal; |
| 129 | + set_unescape_uri $req_uri $arg_req_uri; |
| 130 | + proxy_pass UPSTREAM$req_uri; |
| 131 | + |
| 132 | + # Add AWS ECR authentication headers |
| 133 | + proxy_set_header X-Real-IP $remote_addr; |
| 134 | + proxy_set_header X-Forwarded-For $remote_addr; |
| 135 | + proxy_set_header X-Forwarded-User "Basic $http_authorization"; |
| 136 | + proxy_set_header Authorization "Basic $http_authorization"; |
| 137 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 138 | + |
| 139 | + } |
100 | 140 | }
|
101 | 141 | }
|
0 commit comments