1
0

Dockerfile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # This Dockerfile installs Sydent from source, which is assumed to be in the current
  2. # working directory. The resulting image contains a single "sydent" user, and populates
  3. # their home area with "src" and "venv" directories. The entrypoint runs Sydent,
  4. # listening on port 8090.
  5. #
  6. # Users must provide a persistent volume available to the container as `/data`. This
  7. # will contain Sydent's configuration and database. A blank configuration and database
  8. # file is created the first time Sydent runs.
  9. # Step 1: install dependencies
  10. FROM docker.io/python:3.8-slim as builder
  11. # Add user sydent
  12. RUN addgroup --system --gid 993 sydent \
  13. && adduser --disabled-login --system --uid 993 --gecos sydent sydent
  14. USER sydent:sydent
  15. # Install poetry
  16. RUN pip install --user poetry==1.1.12
  17. # Copy source code and resources
  18. WORKDIR /home/sydent/src
  19. COPY --chown=sydent:sydent ["res", "res"]
  20. COPY --chown=sydent:sydent ["scripts", "scripts"]
  21. COPY --chown=sydent:sydent ["sydent", "sydent"]
  22. COPY --chown=sydent:sydent ["README.rst", "pyproject.toml", "poetry.lock", "./"]
  23. # Install dependencies
  24. RUN python -m poetry install --no-dev --no-interaction
  25. # Record dependencies for posterity
  26. RUN python -m poetry export -o requirements.txt
  27. # Make the virtualenv accessible for the final image
  28. RUN ln -s $(python -m poetry env info -p) /home/sydent/venv
  29. # Nuke bytecode files to keep the final image slim.
  30. RUN find /home/sydent/venv -type f -name '*.pyc' -delete
  31. # Step 2: Create runtime image
  32. FROM docker.io/python:3.8-slim
  33. # Add user sydent and create /data directory
  34. RUN addgroup --system --gid 993 sydent \
  35. && adduser --disabled-login --home /sydent --system --uid 993 --gecos sydent sydent \
  36. && mkdir /data \
  37. && chown sydent:sydent /data
  38. # Copy sydent and the virtualenv
  39. COPY --from=builder ["/home/sydent/src", "/home/sydent/src"]
  40. COPY --from=builder ["/home/sydent/venv", "/home/sydent/venv"]
  41. ENV SYDENT_CONF=/data/sydent.conf
  42. ENV SYDENT_PID_FILE=/data/sydent.pid
  43. ENV SYDENT_DB_PATH=/data/sydent.db
  44. WORKDIR /home/sydent
  45. USER sydent:sydent
  46. VOLUME ["/data"]
  47. EXPOSE 8090/tcp
  48. CMD [ "venv/bin/python", "-m", "sydent.sydent" ]