← Back to team overview

bind-charmers team mailing list archive

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

 

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

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

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

For more details, see:
https://code.launchpad.net/~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder/+merge/388035
-- 
Your team Bind Charmers is requested to review the proposed merge of ~barryprice/charm-k8s-bind/+git/bind-k8s-image-builder:master into charm-k8s-bind:master.
diff --git a/.gitignore b/.gitignore
index 490cc43..b1d81ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,15 @@
+<<<<<<< .gitignore
 *~
 *.charm
 .tox
 .coverage
 __pycache__
 build
+=======
+*.pyc
+*.swp
+*~
+__pycache__
+.coverage
+.tox/
+>>>>>>> .gitignore
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..548bae5
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,33 @@
+ARG DIST_RELEASE
+
+FROM ubuntu:${DIST_RELEASE}
+
+LABEL maintainer="bind-charmers@xxxxxxxxxxxxxxxxxxx"
+
+ARG BUILD_DATE
+ARG PKGS_TO_INSTALL
+
+LABEL org.label-schema.build-date=${BUILD_DATE}
+
+ENV BIND_CONFDIR=/etc/bind
+
+# Avoid interactive prompts
+RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
+
+# Update all packages, remove cruft, install required packages
+RUN apt-get update && apt-get -y dist-upgrade \
+    && apt-get --purge autoremove -y \
+    && 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
+
+ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
+CMD /usr/sbin/named -f -u bind
diff --git a/Makefile b/Makefile
index d403fd0..65754b2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+<<<<<<< Makefile
 blacken:
 	@echo "Normalising python layout with black."
 	@tox -e black
@@ -13,12 +14,39 @@ unittest: bind.charm
 	@tox -e unit
 
 test: lint unittest
+=======
+DIST_RELEASE ?= focal
+DOCKER_DEPS = bind9 bind9-dnsutils git
+
+deps:
+	@echo "Checking shellcheck is present."
+	@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."
+	@docker build \
+		--no-cache=true \
+		--build-arg BUILD_DATE=$$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
+		--build-arg PKGS_TO_INSTALL='$(DOCKER_DEPS)' \
+		--build-arg DIST_RELEASE=$(DIST_RELEASE) \
+		-t bind:$(DIST_RELEASE)-latest \
+		.
+>>>>>>> Makefile
 
 clean:
 	@echo "Cleaning files"
 	@git clean -fXd
 
+<<<<<<< Makefile
 bind.charm: src/*.py requirements.txt
 	charmcraft build
 
 .PHONY: blacken lint unittest test clean
+=======
+.PHONY: build-image build clean 
+>>>>>>> Makefile
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
new file mode 100644
index 0000000..2ed0857
--- /dev/null
+++ b/files/docker-entrypoint.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+set -eu
+
+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 "${BIND_CONFDIR}" ]; then
+		mv "${BIND_CONFDIR}" "${BIND_CONFDIR}_$(date +"%Y-%m-%d_%H-%M-%S")";
+	fi
+	git clone "$CUSTOM_CONFIG_REPO" "$BIND_CONFDIR";
+fi
+
+if [ -d "${BIND_CONFDIR}" ]; then
+	exec "$@"
+else
+	echo "Something went wrong, ${BIND_CONFDIR} does not exist, not starting";
+fi

References