Dockerfile-slim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. FROM python:bookworm
  2. ARG G4F_VERSION
  3. ARG G4F_USER=g4f
  4. ARG G4F_USER_ID=1000
  5. ARG PYDANTIC_VERSION=1.8.1
  6. ENV G4F_VERSION $G4F_VERSION
  7. ENV G4F_USER $G4F_USER
  8. ENV G4F_USER_ID $G4F_USER_ID
  9. ENV G4F_DIR /app
  10. RUN apt-get update && apt-get upgrade -y \
  11. && apt-get install -y git \
  12. && apt-get install --quiet --yes --no-install-recommends \
  13. build-essential \
  14. # Add user and user group
  15. && groupadd -g $G4F_USER_ID $G4F_USER \
  16. && useradd -rm -G sudo -u $G4F_USER_ID -g $G4F_USER_ID $G4F_USER \
  17. && mkdir -p /var/log/supervisor \
  18. && chown "${G4F_USER_ID}:${G4F_USER_ID}" /var/log/supervisor \
  19. && echo "${G4F_USER}:${G4F_USER}" | chpasswd
  20. USER $G4F_USER_ID
  21. WORKDIR $G4F_DIR
  22. ENV HOME /home/$G4F_USER
  23. ENV PATH "${HOME}/.local/bin:${HOME}/.cargo/bin:${PATH}"
  24. # Create app dir and copy the project's requirements file into it
  25. RUN mkdir -p $G4F_DIR
  26. COPY requirements-slim.txt $G4F_DIR
  27. # Install rust toolchain
  28. RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
  29. # Upgrade pip for the latest features and install the project's Python dependencies.
  30. RUN python -m pip install --upgrade pip \
  31. && pip install --no-cache-dir \
  32. Cython==0.29.22 \
  33. setuptools \
  34. # Install PyDantic
  35. && pip install \
  36. -vvv \
  37. --no-cache-dir \
  38. --no-binary pydantic \
  39. --global-option=build_ext \
  40. --global-option=-j8 \
  41. pydantic==${PYDANTIC_VERSION} \
  42. && pip install --no-cache-dir -r requirements-slim.txt \
  43. # Remove build packages
  44. && pip uninstall --yes \
  45. Cython \
  46. setuptools
  47. USER root
  48. # Clean up build deps
  49. RUN rustup self uninstall -y \
  50. && apt-get purge --auto-remove --yes \
  51. build-essential \
  52. && apt-get clean \
  53. && rm --recursive --force /var/lib/apt/lists/* /tmp/* /var/tmp/*
  54. USER $G4F_USER_ID
  55. # Copy the entire package into the container.
  56. ADD --chown=$G4F_USER:$G4F_USER g4f $G4F_DIR/g4f