Add an action to check the cache_control #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cache-Control Test | |
on: | |
push: | |
branches: | |
- feature/proxy-cache | |
workflow_dispatch: | |
jobs: | |
test-cache-control: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create configuration files | |
run: | | |
cat <<EOF > install/docker/config/nginx/test_cache.conf | |
server { | |
listen 8092; | |
location / { | |
default_type text/plain; | |
content_by_lua_block { | |
local args = ngx.req.get_uri_args() | |
local cache_control = args["cache_control"] | |
if cache_control then | |
ngx.header["Cache-Control"] = cache_control | |
ngx.say("Cache-Control set to: ", cache_control) | |
else | |
ngx.say("Cache-Control not specified. Use ?cache_control=<value> to set one.") | |
end | |
} | |
} | |
} | |
EOF | |
cat <<EOF > install/docker/router.yml | |
services: | |
onlyoffice-router: | |
image: openresty/openresty:latest | |
container_name: onlyoffice-router | |
restart: always | |
ports: | |
- "8092:8092" | |
volumes: | |
- ./config/nginx/test_cache.conf:/etc/nginx/conf.d/default.conf | |
networks: | |
default: | |
name: \${NETWORK_NAME} | |
external: true | |
EOF | |
- name: Run Docker containers and script | |
run: | | |
docker network create onlyoffice | |
docker-compose -f install/docker/proxy.yml up -d | |
docker-compose -f install/docker/router.yml up -d | |
- name: Wait for containers to become ready | |
run: | | |
echo "Waiting for containers to become ready..." | |
bash -c 'until curl -s http://localhost:80; do sleep 1; done' | |
bash -c 'until curl -s http://localhost:8092; do sleep 1; done' | |
- name: Execute testing script | |
run: | | |
CACHE_CONTROLS=( | |
"no-cache" | |
"no-store" | |
"public" | |
"private" | |
"max-age=0" | |
"max-age=60" | |
"s-maxage=60" | |
"max-age=3600" | |
"must-revalidate" | |
"proxy-revalidate" | |
"max-age=120,must-revalidate" | |
"no-cache,no-store" | |
"public,max-age=60" | |
"private,max-age=120" | |
"immutable" | |
"public,s-maxage=60,max-age=30" | |
"no-cache,max-age=0" | |
"private,no-cache" | |
"public,no-transform" | |
"no-store,must-revalidate,max-age=0" | |
"public,max-age=0" | |
"private,s-maxage=60" | |
"no-cache,max-age=30" | |
"immutable,max-age=3600" | |
"no-store,s-maxage=120" | |
"max-age=300,must-revalidate" | |
"proxy-revalidate,max-age=600" | |
"no-transform,max-age=900" | |
"public,no-cache" | |
"private,no-store" | |
"must-revalidate,max-age=1200" | |
"proxy-revalidate,s-maxage=150" | |
"no-cache,no-store,max-age=0" | |
"public,immutable,max-age=31536000" | |
"private,max-age=60,must-revalidate" | |
"public,max-age=120,proxy-revalidate" | |
"no-store,no-cache,must-revalidate,max-age=0" | |
"private,immutable,s-maxage=43200" | |
"public,no-transform,s-maxage=60,max-age=30" | |
"max-age=60,no-transform,must-revalidate" | |
) | |
HITS=() | |
MISSES=() | |
for CC in "${CACHE_CONTROLS[@]}"; do | |
curl -s -I "http://localhost/?cache_control=${CC}" > /dev/null | |
if $(curl -s -I "http://localhost/?cache_control=${CC}" | grep "X-Cache-Status" | grep -q "HIT"); then | |
HITS+=("$CC") | |
else | |
MISSES+=("$CC") | |
fi | |
done | |
echo "Cache-Control directives that resulted in a HIT:" | |
for HIT in "${HITS[@]}"; do | |
echo "- $HIT" | |
done | |
echo "-----------------------------------" | |
echo "Cache-Control directives that resulted in a MISS:" | |
for MISS in "${MISSES[@]}"; do | |
echo "- $MISS" | |
done |