← Back to team overview

bind-charmers team mailing list archive

[Merge] ~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder:master into ~bind-charmers/charm-k8s-bind/+git/bind-k8s-image-builder:master

 

Barry Price has proposed merging ~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder:master into ~bind-charmers/charm-k8s-bind/+git/bind-k8s-image-builder:master.

Commit message:
Add a simple readinessProbe script, requires bind9-dnsutils

Requested reviews:
  Bind Charmers (bind-charmers)
  Canonical IS Reviewers (canonical-is-reviewers)

For more details, see:
https://code.launchpad.net/~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder/+merge/388036
-- 
Your team Bind Charmers is requested to review the proposed merge of ~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder:master into ~bind-charmers/charm-k8s-bind/+git/bind-k8s-image-builder:master.
diff --git a/Dockerfile b/Dockerfile
index 9ac37cc..548bae5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,8 +20,11 @@ RUN apt-get update && apt-get -y dist-upgrade \
     && apt-get install -y ${PKGS_TO_INSTALL}
 
 # entrypoint script will configure Bind based on env variables
+# dns-check script will provide a readinessProbe
 COPY ./files/docker-entrypoint.sh /usr/local/bin/
+COPY ./files/dns-check.sh /usr/local/bin/
 RUN chmod 0755 /usr/local/bin/docker-entrypoint.sh
+RUN chmod 0755 /usr/local/bin/dns-check.sh
 
 EXPOSE 53/udp
 EXPOSE 53/tcp
diff --git a/Makefile b/Makefile
index 4af4079..f212b8c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,14 @@
 DIST_RELEASE ?= focal
-DOCKER_DEPS = bind9 git
+DOCKER_DEPS = bind9 bind9-dnsutils git
 
 deps:
 	@echo "Checking shellcheck is present."
-	@which shellcheck >/dev/null || { echo "Please install shellcheck to continue ('sudo snap install shellcheck')" && false; }
+	@command -v shellcheck >/dev/null || { echo "Please install shellcheck to continue ('sudo snap install shellcheck')" && false; }
 
 lint: deps
 	@echo "Running shellcheck."
 	@shellcheck files/docker-entrypoint.sh
+	@shellcheck files/dns-check.sh
 
 build-image: lint
 	@echo "Building the image."
diff --git a/files/dns-check.sh b/files/dns-check.sh
new file mode 100644
index 0000000..643fb94
--- /dev/null
+++ b/files/dns-check.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -eu
+
+TEST_DOMAIN="example.com"
+NSLOOKUP_PATH="/usr/bin/nslookup"
+OUR_ADDRESS="127.0.0.1"
+
+command -v "${NSLOOKUP_PATH}" >/dev/null || { echo "Cannot find the 'nslookup' command" && exit 1; }
+
+exec "${NSLOOKUP_PATH}" "${TEST_DOMAIN}" "${OUR_ADDRESS}" >/dev/null
diff --git a/files/docker-entrypoint.sh b/files/docker-entrypoint.sh
index 254d722..2ed0857 100644
--- a/files/docker-entrypoint.sh
+++ b/files/docker-entrypoint.sh
@@ -1,16 +1,23 @@
 #!/bin/bash
 set -eu
 
-if [ -z "${CUSTOM_CONFIG_REPO-}" ]; then
-	echo "No custom repo set, will fall back to package default config"
-elif [ -z "${BIND_CONFDIR-}" ]; then
+if [ -z "${BIND_CONFDIR-}" ]; then
+	# If BIND_CONFDIR wasn't set, use the package default
 	BIND_CONFDIR="/etc/bind";
+fi
+
+if [ -z "${CUSTOM_CONFIG_REPO-}" ]; then
+	echo "No custom repo set, will fall back to package default config";
 else
-	echo "Pulling config from $CUSTOM_CONFIG_REPO"
-	if [ -d /etc/bind ]; then
-		mv /etc/bind /etc/bind_"$(date +"%Y-%m-%d_%H-%M-%S")";
+	echo "Pulling config from $CUSTOM_CONFIG_REPO";
+	if [ -d "${BIND_CONFDIR}" ]; then
+		mv "${BIND_CONFDIR}" "${BIND_CONFDIR}_$(date +"%Y-%m-%d_%H-%M-%S")";
 	fi
-	git clone "$CUSTOM_CONFIG_REPO" "$BIND_CONFDIR"
+	git clone "$CUSTOM_CONFIG_REPO" "$BIND_CONFDIR";
 fi
 
-exec "$@"
+if [ -d "${BIND_CONFDIR}" ]; then
+	exec "$@"
+else
+	echo "Something went wrong, ${BIND_CONFDIR} does not exist, not starting";
+fi

Follow ups