Dockerfile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. git `# setuptools_scm` \
  10. jq `# edit Pipfile.lock` \
  11. py3-certifi `# pipenv` \
  12. py3-pip `# pipenv install` \
  13. py3-virtualenv `# pipenv` \
  14. && adduser -S build
  15. USER build
  16. RUN pip3 install --user --no-cache-dir --break-system-packages pipenv==2024.4.0
  17. ARG SOURCE_DIR_PATH
  18. COPY --chown=build:nobody Pipfile Pipfile.lock $SOURCE_DIR_PATH/
  19. WORKDIR $SOURCE_DIR_PATH
  20. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
  21. PIPENV_VENV_IN_PROJECT=yes-please \
  22. PATH=/home/build/.local/bin:$PATH
  23. # `sponge` is not pre-installed
  24. RUN jq 'del(.default."systemctl-mqtt")' Pipfile.lock > Pipfile.lock~ \
  25. && mv Pipfile.lock~ Pipfile.lock \
  26. && pipenv install --deploy --verbose
  27. COPY --chown=build:nobody . $SOURCE_DIR_PATH
  28. # allow manual specification to support build without git history
  29. ARG SETUPTOOLS_SCM_PRETEND_VERSION=
  30. RUN pipenv install --deploy --verbose \
  31. && pipenv graph \
  32. && pipenv run pip freeze \
  33. && rm -rf .git/ $PIPENV_CACHE_DIR \
  34. && chmod -cR a+rX .
  35. # workaround for broken multi-stage copy
  36. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  37. USER 0
  38. RUN chown -R 0:0 $SOURCE_DIR_PATH
  39. USER build
  40. # hadolint ignore=DL3006
  41. FROM $BASE_IMAGE
  42. RUN apk add --no-cache \
  43. ca-certificates \
  44. python3 \
  45. tini \
  46. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  47. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  48. USER nobody
  49. ARG SOURCE_DIR_PATH
  50. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  51. ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
  52. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  53. ENTRYPOINT ["tini", "--"]
  54. CMD ["systemctl-mqtt", "--help"]