Skip to content

Commit 96463c1

Browse files
mhbahmanidekobon
andcommitted
feat: implement templating for the PROXY_CACHE_USE_STALE env var
Fixes #437 This change modifies the startup scripts to support the optional parameter `PROXY_CACHE_USE_STALE` which corresponds to the NGINX directive with the same name. When this environment variable is not set, a default is used. Signed-off-by: Elijah Zupancic <e.zupancic@f5.com> Co-Authored-By: Elijah Zupancic <e.zupancic@f5.com>
1 parent 6e2681f commit 96463c1

File tree

8 files changed

+53
-37
lines changed

8 files changed

+53
-37
lines changed

common/docker-entrypoint.d/00-check-for-required-env.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ failed=0
2424

2525
required=("S3_BUCKET_NAME" "S3_SERVER" "S3_SERVER_PORT" "S3_SERVER_PROTO"
2626
"S3_REGION" "S3_STYLE" "ALLOW_DIRECTORY_LIST" "AWS_SIGS_VERSION"
27-
"CORS_ENABLED")
27+
"CORS_ENABLED" "PROXY_CACHE_USE_STALE")
2828

2929
# Require some form of authentication to be configured.
3030

@@ -44,7 +44,7 @@ elif [[ -v AWS_SESSION_TOKEN ]]; then
4444
# b) Using Instance Metadata Service (IMDS) credentials, if IMDS is present at http://169.254.169.254.
4545
# See https://docs.aws.amazon.com/sdkref/latest/guide/feature-imds-credentials.html.
4646
# Example: We are running inside an EC2 instance.
47-
elif TOKEN=`curl -X PUT --silent --fail --connect-timeout 2 --max-time 2 "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" --output /dev/null --silent --head --fail --connect-timeout 2 --max-time 5 "http://169.254.169.254"; then
47+
elif TOKEN=`curl -X PUT --silent --fail --connect-timeout 2 --max-time 2 "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" --output /dev/null --silent --head --fail --connect-timeout 2 --max-time 5 "http://169.254.169.254"; then
4848
echo "Running inside an EC2 instance, using IMDS for credentials"
4949

5050
# c) Using assume role credentials. This is indicated by AWS_WEB_IDENTITY_TOKEN_FILE being set.
@@ -126,6 +126,10 @@ if [ -n "${HEADER_PREFIXES_TO_STRIP+x}" ]; then
126126
fi
127127
fi
128128

129+
if [[ ! "${PROXY_CACHE_USE_STALE}" ]]; then
130+
>&2 echo "PROXY_CACHE_USE_STALE must not be blank"
131+
failed=1
132+
fi
129133

130134
if [ $failed -gt 0 ]; then
131135
exit 1
@@ -144,6 +148,7 @@ echo "Directory Listing Path Prefix: ${DIRECTORY_LISTING_PATH_PREFIX}"
144148
echo "Provide Index Pages Enabled: ${PROVIDE_INDEX_PAGE}"
145149
echo "Append slash for directory enabled: ${APPEND_SLASH_FOR_POSSIBLE_DIRECTORY}"
146150
echo "Stripping the following headers from responses: x-amz-;${HEADER_PREFIXES_TO_STRIP}"
147-
echo "Allow the following headers from responses (these take precendence over the above): ${HEADER_PREFIXES_ALLOWED}"
151+
echo "Allow the following headers from responses (these take precedence over the above): ${HEADER_PREFIXES_ALLOWED}"
148152
echo "CORS Enabled: ${CORS_ENABLED}"
149153
echo "CORS Allow Private Network Access: ${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}"
154+
echo "Proxy cache using stale setting: ${PROXY_CACHE_USE_STALE}"

common/docker-entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fi
7171
# See documentation for this feature. We do not parse this as a boolean
7272
# since "true" and "false" are the required values of the header this populates
7373
if [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}" != "true" ] && [ "${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}" != "false" ]; then
74-
export CORS_ALLOW_PRIVATE_NETWORK_ACCESS=""
74+
export CORS_ALLOW_PRIVATE_NETWORK_ACCESS=""
7575
fi
7676

