1
0

Dockerfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # sync with https://github.com/fphammerle/systemctl-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=alpine:3.13.1
  5. ARG SOURCE_DIR_PATH=/switchbot-mqtt
  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-certifi `# pipenv` \
  14. py3-pip `# pipenv install` \
  15. py3-virtualenv `# pipenv` \
  16. && adduser -S build
  17. USER build
  18. RUN pip3 install --user --no-cache-dir pipenv==2020.6.2
  19. ARG SOURCE_DIR_PATH
  20. COPY --chown=build:nobody . $SOURCE_DIR_PATH
  21. WORKDIR $SOURCE_DIR_PATH
  22. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
  23. PIPENV_VENV_IN_PROJECT=yes-please \
  24. PATH=/home/build/.local/bin:$PATH
  25. RUN pipenv install --deploy --verbose \
  26. && pipenv graph \
  27. && pipenv run pip freeze \
  28. && rm -r .git/ $PIPENV_CACHE_DIR \
  29. && chmod -cR a+rX .
  30. # workaround for broken multi-stage copy
  31. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  32. USER 0
  33. RUN chown -R 0:0 $SOURCE_DIR_PATH
  34. USER build
  35. FROM $BASE_IMAGE
  36. RUN apk add --no-cache \
  37. glib \
  38. python3 \
  39. tini \
  40. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  41. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  42. #RUN apk add bluez-deprecated `# hcitool`
  43. USER nobody
  44. ARG SOURCE_DIR_PATH
  45. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  46. ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
  47. ENV PATH=$VIRTUALENV_PATH/bin:$PATH
  48. ENV MQTT_HOST ""
  49. ENV MQTT_PORT "1883"
  50. ENV MQTT_USERNAME ""
  51. ENV MQTT_PASSWORD ""
  52. ENTRYPOINT ["tini", "--"]
  53. CMD ["sh", "-c", "switchbot-mqtt --mqtt-host \"$MQTT_HOST\" --mqtt-port \"$MQTT_PORT\" --mqtt-username \"$MQTT_USERNAME\" --mqtt-password \"$MQTT_PASSWORD\""]