Dockerfile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ARG BASE_IMAGE=docker.io/python:3.8.7-slim-buster
  2. ARG SOURCE_DIR_PATH=/location-guessing-game-telegram-bot
  3. # hadolint ignore=DL3006
  4. FROM $BASE_IMAGE as build
  5. # hadolint ignore=DL3008
  6. RUN apt-get update \
  7. && apt-get install --no-install-recommends --yes \
  8. ca-certificates \
  9. git `# setuptools_scm` \
  10. jq `# edit Pipfile.lock` \
  11. && rm -rf /var/lib/apt/lists/* \
  12. && useradd --create-home build
  13. USER build
  14. RUN pip install --user --no-cache-dir pipenv==2020.11.15
  15. ARG SOURCE_DIR_PATH
  16. COPY --chown=build Pipfile Pipfile.lock $SOURCE_DIR_PATH/
  17. WORKDIR $SOURCE_DIR_PATH
  18. ENV PIPENV_CACHE_DIR=/tmp/pipenv-cache \
  19. PIPENV_VENV_IN_PROJECT=yes-please \
  20. PATH=/home/build/.local/bin:$PATH
  21. # `sponge` is not pre-installed
  22. RUN jq 'del(.default."location-guessing-game-telegram-bot")' Pipfile.lock > Pipfile.lock~ \
  23. && mv Pipfile.lock~ Pipfile.lock \
  24. && pipenv install --deploy \
  25. && rm -rf $PIPENV_CACHE_DIR
  26. COPY --chown=build . $SOURCE_DIR_PATH
  27. RUN pipenv install --deploy \
  28. && pipenv run location-guessing-game-telegram-bot --help \
  29. && pipenv graph \
  30. && pipenv run pip freeze \
  31. && rm -rf .git/ $PIPENV_CACHE_DIR \
  32. && chmod -cR a+rX .
  33. # workaround for broken multi-stage copy
  34. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  35. USER 0
  36. RUN chown -R 0:0 $SOURCE_DIR_PATH
  37. USER build
  38. # hadolint ignore=DL3006
  39. FROM $BASE_IMAGE
  40. # hadolint ignore=DL3008
  41. RUN apt-get update \
  42. && apt-get install --no-install-recommends --yes ca-certificates \
  43. && rm -rf /var/lib/apt/lists/* \
  44. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  45. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  46. USER nobody
  47. ARG SOURCE_DIR_PATH
  48. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  49. ENV PATH=$SOURCE_DIR_PATH/.venv/bin:$PATH
  50. WORKDIR $SOURCE_DIR_PATH
  51. CMD ["location-guessing-game-telegram-bot"]
  52. # https://github.com/opencontainers/image-spec/blob/v1.0.1/annotations.md
  53. LABEL org.opencontainers.image.title="location guessing game telegram bot" \
  54. org.opencontainers.image.source="https://github.com/fphammerle/location-guessing-game-telegram-bot"