diff --git a/README.md b/README.md index 0fcf2f0..c30275e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,49 @@ chmod u+x ./scripts/generate-certificates.sh ``` You need to add the generated certificate `certificates/docker.rootCA.crt` to your browser authorities and trust related websites. +### Setup local DNS + +To be able to resolve all DNS lookup to *.pontsun.test (or other configured domains), we need a local dns server. +There's 2 options to do that, either in the provided docker container. Or in a locally installed dns server like dnsmasq. + + +#### 1) Use the included dns server container + +Do use the included dnsmasq container, start pontsun with + +```bash +cd containers +docker-compose -f docker-compose.yml -f docker-compose.dns.yml up -d +``` + +You can also add the following to your `containers/.env` file instead + +``` +COMPOSE_FILE=docker-compose.yml:docker-compose.dns.yml +``` + +#### or 3) Use a locally installed dns server + +See + +- [Docker installation for Mac](docs/docker-installation-for-mac.md) +- [Docker installation for Ubuntu](docs/docker-installation-for-ubuntu.md) + +for detilas + +#### Add domain to your dns config + +After you have set the dns server up, do: + +```bash +. containers/.env +./scripts/pontsun add-host $PROJECT_DOMAIN +``` + +do add your default domain (by default pontsun.test) to the dns server. + +### Start pontsun with traefik and portainer + Start Traefik and Portainer ```bash cd containers diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..24b28ea --- /dev/null +++ b/build/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd $DIR +docker build -t liip/pontsun-dnsmasq:latest dnsmasq diff --git a/build/dnsmasq/Dockerfile b/build/dnsmasq/Dockerfile new file mode 100644 index 0000000..478cc56 --- /dev/null +++ b/build/dnsmasq/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:edge + +RUN apk --no-cache add dnsmasq + +ADD dnsmasq.conf /etc/ + +EXPOSE 53 53/udp +ENTRYPOINT ["dnsmasq", "-d"] \ No newline at end of file diff --git a/build/dnsmasq/dnsmasq.conf b/build/dnsmasq/dnsmasq.conf new file mode 100644 index 0000000..3be9784 --- /dev/null +++ b/build/dnsmasq/dnsmasq.conf @@ -0,0 +1,11 @@ +#dnsmasq config, for a complete example, see: +# http://oss.segetech.com/intra/srv/dnsmasq.conf +#log all dns queries +log-queries +#dont use hosts nameservers +no-resolv +#use cloudflare as default nameservers, prefer 1^4 +server=1.0.0.1 +server=1.1.1.1 +strict-order +conf-dir=/etc/dnsmasq.d/,*.conf diff --git a/containers/docker-compose.dns.yml b/containers/docker-compose.dns.yml new file mode 100644 index 0000000..76a30b0 --- /dev/null +++ b/containers/docker-compose.dns.yml @@ -0,0 +1,15 @@ +version: '3.5' +services: + dns: + image: liip/pontsun-dnsmasq:latest + container_name: pontsun_dns + restart: always + volumes: + - "$PONTSUN_DIR_ETC/dnsmasq.d/:/etc/dnsmasq.d/" + ports: + - 53:53/udp + networks: + - pontsun + logging: + options: + max-size: 20m \ No newline at end of file diff --git a/docs/docker-installation-for-mac.md b/docs/docker-installation-for-mac.md index d4ccf7a..6591b94 100644 --- a/docs/docker-installation-for-mac.md +++ b/docs/docker-installation-for-mac.md @@ -30,7 +30,7 @@ gem install docker-sync ## Dnsmasq -Dnsmasq will automatically forward any **\*.docker.lo** domain to our +Dnsmasq will automatically forward any **\*.pontsun.test** domain to our local docker infrastructure. ``` @@ -38,22 +38,29 @@ brew install dnsmasq ``` ``` -mkdir -pv $(brew --prefix)/etc/ -echo 'address=/docker.lo/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf -echo 'strict-order' >> $(brew --prefix)/etc/dnsmasq.conf +mkdir -pv $(brew --prefix)/etc/dnsmasq.d/ +echo 'strict-order' > $(brew --prefix)/etc/dnsmasq.conf +echo 'conf-dir='$(brew --prefix)'/etc/dnsmasq.d/,*.conf' >> $(brew --prefix)/etc/dnsmasq.conf ``` +and then ``` -sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons -sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist -``` - - +./scripts/add-host.sh pontsun.test ``` +or if you prefer to do it by hand +``` +echo address=/$1/127.0.0.1 > $(brew --prefix)/dnsmasq.d/pontsun.test.conf +echo 'strict-order' >> $(brew --prefix)/dnsmasq.d/pontsun.test.conf sudo mkdir -v /etc/resolver sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/docker.lo' ``` +and in the end +``` +sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons +sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist +``` + ## Pontsun Pontsun provides the base setup for Docker environments. diff --git a/docs/docker-installation-for-ubuntu.md b/docs/docker-installation-for-ubuntu.md index d0986f2..c3bdccb 100644 --- a/docs/docker-installation-for-ubuntu.md +++ b/docs/docker-installation-for-ubuntu.md @@ -21,9 +21,18 @@ sudo apt-get install dnsmasq ``` mkdir -pv /etc/dnsmasq.d/ -echo 'address=/docker.lo/127.0.0.1' | sudo tee /etc/dnsmasq.d/docker -echo 'strict-order' | sudo tee --append /etc/dnsmasq.d/docker ``` +and then +``` +./scripts/add-host pontsun.test +``` + +or if you prefer to do it by hand +``` +echo 'address=/pontsun.test/127.0.0.1' | sudo tee /etc/dnsmasq.d/pontsun.test.conf +echo 'strict-order' | sudo tee --append /etc/dnsmasq.d/pontsun.test.conf +``` + ## Pontsun Pontsun provides the base setup for Docker environments. diff --git a/scripts/add-host.sh b/scripts/add-host.sh new file mode 100755 index 0000000..3336d59 --- /dev/null +++ b/scripts/add-host.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PONTSUN_DNS=$(docker inspect -f '{{.State.Running}}' pontsun_dns 2> /dev/null || echo 'false') + +if [[ $PONTSUN_DNS == 'true' ]]; then + DOCKER_COMPOSE="docker-compose -f docker-compose.yml -f docker-compose.dns.yml" + cd $DIR/../containers/ + if $DOCKER_COMPOSE exec dns ash -c "if [[ -f /etc/dnsmasq.d/$1.conf ]]; then exit 1; fi; echo address=/$1/127.0.0.1 > /etc/dnsmasq.d/$1.conf" + then + $DOCKER_COMPOSE restart dns + fi +else + # no DNS container. + # write it to system dnsmasq + + if [[ "$OSTYPE" == "darwin"* ]]; then + ETC_PREFIX=$(brew --prefix)'/etc' + else + ETC_PREFIX='/etc' + fi + + if [[ ! -d $ETC_PREFIX/dnsmasq.d/ ]]; then + RED='\033[0;31m' + NC='\033[0m' # No Color + + printf "${RED}pontsun_dns is not running and can't find $ETC_PREFIX/dnsmasq.d${NC}\n" + printf "Please install dnsmasq locally or start potsun_dns" + exit 1 + fi + + if [[ ! -f $ETC_PREFIX/dnsmasq.d/$1.conf ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + echo address=/$1/127.0.0.1 > $ETC_PREFIX/dnsmasq.d/$1.conf + echo 'strict-order' >> $ETC_PREFIX/dnsmasq.d/$1.conf + else + echo address=/$1/127.0.0.1 | sudo tee $ETC_PREFIX/dnsmasq.d/$1.conf + echo 'strict-order' | sudo tee --append $ETC_PREFIX/dnsmasq.d/$1.conf + fi + echo "dnsmasq entry updated, you may restart it to take effect." + else + echo "No dnsmasq changes done, $ETC_PREFIX/dnsmasq.d/$1.conf already exists." + fi +fi + +if [[ "$OSTYPE" == "darwin"* ]] && [[ ! -f /etc/resolver/$1 ]]; then + echo "Adding to /etc/resolver/$1" + sudo mkdir -vp /etc/resolver + sudo bash -c "echo 'nameserver 127.0.0.1' > /etc/resolver/$1" +fi