Dockerfile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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=/switchbot-mqtt
  5. ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
  6. FROM $BASE_IMAGE as build
  7. RUN apk add --no-cache \
  8. gcc \
  9. git `# setuptools_scm` \
  10. glib-dev \
  11. make \
  12. musl-dev \
  13. py3-virtualenv
  14. ARG SOURCE_DIR_PATH
  15. RUN mkdir $SOURCE_DIR_PATH \
  16. && chown nobody $SOURCE_DIR_PATH
  17. USER nobody
  18. ARG VIRTUALENV_PATH
  19. RUN virtualenv --no-site-packages $VIRTUALENV_PATH
  20. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  21. WORKDIR $SOURCE_DIR_PATH
  22. RUN pip install --no-cache-dir pipenv==2020.6.2
  23. COPY --chown=nobody . $SOURCE_DIR_PATH
  24. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache
  25. RUN pipenv install --deploy --verbose \
  26. && rm -r .git/ $PIPENV_CACHE_DIR
  27. # workaround for broken multi-stage copy
  28. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  29. USER 0
  30. RUN chown -R 0:0 $SOURCE_DIR_PATH
  31. FROM $BASE_IMAGE
  32. RUN apk add --no-cache \
  33. glib \
  34. python3 \
  35. tini \
  36. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  37. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  38. #RUN apk add bluez-deprecated `# hcitool`
  39. USER nobody
  40. ARG SOURCE_DIR_PATH
  41. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  42. ARG VIRTUALENV_PATH
  43. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  44. ENTRYPOINT ["tini", "--"]
  45. CMD ["switchbot-mqtt", "--help"]