Initial commit

This commit is contained in:
dpedu 2015-09-05 20:37:34 -07:00
commit 66d863906e
6 changed files with 101 additions and 0 deletions

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM ubuntu:trusty
ADD start /start
RUN chmod +x /start ;\
locale-gen en_US en_US.UTF-8 ;\
apt-get update ;\
apt-get install -y apt-transport-https curl supervisor inotify-tools ;\
curl https://repo.varnish-cache.org/ubuntu/GPG-key.txt | apt-key add - ;\
echo "deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.0" >> /etc/apt/sources.list.d/varnish-cache.list ;\
apt-get update ;\
DEBIAN_FRONTEND=noninteractive apt-get install -y varnish ;\
rm /etc/varnish/secret
ADD varnish.conf /etc/supervisor/conf.d/varnish.conf
ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf
WORKDIR /etc/varnish
CMD ["/start"]
EXPOSE 80 6082

19
README.md Normal file
View File

@ -0,0 +1,19 @@
docker-varnish
==============
Container for running [Varnish Cache](https://www.varnish-cache.org/). Automatically checks vcl validity before running varnish and reports compile errors in stdout.
*Usage:*
* Build: `docker build -t varnish .`
* Run: `docker run -d -v /my/test.vcl:/etc/varnish/default.vcl -p 80:80 varnish`
*Advanced*
* Set memory size: `docker run` with `-e MEMSIZE=128m`
* Use pre-set secret: `-e SECRET=7d40f8f1-9107-4cce-a2b6-f5caf6fc7b9d`
* Expose control terminal: `-p 1234:6082`
*Extras*
* test.vcl - example default.vcl file

20
start Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# Cleanly kill supervisor when container is stopped
trap 'kill $(jobs -p)' EXIT
if [ -z "$MEMSIZE" ]; then
export MEMSIZE=64M
fi
if [ ! -f /etc/varnish/secret ]; then
if [ -z "$SECRET" ]; then
SECRET=`cat /proc/sys/kernel/random/uuid`
fi
echo $SECRET > /etc/varnish/secret
fi
echo "Secret is `cat /etc/varnish/secret`"
varnishd -C -f /etc/varnish/default.vcl > /dev/null || exit 1
supervisord

2
supervisor.conf Normal file
View File

@ -0,0 +1,2 @@
[supervisord]
nodaemon=true

34
test.vcl Normal file
View File

@ -0,0 +1,34 @@
vcl 4.0;
import std;
import directors;
backend default {
.host = "dpedu.io";
.port = "80";
}
# Setup function
sub vcl_init {
new default_balancer = directors.round_robin();
default_balancer.add_backend(default);
}
sub vcl_recv {
# If X-Real-IP is unset, assume we are talking directly to the client
if (!req.http.X-Real-IP) {
set req.http.X-Real-IP = client.ip;
}
# Set backend to handle request
set req.backend_hint = default_balancer.backend();
set req.http.host = "dpedu.io";
# Disabled cookies for static assets
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") {
unset req.http.Cookie;
# return cache for object
return (pass);
}
return (pass);
}

5
varnish.conf Normal file
View File

@ -0,0 +1,5 @@
[program:varnishd]
command=/usr/sbin/varnishd -f /etc/varnish/default.vcl -a 0.0.0.0:80 -T 0.0.0.0:6082 -S /etc/varnish/secret -s malloc,%(ENV_MEMSIZE)s -F
autostart=true
autorestart=true
redirect_stderr=true