← Back to team overview

bind-charmers team mailing list archive

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

 

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

Commit message:
Migrate the image builder here from its own branch, use .jujuignore to ensure charmcraft doesn't include those parts in our built charm

Requested reviews:
  Bind Charmers (bind-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/charm-k8s-bind/+git/charm-k8s-bind/+merge/388449
-- 
Your team Bind Charmers is requested to review the proposed merge of ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:image-builder into charm-k8s-bind:master.
diff --git a/.jujuignore b/.jujuignore
new file mode 100644
index 0000000..d968a07
--- /dev/null
+++ b/.jujuignore
@@ -0,0 +1,7 @@
+*~
+.coverage
+__pycache__
+/dockerfile
+/image-scripts/
+/tests/
+/Makefile
diff --git a/Makefile b/Makefile
index d403fd0..66fc8ed 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,6 @@
+DIST_RELEASE ?= focal
+DOCKER_DEPS = bind9 bind9-dnsutils git
+
 blacken:
 	@echo "Normalising python layout with black."
 	@tox -e black
@@ -21,4 +24,23 @@ clean:
 bind.charm: src/*.py requirements.txt
 	charmcraft build
 
-.PHONY: blacken lint unittest test clean
+image-deps:
+	@echo "Checking shellcheck is present."
+	@command -v shellcheck >/dev/null || { echo "Please install shellcheck to continue ('sudo snap install shellcheck')" && false; }
+
+image-lint: image-deps
+	@echo "Running shellcheck."
+	@shellcheck files/docker-entrypoint.sh
+	@shellcheck files/dns-check.sh
+
+image-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 \
+		.
+
+.PHONY: blacken lint unittest test clean image-deps image-lint image-build
diff --git a/dockerfile b/dockerfile
new file mode 100644
index 0000000..2e580d4
--- /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 -g -u bind -c /etc/bind/named.conf
diff --git a/image-scripts/dns-check.sh b/image-scripts/dns-check.sh
new file mode 100644
index 0000000..ca4a5a0
--- /dev/null
+++ b/image-scripts/dns-check.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -eu
+
+TEST_DOMAIN="ddebs.ubuntu.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/image-scripts/docker-entrypoint.sh b/image-scripts/docker-entrypoint.sh
new file mode 100644
index 0000000..2ed0857
--- /dev/null
+++ b/image-scripts/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

Follow ups