Browse Source

added dockerfile

https://github.com/fphammerle/switchbot-mqtt/commit/d82784cb9f0d62e2cd484bd01401412bc568472d
Fabian Peter Hammerle 3 years ago
parent
commit
d0a34c14ff
2 changed files with 71 additions and 0 deletions
  1. 10 0
      .dockerignore
  2. 61 0
      Dockerfile

+ 10 - 0
.dockerignore

@@ -0,0 +1,10 @@
+*
+# setuptools_scm
+!.git/
+.git/index
+!COPYING
+!Pipfile
+!Pipfile.lock
+!README.md
+!setup.py
+!intertechno_cc1101_mqtt

+ 61 - 0
Dockerfile

@@ -0,0 +1,61 @@
+# sync with https://github.com/fphammerle/wireless-sensor-mqtt/blob/master/Dockerfile
+
+ARG BASE_IMAGE=python:3.8-alpine3.13
+ARG SOURCE_DIR_PATH=/wireless-sensor-mqtt
+
+
+# hadolint ignore=DL3006
+FROM $BASE_IMAGE as build
+
+RUN apk add --no-cache \
+        gcc `# spidev build` \
+        git `# setuptools_scm` \
+        jq `# edit Pipfile.lock` \
+        linux-headers `# spidev build linux/spi/spidev.h` \
+        musl-dev `# spidev build` \
+    && adduser -S build
+
+USER build
+RUN pip install --user --no-cache-dir pipenv==2020.6.2
+
+ARG SOURCE_DIR_PATH
+COPY --chown=build:nobody Pipfile Pipfile.lock $SOURCE_DIR_PATH/
+WORKDIR $SOURCE_DIR_PATH
+ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
+    PIPENV_VENV_IN_PROJECT=yes-please \
+    PATH=/home/build/.local/bin:$PATH
+# `sponge` is not pre-installed
+RUN jq 'del(.default."intertechno-cc1101-mqtt")' Pipfile.lock > Pipfile.lock~ \
+    && mv Pipfile.lock~ Pipfile.lock \
+    && pipenv install --deploy --verbose
+COPY --chown=build:nobody . $SOURCE_DIR_PATH
+RUN pipenv install --deploy --verbose \
+    && pipenv graph \
+    && pipenv run pip freeze \
+    && rm -r .git/ $PIPENV_CACHE_DIR \
+    && chmod -cR a+rX .
+
+# workaround for broken multi-stage copy
+# > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
+USER 0
+RUN chown -R 0:0 $SOURCE_DIR_PATH
+USER build
+
+
+# hadolint ignore=DL3006
+FROM $BASE_IMAGE
+
+RUN apk add --no-cache \
+        ca-certificates \
+        tini \
+    && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
+    && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
+
+USER nobody
+
+ARG SOURCE_DIR_PATH
+COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
+ARG VIRTUALENV_PATH=$SOURCE_DIR_PATH/.venv
+ENV PATH=$VIRTUALENV_PATH/bin:$PATH
+ENTRYPOINT ["tini", "--"]
+CMD ["intertechno-cc1101-mqtt", "--help"]