Skip to content

Instantly share code, notes, and snippets.

@theit8514
Created August 6, 2017 22:57
Show Gist options
  • Select an option

  • Save theit8514/22a615e42da04a375c7ddc38af435d1b to your computer and use it in GitHub Desktop.

Select an option

Save theit8514/22a615e42da04a375c7ddc38af435d1b to your computer and use it in GitHub Desktop.
Docker file for portainer 855
#!/bin/bash
[ -z "$PUBLIC_IP" ] && PUBLIC_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
[ -z "$PUBLIC_IP" -o "not found" = "$PUBLIC_IP" ] && PUBLIC_IP=`curl -s icanhazip.com`
[ -z "$PRIVATE_TOP_ZONES" ] && PRIVATE_TOP_ZONES="localhost local priv private"
{{ range $zone, $containers := groupByMulti $ "Env.ZONE" "," }}
zone={{ $zone }}
{{ end }}
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
host={{ $host }}
topzone=$(echo "${host##*.}")
if [ -n "$zone" ]; then
tenant=$(echo "${host%.$zone}")
else
tenant=$(echo "${host%.*.*}")
zone=$(echo "${host#$tenant.}")
fi
if [ "${PRIVATE_TOP_ZONES#*$topzone}" != "$PRIVATE_TOP_ZONES" -o "$tenant" = "$zone" ]; then
echo "Skipping private hostname $host" >> /var/log/route53-dyndns.log
else
cmd="cli53 rrcreate --replace $zone '$tenant 60 A $PUBLIC_IP'"
if [ -z "$DRY_ROUTE53" ]; then
echo "$cmd" >> /var/log/route53-dyndns.log
bash -c "$cmd" >> /var/log/route53-dyndns.log 2>&1
else
echo "DRYRUN: $cmd"
fi
fi
{{ end }}
## DynDNS for Docker with Route53
##
## Dynamic DNS counterpart of James Wilder's nginx-proxy for docker:
## [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy).
##
## Containerize cli53
## Discover the expected DNS names following the same conventions than jwilder/nginx-proxy
## Generate the DNS A record file and call cli53 to process it
FROM python:2-slim
MAINTAINER hugues@sutoiku.com
RUN mkdir /app
RUN apt-get update && apt-get install -y wget curl --no-install-recommends && \
apt-get clean && \
rm -r /var/lib/apt/lists/*
ENV CLI53_VERSION 0.8.8
ENV DOCKER_GEN_VERSION 0.7.3
RUN wget https://github.com/barnybug/cli53/releases/download/$CLI53_VERSION/cli53-linux-amd64 -O /usr/local/bin/cli53 && \
chmod +x /usr/local/bin/cli53
RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz -O docker-gen-linux-amd64.tar.gz && \
tar xvzf docker-gen-linux-amd64.tar.gz -C /usr/local/bin && \
rm docker-gen-linux-amd64.tar.gz
WORKDIR /app
ADD cli53routes.tmpl /app/cli53routes.tmpl
ENV DOCKER_HOST unix:///tmp/docker.sock
CMD /usr/local/bin/docker-gen -watch -notify "/bin/bash /app/cli53routes.sh" /app/cli53routes.tmpl /app/cli53routes.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment