Dockerfile 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # not using python:3.*-alpine cause glib-dev package depends on python3
  2. # https://pkgs.alpinelinux.org/package/v3.11/main/aarch64/glib-dev
  3. ARG BASE_IMAGE=alpine:3.11
  4. ARG SOURCE_DIR_PATH=/systemctl-mqtt
  5. ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
  6. FROM $BASE_IMAGE as build
  7. RUN apk add --no-cache \
  8. dbus-dev \
  9. gcc \
  10. git `# setuptools_scm` \
  11. glib-dev `# dbus-python` \
  12. make `# dbus-python` \
  13. musl-dev `# dbus-python` \
  14. py3-virtualenv \
  15. python3-dev `# dbus-python`
  16. ARG SOURCE_DIR_PATH
  17. RUN mkdir $SOURCE_DIR_PATH \
  18. && chown nobody $SOURCE_DIR_PATH
  19. USER nobody
  20. ARG VIRTUALENV_PATH
  21. RUN virtualenv --no-site-packages $VIRTUALENV_PATH
  22. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  23. WORKDIR $SOURCE_DIR_PATH
  24. RUN pip install --no-cache-dir pipenv==2020.6.2
  25. COPY --chown=nobody . $SOURCE_DIR_PATH
  26. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache
  27. RUN pipenv install --deploy --verbose \
  28. && rm -r .git/ $PIPENV_CACHE_DIR
  29. # workaround for broken multi-stage copy
  30. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  31. USER 0
  32. RUN chown -R 0:0 $SOURCE_DIR_PATH
  33. FROM $BASE_IMAGE
  34. RUN apk add --no-cache \
  35. ca-certificates \
  36. dbus-libs \
  37. python3 \
  38. tini \
  39. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  40. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  41. USER nobody
  42. ARG SOURCE_DIR_PATH
  43. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  44. ARG VIRTUALENV_PATH
  45. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  46. ENTRYPOINT ["tini", "--"]
  47. CMD ["systemctl-mqtt", "--help"]