Dockerfile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ARG BASE_IMAGE=docker.io/python:3.10.0-slim-bullseye
  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", .default."sanitized-package")' 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. # allow manual specification to support build without git history
  28. ARG SETUPTOOLS_SCM_PRETEND_VERSION=
  29. RUN pipenv install --deploy \
  30. && pipenv run location-guessing-game-telegram-bot --help \
  31. && pipenv graph \
  32. && pipenv run pip freeze \
  33. && rm -rf .git/ $PIPENV_CACHE_DIR \
  34. && chmod -cR a+rX .
  35. # workaround for broken multi-stage copy
  36. # > failed to copy files: failed to copy directory: Error processing tar file(exit status 1): Container ID ... cannot be mapped to a host ID
  37. USER 0
  38. RUN chown -R 0:0 $SOURCE_DIR_PATH
  39. USER build
  40. # hadolint ignore=DL3006
  41. FROM $BASE_IMAGE
  42. # hadolint ignore=DL3008
  43. RUN apt-get update \
  44. && apt-get install --no-install-recommends --yes ca-certificates \
  45. && rm -rf /var/lib/apt/lists/* \
  46. && find / -xdev -type f -perm /u+s -exec chmod -c u-s {} \; \
  47. && find / -xdev -type f -perm /g+s -exec chmod -c g-s {} \;
  48. USER nobody
  49. ARG SOURCE_DIR_PATH
  50. COPY --from=build $SOURCE_DIR_PATH $SOURCE_DIR_PATH
  51. ENV PATH=$SOURCE_DIR_PATH/.venv/bin:$PATH
  52. WORKDIR $SOURCE_DIR_PATH
  53. CMD ["location-guessing-game-telegram-bot"]
  54. # https://github.com/opencontainers/image-spec/blob/v1.0.1/annotations.md
  55. LABEL org.opencontainers.image.title="location guessing game telegram bot" \
  56. org.opencontainers.image.source="https://github.com/fphammerle/location-guessing-game-telegram-bot"