Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmakarov committed Oct 12, 2016
2 parents 125649d + ee3f515 commit b331c0d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FROM alpine:3.3
FROM alpine:3.4

MAINTAINER Leonid Makarov <leonid.makarov@blinkreaction.com>
MAINTAINER Leonid Makarov <leonid.makarov@ffwagency.com>

RUN apk add --update \
ca-certificates \
RUN apk add --no-cache \
curl \
supervisor \
dnsmasq \

&& rm -rf /var/cache/apk/*

# Install docker-gen
ENV DOCKER_GEN_VERSION 0.7.1
RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz && \
tar -C /usr/local/bin -xvzf docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz && \
rm /docker-gen-linux-i386-$DOCKER_GEN_VERSION.tar.gz
ENV DOCKER_GEN_VERSION 0.7.3
ENV DOCKER_GEN_TARFILE docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
RUN curl -sSL https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/$DOCKER_GEN_TARFILE -O && \
tar -C /usr/local/bin -xvzf $DOCKER_GEN_TARFILE && \
rm $DOCKER_GEN_TARFILE

# dnsmasq config dir
RUN mkdir -p /etc/dnsmasq.d && \
Expand All @@ -23,12 +23,11 @@ COPY conf/dnsmasq.tmpl /etc/dnsmasq.d/dockergen.tmpl
COPY conf/supervisord.conf /etc/supervisor.d/docker-gen.ini
COPY entrypoint.sh /opt/entrypoint.sh

# Default IP for Drude
ENV DRUDE_IP '192.168.10.10'
# Default domain and IP for wildcard query resolution
ENV DNS_DOMAIN 'docksal'
ENV DNS_IP '192.168.64.100'
ENV LOG_QUERIES false
ENV DOCKER_HOST unix:///var/run/docker.sock

VOLUME /var/run
EXPOSE 53/udp

ENTRYPOINT ["/opt/entrypoint.sh"]
Expand Down
31 changes: 18 additions & 13 deletions conf/dnsmasq.tmpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{{ range $host, $containers := groupByMulti $ "Env.DOMAIN_NAME" "," }}
{{ range $index, $container := $containers }}
{{ $addrLen := len $container.Addresses }}
{{ $address := $container }}
{{ if gt $addrLen 0 }}
{{ $address := index $container.Addresses 0 }}
{{/* template */}}
{{ define "host" }}
{{ $host := .Host }}
{{ range $index, $network := .Container.Networks }}
{{ if ne $network.IP "" }}
address=/{{ $host }}/{{ $network.IP }}
{{ end }}
address=/{{ $host }}/{{ $address.IP }}
{{ end }}
{{ end }}

{{ range $index, $container := $ }}
{{ $addrLen := len $container.Addresses }}
{{ $address := $container }}
{{ if gt $addrLen 0 }}
{{ $address := index $container.Addresses 0 }}
{{/* Configuration via "dns.name" label */}}
{{ range $index, $container := (whereLabelExists . "dns.name") }}
{{ with $container }}
{{ $dnsname := index .Labels "dns.name" }}
{{ template "host" (dict "Container" $container "Host" (print $dnsname) "Tld" "") }}
{{ end }}
{{ end }}

{{/* Configuration via "DNS_NAME" envitonment variables */}}
{{ range $host, $containers := groupByMulti $ "Env.DNS_NAME" "," }}
{{ range $index, $container := $containers }}
{{ template "host" (dict "Container" $container "Host" (print $host) "Tld" "") }}
{{ end }}
address=/{{ $container.Name }}.docker/{{ $address.IP }}
{{ end }}
12 changes: 6 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ set -e

# Default command (assuming container start)
if [ "$1" = 'supervisord' ]; then
# Drude IP config for dnsmasq
touch /etc/dnsmasq.d/drude.conf
# Resolve *.drude to $DRUDE_IP
echo "address=/drude/${DRUDE_IP}" >> /etc/dnsmasq.d/drude.conf
# Reverse resolution of $DRUDE_IP to 'drude'
echo $DRUDE_IP | awk -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,drude"}' >> /etc/dnsmasq.d/drude.conf
# $DNS_DOMAIN IP config for dnsmasq
touch /etc/dnsmasq.d/${DNS_DOMAIN}.conf
# Resolve *.$DNS_DOMAIN to $DNS_IP
echo "address=/${DNS_DOMAIN}/${IP}" >> /etc/dnsmasq.d/${DNS_DOMAIN}.conf
# Reverse resolution of $DNS_IP to ${DNS_DOMAIN}
echo $DNS_IP | awk -v dzone=${DNS_DOMAIN} -F . '{print "ptr-record="$4"."$3"."$2"."$1".in-addr.arpa,"dzone}' >> /etc/dnsmasq.d/${DNS_DOMAIN}.conf

# Turn query loggin on
if [ "$LOG_QUERIES" = true ]; then
Expand Down

0 comments on commit b331c0d

Please sign in to comment.