7777
# This is the primary logic to determine the s3 host used for the
@@ -94,6 +94,10 @@ else
9494
export S3_HOST_HEADER="${S3_BUCKET_NAME}.${S3_SERVER}"
9595
fi
9696

97+
# Use default proxy_cache_use_stale settings if the variable is not defined
98+
if [[ ! -v PROXY_CACHE_USE_STALE ]]; then
99+
export PROXY_CACHE_USE_STALE="error timeout http_500 http_502 http_503 http_504"
100+
fi
97101

98102
# Nothing is modified under this line
99103

common/etc/nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ env PROXY_CACHE_VALID_OK;
3838
env PROXY_CACHE_SLICE_SIZE;
3939
env PROXY_CACHE_VALID_NOTFOUND;
4040
env PROXY_CACHE_VALID_FORBIDDEN;
41+
env PROXY_CACHE_USE_STALE;
4142
env HEADER_PREFIXES_TO_STRIP;
4243
env FOUR_O_FOUR_ON_EMPTY_BUCKET;
4344
env STRIP_LEADING_DIRECTORY_PATH;

common/etc/nginx/templates/default.conf.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ server {
5656
proxy_cache_revalidate on;
5757
proxy_cache_background_update on;
5858
proxy_cache_lock on;
59-
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
59+
proxy_cache_use_stale ${PROXY_CACHE_USE_STALE};
6060
proxy_cache_key "$request_method$host$uri";
6161

6262
# If you need to support proxying range request, refer to this article:

deployments/s3_express/settings.s3express.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ PROXY_CACHE_INACTIVE=60m
2020
PROXY_CACHE_VALID_OK=1h
2121
PROXY_CACHE_VALID_NOTFOUND=1m
2222
PROXY_CACHE_VALID_FORBIDDEN=30s
23+
PROXY_CACHE_USE_STALE='error timeout http_500 http_502 http_503 http_504'

docs/getting_started.md

Lines changed: 33 additions & 32 deletions
Large diffs are not rendered by default.

settings.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ PROXY_CACHE_INACTIVE=60m
2020
PROXY_CACHE_VALID_OK=1h
2121
PROXY_CACHE_VALID_NOTFOUND=1m
2222
PROXY_CACHE_VALID_FORBIDDEN=30s
23+
PROXY_CACHE_USE_STALE='error timeout http_500 http_502 http_503 http_504'
2324
STRIP_LEADING_DIRECTORY_PATH=/somepath

standalone_ubuntu_oss_install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ echo "Slice of slice for byte range requests: ${PROXY_CACHE_SLICE_SIZE}"
9696
echo "Proxy Caching Time for Valid Response: ${PROXY_CACHE_VALID_OK}"
9797
echo "Proxy Caching Time for Not Found Response: ${PROXY_CACHE_VALID_NOTFOUND}"
9898
echo "Proxy Caching Time for Forbidden Response: ${PROXY_CACHE_VALID_FORBIDDEN}"
99+
echo "Proxy Cache Using Stale: ${PROXY_CACHE_USE_STALE}"
99100
echo "CORS Enabled: ${CORS_ENABLED}"
100101
echo "CORS Allow Private Network Access: ${CORS_ALLOW_PRIVATE_NETWORK_ACCESS}"
101102

@@ -179,6 +180,8 @@ PROXY_CACHE_VALID_OK=${PROXY_CACHE_VALID_OK:-'1h'}
179180
PROXY_CACHE_VALID_NOTFOUND=${PROXY_CACHE_VALID_NOTFOUND:-'1m'}
180181
# Proxy caching time for response code 403
181182
PROXY_CACHE_VALID_FORBIDDEN=${PROXY_CACHE_VALID_FORBIDDEN:-'30s'}
183+
# Proxy cache using stale data when error occurs
184+
PROXY_CACHE_USE_STALE=${PROXY_CACHE_USE_STALE:-'error timeout http_500 http_502 http_503 http_504'}
182185
# Enables or disables CORS for the S3 Gateway (true=enabled, false=disabled)
183186
CORS_ENABLED=${CORS_ENABLED:-'false'}
184187
# Configure portion of URL to be removed (optional)

0 commit comments

Comments
 (0)