Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Varnish cache_file name is optional #8

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

LABEL maintainer="Donald Gray <[email protected]>"
LABEL org.opencontainers.image.source=https://github.com/dlcs/dlcs-varnish
Expand All @@ -7,13 +7,13 @@ LABEL org.opencontainers.image.description="Varnish on Ubuntu, vcl sourced from
RUN apt-get update -y && apt-get install -y varnish python3-pip
RUN pip install awscli

COPY start.sh /start.sh
RUN chmod +x /start.sh

WORKDIR /usr/app/src
COPY varnish-cleanup/requirements.txt ./
RUN pip install -r requirements.txt

COPY start.sh /start.sh
RUN chmod +x /start.sh

COPY varnish-cleanup/cleanup_handler.py ./
COPY varnish-cleanup/app ./app

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ The following environment settings are expected:
* `VARNISH_CACHE_FOLDER` - Folder where disk backed cache is stored.
* `VARNISH_CACHE_SIZE` - Size of cache.
* `AWS_PROFILE` - Required to run locally
* `INCOMING_QUEUE` - the name of the queue that the cleanup handler listens to

The following configuration is optional:

* `VARNISH_CACHE_FILE` - The name of varnish [storage file](https://varnish-cache.org/docs/trunk/users-guide/storage-backends.html#file) (e.g. `varnish_cache.bin`). If specified it is appended to `VARNISH_CACHE_FOLDER` to create file (if unspecified folder only is used)
* `INCOMING_QUEUE` - the name of the queue that the cleanup handler listens to
* `VARNISH_ADDRESS` - The location of varnish used by the cleanup handler. Defaults to localhost
* `AWS_REGION` - The AWS region. Defaults to eu-west-1
* `USE_LOCAL_CONFIG` - Whether to use a local config file over S3.
Expand All @@ -34,14 +35,14 @@ docker run -it --rm \
--env VARNISH_CACHE_SIZE='100M' \
--env-file='/path/to/env' \
{REQUIRED FOR LOCAL RUNNING}--volume $HOME\.aws\credentials:/root/.aws/credentials:ro \
{OPTIONAL}--mount type=bind,source=.\etc\default.vcl,target=/mnt/varnish/default.vcl \
{OPTIONAL}--volume ./etc/:/mnt/varnish/ \
dlcs-varnish:local
```
# varnish-cleanup
## varnish-cleanup

Additionally, there is a standalone docker container for the cleanup handler.

## Configuration
### Configuration

Required:
* `AWS_PROFILE` - Required to run locally
Expand Down
15 changes: 10 additions & 5 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ RELOAD_VCL=1

mkdir -p ${VARNISH_CACHE_FOLDER}

varnishd -a 0.0.0.0:${VARNISH_PORT} -T 127.0.0.1:6082 -f /etc/varnish/default.vcl -s file,${VARNISH_CACHE_FOLDER}/varnish_cache.bin,${VARNISH_CACHE_SIZE}
varnishd -a 0.0.0.0:${VARNISH_PORT} -T 127.0.0.1:6082 -f /etc/varnish/default.vcl -s file,${VARNISH_CACHE_FOLDER}/${VARNISH_CACHE_FILE},${VARNISH_CACHE_SIZE}

varnishlog &

# Start varnish cleanup

python3 /usr/app/src/cleanup_handler.py
if [ -z "$INCOMING_QUEUE" ]
then
echo 'no queue monitoring'
varnishlog
else
# Start varnish cleanup
varnishlog &
python3 /usr/app/src/cleanup_handler.py
fi
1 change: 0 additions & 1 deletion varnish-cleanup/app/aws_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import boto3
from moto import sqs

from app.settings import LOCALSTACK, REGION, LOCALSTACK_ADDRESS
from logzero import logger
Expand Down
Binary file modified varnish-cleanup/requirements.txt
Binary file not shown.
4 changes: 4 additions & 0 deletions varnish-cleanup/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mock==5.1.0
moto==4.1.14
pytest==7.4.0
requests-mock==1.11.0
Loading