Skip to content

Commit

Permalink
Merge pull request #9 from docksal/develop
Browse files Browse the repository at this point in the history
Release 1.1.1
  • Loading branch information
lmakarov authored Nov 14, 2018
2 parents 7c83a7d + 2707e33 commit bae5cc6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 11 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ sudo: required
language: generic

env:
REPO: docksal/dns
IMAGE_DNS: ${REPO}:dev
DOCKSAL_VERSION: develop

services:
- docker

install:
- sudo sudo curl -L https://raw.githubusercontent.com/docksal/docksal/${DOCKSAL_VERSION}/bin/fin -o /usr/local/bin/fin && sudo chmod +x /usr/local/bin/fin
# Install Docksal to have a matching versions of Docker on the build host
- curl -fsSL https://get.docksal.io | bash
- fin version
- fin update
- fin sysinfo

script:
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN set -xe; \
RUN sed -i '/strict-order/s/^#//g' /etc/dnsmasq.conf

COPY docker-entrypoint.sh /usr/local/bin
COPY healthcheck.sh /opt/healthcheck.sh

# Default domain and IP for wildcard query resolution
ENV DNS_DOMAIN 'docksal'
Expand All @@ -21,3 +22,6 @@ EXPOSE 53/udp
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["dnsmasq"]

# Health check script
HEALTHCHECK --interval=5s --timeout=1s --retries=3 CMD ["/opt/healthcheck.sh"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ VERSION ?= dev

REPO = docksal/dns
NAME = docksal-dns
DOCKSAL_IP=192.168.64.100

.EXPORT_ALL_VARIABLES:

Expand All @@ -29,7 +30,7 @@ shell:
@make exec-it -e CMD=sh

run: clean
docker run --rm -it -e DNS_DOMAIN=docksal -e DNS_IP=192.168.64.100 ${REPO}:${VERSION} sh
docker run --rm -it -e DNS_DOMAIN=docksal -e DNS_IP=${DOCKSAL_IP} ${REPO}:${VERSION} sh

# This is the only place where fin is used/necessary
start:
Expand Down
3 changes: 3 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
DEBUG=${DEBUG:-0}
# Turn debugging ON when cli is started in the service mode
if [ "$1" == "dnsmasq" ]; then DEBUG=1; fi

# Print a debug message if debug mode is on
# @param message
echo_debug ()
{
[[ "$DEBUG" != 0 ]] && echo "$(date +"%F %H:%M:%S") | $@"
Expand Down
6 changes: 6 additions & 0 deletions healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

netstat -nlp | grep -E 'tcp.*53.*LISTEN.*dnsmasq' >/dev/null || exit 1
netstat -nlp | grep -E 'udp.*53.*dnsmasq' >/dev/null || exit 1

exit 0
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then

if [[ "$TAG" != "" ]]; then
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
docker tag ${IMAGE_DNS} ${REPO}:${TAG}
docker tag ${REPO}:dev ${REPO}:${TAG}
docker push ${REPO}:${TAG}
fi;
fi;
57 changes: 52 additions & 5 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,68 @@ teardown() {
echo "================================================================"
}

# Globals
DOCKSAL_IP=192.168.64.100
# Checks container health status (if available)
# @param $1 container id/name
_healthcheck ()
{
local health_status
health_status=$(docker inspect --format='{{json .State.Health.Status}}' "$1" 2>/dev/null)

# Wait for 5s then exit with 0 if a container does not have a health status property
# Necessary for backward compatibility with images that do not support health checks
if [[ $? != 0 ]]; then
echo "Waiting 10s for container to start..."
sleep 10
return 0
fi

# If it does, check the status
echo $health_status | grep '"healthy"' >/dev/null 2>&1
}

# Waits for containers to become healthy
# For reasoning why we are not using `depends_on` `condition` see here:
# https://github.com/docksal/docksal/issues/225#issuecomment-306604063
_healthcheck_wait ()
{
# Wait for cli to become ready by watching its health status
local container_name="${NAME}"
local delay=5
local timeout=30
local elapsed=0

until _healthcheck "$container_name"; do
echo "Waiting for $container_name to become ready..."
sleep "$delay";

# Give the container 30s to become ready
elapsed=$((elapsed + delay))
if ((elapsed > timeout)); then
echo-error "$container_name heathcheck failed" \
"Container did not enter a healthy state within the expected amount of time." \
"Try ${yellow}fin restart${NC}"
exit 1
fi
done

return 0
}

# To work on a specific test:
# run `export SKIP=1` locally, then comment skip in the test you want to debug

@test "DNS container is up and using the \"${IMAGE}\" image" {
@test "${NAME} container is up and using the \"${IMAGE}\" image" {
[[ ${SKIP} == 1 ]] && skip
_healthcheck_wait

run docker ps --filter "name=docksal-dns" --format "{{ .Image }}"
[[ "$output" =~ "$IMAGE" ]]
run docker ps --filter "name=${NAME}" --format "{{ .Image }}"
[[ "$output" =~ "${IMAGE}" ]]
unset output
}

@test ".docksal name resolution" {
[[ $SKIP == 1 ]] && skip
_healthcheck_wait

# Check .docksal domain resolution via ping
run ping -c 1 -t 1 anything.docksal
Expand All @@ -40,6 +86,7 @@ DOCKSAL_IP=192.168.64.100

@test "External name resolution" {
[[ $SKIP == 1 ]] && skip
_healthcheck_wait

# Real domain
run ping -c 1 -t 1 www.google.com
Expand Down

0 comments on commit bae5cc6

Please sign in to comment.