diff --git a/Dockerfile b/Dockerfile index 2fca67d..88ac1d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 LABEL maintainer="Donald Gray " LABEL org.opencontainers.image.source=https://github.com/dlcs/dlcs-varnish @@ -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 diff --git a/README.md b/README.md index 7dfcae4..43b9a55 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/start.sh b/start.sh index 391e6f2..d3221b1 100755 --- a/start.sh +++ b/start.sh @@ -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 \ No newline at end of file diff --git a/varnish-cleanup/app/aws_factory.py b/varnish-cleanup/app/aws_factory.py index f8564ed..84c49ff 100644 --- a/varnish-cleanup/app/aws_factory.py +++ b/varnish-cleanup/app/aws_factory.py @@ -1,5 +1,4 @@ import boto3 -from moto import sqs from app.settings import LOCALSTACK, REGION, LOCALSTACK_ADDRESS from logzero import logger diff --git a/varnish-cleanup/requirements.txt b/varnish-cleanup/requirements.txt index 9da4e97..488c9ff 100644 Binary files a/varnish-cleanup/requirements.txt and b/varnish-cleanup/requirements.txt differ diff --git a/varnish-cleanup/test_requirements.txt b/varnish-cleanup/test_requirements.txt new file mode 100644 index 0000000..87033fd --- /dev/null +++ b/varnish-cleanup/test_requirements.txt @@ -0,0 +1,4 @@ +mock==5.1.0 +moto==4.1.14 +pytest==7.4.0 +requests-mock==1.11.0