def _download_package(self, version: str, package_name: str) -> Path: temp_package_path = Path("/tmp", package_name) package_url = self._package_url(version, package_name) logger.info("Downloading from: %s", package_url) response = requests.get( # nosec package_url, auth=get_cmk_download_credentials(), verify=False ) response.raise_for_status() with open(temp_package_path, "wb") as f: f.write(response.content) return temp_package_path
def _build(request, client, version, prepare_package=True): _prepare_build() if prepare_package: _prepare_package(version) logger.info("Starting helper container for build secrets") secret_container = client.containers.run( image="busybox", command=["timeout", "180", "httpd", "-f", "-p", "8000", "-h", "/files"], detach=True, remove=True, volumes={get_cmk_download_credentials_file(): {"bind": "/files/secret", "mode": "ro"}}, ) request.addfinalizer(lambda: secret_container.remove(force=True)) logger.info("Building docker image (or reuse existing): %s", _image_name(version)) try: image, build_logs = client.images.build( path=build_path, tag=_image_name(version), network_mode="container:%s" % secret_container.id, buildargs={ "CMK_VERSION": version.version, "CMK_EDITION": version.edition(), "CMK_DL_CREDENTIALS": ":".join(get_cmk_download_credentials()), "IMAGE_CMK_BASE": resolve_image_alias("IMAGE_CMK_BASE"), }, ) except docker.errors.BuildError as e: logger.error("= Build log ==================") for entry in e.build_log: if "stream" in entry: logger.error(entry["stream"]) elif "errorDetail" in entry: continue # Is already part of the exception message else: logger.error("UNEXPECTED FORMAT: %r", entry) logger.error("= Build log ==================") raise logger.info("(Set pytest log level to DEBUG (--log-cli-level=DEBUG) to see the build log)") for entry in build_logs: if "stream" in entry: logger.debug(entry["stream"].rstrip()) elif "aux" in entry: logger.debug(entry["aux"]) else: logger.debug("UNEXPECTED FORMAT: %r", entry) logger.debug("= Build log ==================") # TODO: Enable this on CI system. Removing during development slows down testing # request.addfinalizer(lambda: client.images.remove(image.id, force=True)) logger.info("Built image: %s", image.short_id) attrs = image.attrs config = attrs["Config"] assert config["Labels"] == { "org.opencontainers.image.vendor": "tribe29 GmbH", "org.opencontainers.image.version": version.version, "maintainer": "*****@*****.**", "org.opencontainers.image.description": "Checkmk is a leading tool for Infrastructure & Application Monitoring", "org.opencontainers.image.source": "https://github.com/tribe29/checkmk", "org.opencontainers.image.title": "Checkmk", "org.opencontainers.image.url": "https://checkmk.com/", } assert config["Env"] == [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "CMK_SITE_ID=cmk", "CMK_LIVESTATUS_TCP=", "CMK_PASSWORD="******"MAIL_RELAY_HOST=", ] assert "Healthcheck" in config assert attrs["ContainerConfig"]["Entrypoint"] == ["/docker-entrypoint.sh"] assert attrs["ContainerConfig"]["ExposedPorts"] == { "5000/tcp": {}, "6557/tcp": {}, } # 2018-11-14: 900 -> 920 # 2018-11-22: 920 -> 940 # 2019-04-10: 940 -> 950 # 2019-07-12: 950 -> 1040 (python3) # 2019-07-27: 1040 -> 1054 (numpy) # 2019-11-15: Temporarily disabled because of Python2 => Python3 transition # assert attrs["Size"] < 1110955410.0, \ # "Docker image size increased: Please verify that this is intended" assert len(attrs["RootFS"]["Layers"]) == 6 return image, build_logs