Module: check_mk
Branch: master
Commit: 15996bd1697992c5450878718eb821d21d34a4ff
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=15996bd1697992…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 14 14:33:25 2018 +0200
Docker image: Add support for building using local CMK files
Change-Id: Id9828aeba54b7be128fce110d81e1dbefa576995
---
docker/Dockerfile | 23 ++++++++++++++++++-----
docker/Makefile | 1 -
docker/README.asciidoc | 7 +++++++
tests/docker/test_docker.py | 28 +++++++++++++++++++++++++++-
tests/testlib/__init__.py | 6 +++++-
5 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/docker/Dockerfile b/docker/Dockerfile
index db1684d..3af9145 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -49,6 +49,11 @@ RUN set -e \
&& rm -rf /var/lib/apt/lists/* \
&& rm needed-packages
+#
+# Optionally copy an existing Check_MK debian package to the container. In case the file
is
+# available that is later used by the build procedure the file will not be downloaded.
+COPY check-mk-${CMK_EDITION}-${CMK_VERSION}_0.stretch_*.deb Check_MK-pubkey*gpg
needed-packages /
+
# Now install the Check_MK version specific things
# hadolint ignore=DL3003,DL3008,DL4006
RUN set -e \
@@ -58,13 +63,21 @@ RUN set -e \
&& export DEBIAN_FRONTEND=noninteractive \
&& PKG_NAME="check-mk-${CMK_EDITION}-${CMK_VERSION}" \
&& PKG_FILE="${PKG_NAME}_0.stretch_$(dpkg
--print-architecture).deb" \
- && echo "--user \"${CMK_DL_CREDENTIALS}\"" \
- | curl -o "${PKG_FILE}" -K -
"${CMK_DL_URL}/${CMK_VERSION}/${PKG_FILE}" \
- && curl -sS "${CMK_DL_URL}/Check_MK-pubkey.gpg" \
- | gpg -q --import \
+ && if [ ! -e "/${PKG_FILE}" ]; then \
+ echo "Downloading ${PKG_FILE}..." && \
+ echo "--user \"${CMK_DL_CREDENTIALS}\"" \
+ | curl -o "${PKG_FILE}" -K -
"${CMK_DL_URL}/${CMK_VERSION}/${PKG_FILE}" ; \
+ fi \
+ && if [ ! -e "/Check_MK-pubkey.gpg" ]; then \
+ echo "Downloading Check_MK-pubkey.gpg..." && \
+ curl -sS "${CMK_DL_URL}/Check_MK-pubkey.gpg" \
+ | gpg -q --import ; \
+ else \
+ gpg -q --import "/Check_MK-pubkey.gpg" ; \
+ fi \
&& dpkg-sig --verify "${PKG_FILE}" \
&& dpkg -i "${PKG_FILE}" \
- && rm -f "${PKG_FILE}" \
+ && rm -f *.deb *.gpg needed-packages \
&& apt-get clean \
&& rm /usr/sbin/policy-rc.d \
&& rm -rf /var/lib/apt/lists/*
diff --git a/docker/Makefile b/docker/Makefile
index 39df048..b25632f 100644
--- a/docker/Makefile
+++ b/docker/Makefile
@@ -67,7 +67,6 @@ image-daily: needed-packages
else \
BRANCH_PREFIX="$${BRANCH_PREFIX}-" ; \
fi ; \
- BRANCH_PREFIX="1.5.0-" ; \
VERSION="$$(date +%F)" ; \
VERSION="$${BRANCH_PREFIX}$${VERSION//-/.}" ; \
CREDENTIALS="$$(cat "$(CREDENTIALS_FILE)")" ; \
diff --git a/docker/README.asciidoc b/docker/README.asciidoc
index d0bdcaf..0cecede 100644
--- a/docker/README.asciidoc
+++ b/docker/README.asciidoc
@@ -293,6 +293,13 @@ docker build \
-t mycompany/check-mk-enterprise:1.5.0p3
....
+Doing it like this the build process will download 2 files from our download
+server: The Debian stretch package and the GPG public key for verifying the
+package signature. To prevent this you may put the files that are needed during
+the build into the `docker` directory. For the above call you would have to put
+the `check-mk-enterprise-1.5.0p3.stretch_amd64.deb` and `Check_MK-pubkey.gpg`
+into this directory.
+
We'll offer prebuilt images for the Enterprise and Managed Services
Edition in the future. For the moment you'll have to build them on your
own (e.g. using the command above).
diff --git a/tests/docker/test_docker.py b/tests/docker/test_docker.py
index 62d68a6..91061a9 100644
--- a/tests/docker/test_docker.py
+++ b/tests/docker/test_docker.py
@@ -100,7 +100,7 @@ def _build(request, client, edition, version, add_args=None):
assert attrs["Size"] < 840000000
- assert len(attrs["RootFS"]["Layers"]) == 5
+ assert len(attrs["RootFS"]["Layers"]) == 6
return image, build_logs
@@ -224,6 +224,32 @@ def test_start_with_custom_command(request, client):
assert output.endswith("1\n")
+# Test that the local deb package is used by making the build fail because of an empty
file
+def test_build_using_local_deb(request, client):
+ pkg_path = os.path.join(build_path,
build_version.package_name_of_distro("stretch"))
+ try:
+ with open(pkg_path, "w") as f:
+ f.write("")
+
+ with pytest.raises(docker.errors.BuildError):
+ _build(request, client, "enterprise", build_version)
+ finally:
+ os.unlink(pkg_path)
+
+
+# Test that the local GPG file is used by making the build fail because of an empty file
+def test_build_using_local_gpg_pubkey(request, client):
+ pkg_path = os.path.join(build_path, "Check_MK-pubkey.gpg")
+ try:
+ with open(pkg_path, "w") as f:
+ f.write("")
+
+ with pytest.raises(docker.errors.BuildError):
+ _build(request, client, "enterprise", build_version)
+ finally:
+ os.unlink(pkg_path)
+
+
def test_start_enable_mail(request, client):
c = _start(request, client, environment={
"MAIL_RELAY_HOST": "mailrelay.mydomain.com",
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 92ed47f..2220d1f 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -174,8 +174,12 @@ class CMKVersion(object):
def package_name(self):
+ return self.package_name_of_distro(self._needed_distro())
+
+
+ def package_name_of_distro(self, distro):
return "check-mk-%s-%s_0.%s_%s.deb" % \
- (self.edition(), self.version, self._needed_distro(),
self._needed_architecture())
+ (self.edition(), self.version, distro, self._needed_architecture())
def package_url(self):