Dockerfile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # sync with https://github.com/fphammerle/wireless-sensor-mqtt/blob/master/Dockerfile
  2. # not using python:3.*-alpine cause glib-dev package depends on python3
  3. # https://pkgs.alpinelinux.org/package/v3.11/main/aarch64/glib-dev
  4. ARG BASE_IMAGE=docker.io/alpine:3.21.0
  5. ARG SOURCE_DIR_PATH=/systemctl-mqtt
  6. # hadolint ignore=DL3006
  7. FROM $BASE_IMAGE AS build
  8. RUN apk add --no-cache \
  9. cairo-dev `# PyGObject > pycairo` \
  10. dbus `# dbus-run-session for dbus-python's build` \
  11. dbus-dev \
  12. gcc \
  13. git `# setuptools_scm` \
  14. glib-dev `# dbus-python` \
  15. gobject-introspection-dev `# PyGObject` \
  16. jq `# edit Pipfile.lock` \
  17. make `# dbus-python` \
  18. musl-dev `# dbus-python` \
  19. py3-certifi `# pipenv` \
  20. py3-pip `# pipenv install` \
  21. py3-virtualenv `# pipenv` \
  22. python3-dev `# dbus-python` \
  23. && adduser -S build
  24. USER build
  25. RUN pip3 install --user --no-cache-dir --break-system-packages pipenv==2024.4.0
  26. ARG SOURCE_DIR_PATH
  27. COPY --chown=build:nobody Pipfile Pipfile.lock $SOURCE_DIR_PATH/
  28. WORKDIR $SOURCE_DIR_PATH
  29. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
  30. PIPENV_VENV_IN_PROJECT=yes-please \
  31. PATH=/home/build/.local/bin:$PATH
  32. # `sponge` is not pre-installed
  33. RUN jq 'del(.default."systemctl-mqtt")' Pipfile.lock > Pipfile.lock~ \
  34. && mv Pipfile.lock~ Pipfile.lock \
  35. && pipenv install --deploy --verbose
  36. COPY --chown=build:nobody . $SOURCE_DIR_PATH
  37. # allow manual specification to support build without git history
  38. ARG SETUPTOOLS_SCM_PRETEND_VERSION=
  39. RUN pipenv install --deploy --verbose \
  40. && pipenv graph \
  41. && pipenv run pip freeze \
  42. && rm -rf .git/ $PIPENV_CACHE_DIR \
  43. && chmod -cR a+rX .
  44. # workaround for broken multi-stage copy
  45. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  46. USER 0
  47. RUN chown -R 0:0 $SOURCE_DIR_PATH
  48. USER build
  49. # hadolint ignore=DL3006
  50. FROM $BASE_IMAGE
  51. RUN apk add --no-cache \
  52. ca-certificates \
  53. dbus-libs \
  54. glib `# PyGObject` \
  55. gobject-introspection `# PyGObject` \
  56. python3 \
  57. tini \
  58. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  59. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  60. USER nobody
  61. ARG SOURCE_DIR_PATH
  62. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  63. ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
  64. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  65. ENTRYPOINT ["tini", "--"]
  66. CMD ["systemctl-mqtt", "--help"]