Skip to content

Commit

Permalink
Fixed the build of the docker image; Added test for running sdocker i…
Browse files Browse the repository at this point in the history
…mage

Details:

* The Dockerfile used the python:3.12-slim image for the builder environment
  and switched that to the python:3.12-alpine image for the final container
  environment.

  The installation of the 'rpds' Python package builds a shared library. That
  library was built against the builder OS and then attempted to be run in the
  (different) final OS. The two OS images were different enough for that to
  fail.

  Fixed that by using the same OS image python:3.12-slim for both enviroments.

  This increased the image size from 86 MB to 186 MB.

* Added showing the rpds package files to the docker builder phase.

* Added test to 'docker make' for running the docker image to show the
  exporter version.

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Sep 25, 2024
1 parent 9778e8a commit eff8976
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ RUN apt-get update \

# Install the zhmc-prometheus-exporter package
COPY ${bdist_file} /tmp/${bdist_file}
RUN pip install --user /tmp/${bdist_file} \
&& rm -f /tmp/${bdist_file} \
RUN pip install --user /tmp/${bdist_file}

# Show the installed Python packages
RUN echo "Installed Python packages:" \
&& pip list

# Uninstall Python packages not needed for running the package
RUN python -m pip uninstall -y pip setuptools wheel
# Display files in 'rpds' Python package (verifying that it can be imported)
RUN echo "Files in rpds Python package:" \
&& python -c "import rpds, os, sys; rpds_dir=os.path.dirname(rpds.__file__); print(rpds_dir); sys.stdout.flush(); os.system(f'ls -al {rpds_dir}')"

FROM python:3.12-alpine
# The Python 'rpds' package (used by 'jsonschema') has a shared library that is
# built during its installation, and thus depends on system APIs of the OS used
# in the builder container. Therefore, the OS used in the final container needs
# to be compatible with the builder OS. We use the same OS image to make sure.
FROM python:3.12-slim

# Version of the zhmc-prometheus-exporter package
ARG package_version
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ help:
@echo " build - Build the distribution files in $(dist_dir)"
@echo " builddoc - Build the documentation in $(doc_build_dir)"
@echo " all - Do all of the above"
@echo " docker - Build local Docker image in registry $(docker_registry)"
@echo " docker - Build local Docker image in registry $(docker_registry) and run it to show version"
@echo " authors - Generate AUTHORS.md file from git log"
@echo " upload - Upload the package to Pypi"
@echo " clean - Remove any temporary files"
Expand Down Expand Up @@ -455,6 +455,7 @@ $(done_dir)/docker_$(pymn)_$(PACKAGE_LEVEL).done: $(done_dir)/develop_$(pymn)_$(
@echo "Makefile: Building Docker image $(docker_registry):latest"
-$(call RM_FUNC,$@)
docker build --tag $(docker_registry):$(subst +,.,$(package_version)) --build-arg bdist_file=$(bdist_file) --build-arg package_version=$(subst +,.,$(package_version)) --build-arg build_date="$(shell date -Iseconds)" --build-arg git_commit="$(shell git rev-parse HEAD)" .
docker run --rm $(docker_registry):$(subst +,.,$(package_version)) --version
docker image list --filter reference=$(docker_registry)
@echo "Makefile: Done building Docker image"
echo "done" >$@
2 changes: 2 additions & 0 deletions changes/623.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed the build of the docker image which failed with an ImportError
on the rpds package. Added test for running the docker image.

0 comments on commit eff8976

Please sign in to comment.