Dockerfile 2.2 KB

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