Dockerfile 2.3 KB

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