Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas Molnar committed Apr 14, 2017
0 parents commit 84ebfcf
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
*.iml
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Starting from Ubuntu and not from alpine, as libvmod-dynamic used for generating dynamic backends
# compiles currently only on debian based images.
FROM ubuntu:trusty

ENV VARNISHSRC=/usr/include/varnish VMODDIR=/usr/lib/varnish/vmods

RUN apt-get update -q && \
apt-get install -qq git curl apt-transport-https autotools-dev automake autoconf libtool python make python-docutils && \
curl https://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - && \
echo "deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.1" | tee /etc/apt/sources.list.d/varnish-cache.list && \
apt-get -q update && \
apt-get install -qq varnish varnish-dev && \
cd / && echo "-------mod-dynamic build -------" && \
git clone https://github.com/nigoroll/libvmod-dynamic.git && \
cd libvmod-dynamic && \
./autogen.sh && \
./configure && \
make && \
make install && \
apt-get remove -qq git curl apt-transport-https autotools-dev automake autoconf libtool python make python-docutils && \
apt-get -qq autoremove && \
apt-get -qq clean && \
rm -rf /libvmod-dynamic

COPY default.vcl /etc/varnish/default.vcl
COPY start.sh /start.sh

RUN chmod +x /start.sh
EXPOSE 80
CMD ["/start.sh"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## UPP Publishing Cluster Path routing Varnish

The Publishing Varnish routing proxy placed after the publishing auth varnish.
Its role is to route traffic based on the context path in the URL to appropriate services.

See [default.vcl](/default.vcl) for the Varnish routing policies.
67 changes: 67 additions & 0 deletions default.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
vcl 4.0;

import dynamic;

# Dummy definitions as we're using dynamic backend declaration
backend default {
.host = "localhost";
.port = "8888";
}

sub vcl_init {
new dynBackend = dynamic.director(port = "8080");
}

acl purge {
"localhost";
}

sub vcl_recv {

# allow PURGE from localhost
if (req.method == "PURGE") {
if (!client.ip ~ purge) {
return(synth(405,"Not allowed."));
}
return (purge);
}

# healthcheck
if (req.method == "GET" && req.url == "/status") {
return(synth(200, "OK"));
}

if (req.url ~ "^\/content.*$") {
set req.url = regsub(req.url, "content", "/notify");
set req.backend_hint = dynBackend.backend("cms-notifier");
}
elif (req.url ~ "^\/video.*$") {
set req.url = regsub(req.url, "video", "/notify");
set req.backend_hint = dynBackend.backend("cms-notifier");
}
eif (req.url ~ "^\/metadata.*$") {
set req.url = regsub(req.url, "metadata", "/notify");
set req.backend_hint = dynBackend.backend("cms-metadata-notifier");
}
elif (req.url ~ "\/notification\/wordpress.*$") {
set req.url = regsub(req.url, "notification\/wordpress", "/content");
set req.backend_hint = dynBackend.backend("wordpress-notifier");
}
elif (req.url ~ "\/notification\/brightcove\/content.*$") {
set req.url = regsub(req.url, "notification\/brightcove\/content", "/notify");
set req.backend_hint = dynBackend.backend("brightcove-notifier");
}
elif (req.url ~ "\/notification\/brightcove\/metadata.*$") {
set req.url = regsub(req.url, "notification\/brightcove\/metadata", "/notify");
set req.backend_hint = dynBackend.backend("brightcove-metadata-preprocessor");
}
elif (req.url ~ "^\/__[\w-]*\/.*$") {
# create a new backend dynamically to match the requested URL that will be looked up in the Kubernetes DNS.
# For example calling the URL /__content-ingester/xyz will forward the request to the service content-ingester with the url /xyz
set req.backend_hint = dynBackend.backend(regsub(req.url, "^\/__([\w-]*)\/.*$", "\1"));
set req.url = regsub(req.url, "^\/__[\w-]*\/(.*)$", "/\1");
set req.http.X-VarnishPassThrough = "true";
}

return (pipe);
}
29 changes: 29 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh


shutdown() {
log "Stopping"
pkill varnishd
log "Stopped varnishd $?"
pkill varnishncsa
log "Stopped varnishncsa $?"
exit 0
}

log() {
echo "`date +'%F %T'` $1"
}

trap 'shutdown' HUP INT QUIT KILL TERM


# Start varnish and log
log "Starting"
varnishd -f /etc/varnish/default.vcl -s malloc,1024m -t 5 -p default_grace=0 &
sleep 4

varnishncsa -F '%{X-Forwarded-For}i %u %{%d/%b/%Y:%T}t %U%q %s %D "%{User-Agent}i" %{Varnish:handling}x' &
log "Started"

# Wait for the process to finish
wait ${!}

0 comments on commit 84ebfcf

Please sign in to comment.