From a18b2450f8c8b6bd8106baecf0b0fb43aeffa9fd Mon Sep 17 00:00:00 2001 From: Donald Gray Date: Wed, 8 May 2024 15:51:42 +0100 Subject: [PATCH 1/4] All varnish to set varnish file name --- Dockerfile | 6 +++--- README.md | 3 ++- start.sh | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2fca67d..1d3008c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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..e143aa0 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. 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 From 8a8004f0eeb1877abde243764aa56348ad039104 Mon Sep 17 00:00:00 2001 From: Donald Gray Date: Wed, 8 May 2024 17:43:36 +0100 Subject: [PATCH 2/4] Update deps, running into s3 exceptions --- Dockerfile | 2 +- varnish-cleanup/requirements.txt | Bin 1150 -> 577 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1d3008c..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 diff --git a/varnish-cleanup/requirements.txt b/varnish-cleanup/requirements.txt index 9da4e97556cc8cfc2e5fc4a06027deab5f79c642..6098ef25812a6c53fddea8ca8d163cc905afb810 100644 GIT binary patch literal 577 zcmY+CPjB2H5XJBFU3O%^@g@fjQEpWuRqCPYk!7)$T^k7CD$b|x!>dTi&GUyhzc=Gk ztWjw#SoJKrj!uYe%vgqRmI`wy43RxG(A z8|RqKVzlnK=K=9Qm(2umsPK_&-cpTIHtDiy-3#tm(aTmZF*Jz|5@*n)+5`rc3N0sKV&0V*%3e*gdg literal 1150 zcmaKsPfx;75XAS)cY)A?s0RCc)6aTqt%MSX=-E=A1XH1GwI@QUOBZ= z-^7Cpoaouw-Wpe4I!YrJd(RuYHqb`OywK@Jv0A(m3u3T%)G5w@lNd}CL+@PCs$&N8 zv7c2sr=oH%O0Nn{fq1ESWiP7B58YxWJ)N$kWUX#fXGBM0u*rmuA7$rP?bSq44cBW` zwYIRW>TmV?sdI(y`RX!d~h#*G>QV4-kF0Nq63V;d{lTm|^IT fo3@kMrTW%#nce=r37HT>_1 Date: Thu, 9 May 2024 14:36:48 +0100 Subject: [PATCH 3/4] Move test deps to diff requirements.txt --- README.md | 6 +++--- varnish-cleanup/requirements.txt | 4 ---- varnish-cleanup/test_requirements.txt | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 varnish-cleanup/test_requirements.txt diff --git a/README.md b/README.md index e143aa0..43b9a55 100644 --- a/README.md +++ b/README.md @@ -35,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/varnish-cleanup/requirements.txt b/varnish-cleanup/requirements.txt index 6098ef2..488c9ff 100644 --- a/varnish-cleanup/requirements.txt +++ b/varnish-cleanup/requirements.txt @@ -14,17 +14,13 @@ Jinja2==3.1.2 jmespath==1.0.1 logzero==1.7.0 MarkupSafe==2.1.3 -mock==5.1.0 -moto==4.1.14 packaging==23.1 pipreqs==0.4.13 pluggy==1.2.0 pycparser==2.21 -pytest==7.4.0 python-dateutil==2.8.2 PyYAML==6.0.1 requests==2.31.0 -requests-mock==1.11.0 responses==0.23.3 s3transfer==0.10.1 six==1.16.0 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 From 663807ff40c7ed527005c17a7b3542d60cd0625d Mon Sep 17 00:00:00 2001 From: Donald Gray Date: Thu, 9 May 2024 15:23:14 +0100 Subject: [PATCH 4/4] Remove unused import that relied on moto --- varnish-cleanup/app/aws_factory.py | 1 - 1 file changed, 1 deletion(-) 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