Skip to content

Commit

Permalink
Make packages.json expiry configurable through `*_PACKAGES_JSON_EXP…
Browse files Browse the repository at this point in the history
…IRY`
  • Loading branch information
gmta committed Oct 6, 2022
1 parent 16bcc34 commit 44dc23b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MIRROR_PACKAGIST_TYPE=composer
#MIRROR_PACKAGIST_CACHE_EXPIRY=3650d
#MIRROR_PACKAGIST_CACHE_SIZE=1g
#MIRROR_PACKAGIST_ALLOW_REVALIDATE=false
#MIRROR_PACKAGIST_PACKAGES_JSON_EXPIRY=2m
#MIRROR_PACKAGIST_AUTH_TYPE=basic
#MIRROR_PACKAGIST_AUTH_USERNAME=
#MIRROR_PACKAGIST_AUTH_PASSWORD=
Expand Down
23 changes: 12 additions & 11 deletions proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ docker run -d --name velocita -p 80:8080 \

For every mirror, the following configuration options are available:

| Environment variable | Required | Type | Description |
| -------------------------------- | -------- | -------------------------------------- | --------------------------------------- |
| `MIRROR_{name}_URL` | Yes | URL | The URL of the upstream server to proxy |
| `MIRROR_{name}_TYPE` | No | One of: `simple` (default), `composer` | The mirror type |
| `MIRROR_{name}_CACHE_EXPIRY` | No | Time (default: `3650d`) | Time after which cached items expire |
| `MIRROR_{name}_CACHE_SIZE` | No | Size (default: `1g`) | Maximum size of this mirror's cache |
| `MIRROR_{name}_ALLOW_REVALIDATE` | No | Boolean (default: `false`) | Allow revalidation of cached items |
| `MIRROR_{name}_AUTH_TYPE` | No | Always `basic` (default) | Type of upstream authentication |
| `MIRROR_{name}_AUTH_USERNAME` | No | String | Username for basic authentication |
| `MIRROR_{name}_AUTH_PASSWORD` | No | String | Password for basic authentication |
| `MIRROR_{name}_USER_AGENT` | No | String | User Agent header sent to upstream |
| Environment variable | Required | Type | Description |
| ------------------------------------ | -------- | -------------------------------------- | ---------------------------------------- |
| `MIRROR_{name}_URL` | Yes | URL | The URL of the upstream server to proxy |
| `MIRROR_{name}_TYPE` | No | One of: `simple` (default), `composer` | The mirror type |
| `MIRROR_{name}_CACHE_EXPIRY` | No | Time (default: `3650d`) | Time after which cached items expire |
| `MIRROR_{name}_CACHE_SIZE` | No | Size (default: `1g`) | Maximum size of this mirror's cache |
| `MIRROR_{name}_ALLOW_REVALIDATE` | No | Boolean (default: `false`) | Allow revalidation of cached items |
| `MIRROR_{name}_PACKAGES_JSON_EXPIRY` | No | Time (default: `2m`) | Time after which `packages.json` expires |
| `MIRROR_{name}_AUTH_TYPE` | No | Always `basic` (default) | Type of upstream authentication |
| `MIRROR_{name}_AUTH_USERNAME` | No | String | Username for basic authentication |
| `MIRROR_{name}_AUTH_PASSWORD` | No | String | Password for basic authentication |
| `MIRROR_{name}_USER_AGENT` | No | String | User Agent header sent to upstream |

For time and size unit syntax, see: http://nginx.org/en/docs/syntax.html

Expand Down
3 changes: 2 additions & 1 deletion proxy/templates/proxy.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ENV.keys.map { |key| key.to_s }
:url => url,
:cache => friendly_name,
:revalidate => ['true', '1', 'on', 'yes'].include?(ENV["MIRROR_#{name}_ALLOW_REVALIDATE"]),
:packages_json_expiry => ENV["MIRROR_#{name}_PACKAGES_JSON_EXPIRY"] || '2m',
:auth_type => ENV["MIRROR_#{name}_AUTH_TYPE"] || 'basic',
:auth_user => ENV["MIRROR_#{name}_AUTH_USERNAME"] || '',
:auth_pass => ENV["MIRROR_#{name}_AUTH_PASSWORD"] || '',
Expand Down Expand Up @@ -150,7 +151,7 @@ server {

location = /mirror/<%= mirror[:path] %>/packages.json {
proxy_pass <%= mirror[:url] %>packages.json;
proxy_cache_valid 200 2m;
proxy_cache_valid 200 <%= mirror[:packages_json_expiry] %>;
}
<%- end -%>
}
Expand Down

0 comments on commit 44dc23b

Please sign in to comment.