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

Proposed by Barry Price
Status: Merged
Approved by: Tom Haddon
Approved revision: 55f728221f7857cd037d987b73eca4dec1a36bb1
Merged at revision: af1d0d984eb1a91518747540bbddab2ce012fcfe
Proposed branch: ~barryprice/charm-k8s-bind/+git/charm-k8s-bind:image-builder
Merge into: charm-k8s-bind:master
Diff against target: 133 lines (+96/-1)
5 files modified
.jujuignore (+7/-0)
Makefile (+23/-1)
dockerfile (+33/-0)
image-scripts/dns-check.sh (+10/-0)
image-scripts/docker-entrypoint.sh (+23/-0)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+388449@code.launchpad.net

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

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thx

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision af1d0d984eb1a91518747540bbddab2ce012fcfe

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.jujuignore b/.jujuignore
2new file mode 100644
3index 0000000..d968a07
4--- /dev/null
5+++ b/.jujuignore
6@@ -0,0 +1,7 @@
7+*~
8+.coverage
9+__pycache__
10+/dockerfile
11+/image-scripts/
12+/tests/
13+/Makefile
14diff --git a/Makefile b/Makefile
15index d403fd0..66fc8ed 100644
16--- a/Makefile
17+++ b/Makefile
18@@ -1,3 +1,6 @@
19+DIST_RELEASE ?= focal
20+DOCKER_DEPS = bind9 bind9-dnsutils git
21+
22 blacken:
23 @echo "Normalising python layout with black."
24 @tox -e black
25@@ -21,4 +24,23 @@ clean:
26 bind.charm: src/*.py requirements.txt
27 charmcraft build
28
29-.PHONY: blacken lint unittest test clean
30+image-deps:
31+ @echo "Checking shellcheck is present."
32+ @command -v shellcheck >/dev/null || { echo "Please install shellcheck to continue ('sudo snap install shellcheck')" && false; }
33+
34+image-lint: image-deps
35+ @echo "Running shellcheck."
36+ @shellcheck files/docker-entrypoint.sh
37+ @shellcheck files/dns-check.sh
38+
39+image-build: image-lint
40+ @echo "Building the image."
41+ @docker build \
42+ --no-cache=true \
43+ --build-arg BUILD_DATE=$$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
44+ --build-arg PKGS_TO_INSTALL='$(DOCKER_DEPS)' \
45+ --build-arg DIST_RELEASE=$(DIST_RELEASE) \
46+ -t bind:$(DIST_RELEASE)-latest \
47+ .
48+
49+.PHONY: blacken lint unittest test clean image-deps image-lint image-build
50diff --git a/dockerfile b/dockerfile
51new file mode 100644
52index 0000000..2e580d4
53--- /dev/null
54+++ b/dockerfile
55@@ -0,0 +1,33 @@
56+ARG DIST_RELEASE
57+
58+FROM ubuntu:${DIST_RELEASE}
59+
60+LABEL maintainer="bind-charmers@lists.launchpad.net"
61+
62+ARG BUILD_DATE
63+ARG PKGS_TO_INSTALL
64+
65+LABEL org.label-schema.build-date=${BUILD_DATE}
66+
67+ENV BIND_CONFDIR=/etc/bind
68+
69+# Avoid interactive prompts
70+RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
71+
72+# Update all packages, remove cruft, install required packages
73+RUN apt-get update && apt-get -y dist-upgrade \
74+ && apt-get --purge autoremove -y \
75+ && apt-get install -y ${PKGS_TO_INSTALL}
76+
77+# entrypoint script will configure Bind based on env variables
78+# dns-check script will provide a readinessProbe
79+COPY ./files/docker-entrypoint.sh /usr/local/bin/
80+COPY ./files/dns-check.sh /usr/local/bin/
81+RUN chmod 0755 /usr/local/bin/docker-entrypoint.sh
82+RUN chmod 0755 /usr/local/bin/dns-check.sh
83+
84+EXPOSE 53/udp
85+EXPOSE 53/tcp
86+
87+ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
88+CMD /usr/sbin/named -g -u bind -c /etc/bind/named.conf
89diff --git a/image-scripts/dns-check.sh b/image-scripts/dns-check.sh
90new file mode 100644
91index 0000000..ca4a5a0
92--- /dev/null
93+++ b/image-scripts/dns-check.sh
94@@ -0,0 +1,10 @@
95+#!/bin/bash
96+set -eu
97+
98+TEST_DOMAIN="ddebs.ubuntu.com."
99+NSLOOKUP_PATH="/usr/bin/nslookup"
100+OUR_ADDRESS="127.0.0.1"
101+
102+command -v "${NSLOOKUP_PATH}" >/dev/null || { echo "Cannot find the 'nslookup' command" && exit 1; }
103+
104+exec "${NSLOOKUP_PATH}" "${TEST_DOMAIN}" "${OUR_ADDRESS}" >/dev/null
105diff --git a/image-scripts/docker-entrypoint.sh b/image-scripts/docker-entrypoint.sh
106new file mode 100644
107index 0000000..2ed0857
108--- /dev/null
109+++ b/image-scripts/docker-entrypoint.sh
110@@ -0,0 +1,23 @@
111+#!/bin/bash
112+set -eu
113+
114+if [ -z "${BIND_CONFDIR-}" ]; then
115+ # If BIND_CONFDIR wasn't set, use the package default
116+ BIND_CONFDIR="/etc/bind";
117+fi
118+
119+if [ -z "${CUSTOM_CONFIG_REPO-}" ]; then
120+ echo "No custom repo set, will fall back to package default config";
121+else
122+ echo "Pulling config from $CUSTOM_CONFIG_REPO";
123+ if [ -d "${BIND_CONFDIR}" ]; then
124+ mv "${BIND_CONFDIR}" "${BIND_CONFDIR}_$(date +"%Y-%m-%d_%H-%M-%S")";
125+ fi
126+ git clone "$CUSTOM_CONFIG_REPO" "$BIND_CONFDIR";
127+fi
128+
129+if [ -d "${BIND_CONFDIR}" ]; then
130+ exec "$@"
131+else
132+ echo "Something went wrong, ${BIND_CONFDIR} does not exist, not starting";
133+fi

Subscribers

People subscribed via source and target branches

to all changes: