Create Dockerfile
Browse files- Dockerfile +73 -0
Dockerfile
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
+
|
| 3 |
+
# Comments are provided throughout this file to help you get started.
|
| 4 |
+
# If you need more help, visit the Dockerfile reference guide at
|
| 5 |
+
# https://docs.docker.com/go/dockerfile-reference/
|
| 6 |
+
|
| 7 |
+
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
|
| 8 |
+
|
| 9 |
+
ARG PYTHON_VERSION=3.11.9
|
| 10 |
+
FROM python:${PYTHON_VERSION}-slim as base
|
| 11 |
+
|
| 12 |
+
# Prevents Python from writing pyc files.
|
| 13 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 14 |
+
|
| 15 |
+
# Keeps Python from buffering stdout and stderr to avoid situations where
|
| 16 |
+
# the application crashes without emitting any logs due to buffering.
|
| 17 |
+
ENV PYTHONUNBUFFERED=1
|
| 18 |
+
|
| 19 |
+
WORKDIR /app
|
| 20 |
+
|
| 21 |
+
# Create a non-privileged user that the app will run under.
|
| 22 |
+
# See https://docs.docker.com/go/dockerfile-user-best-practices/
|
| 23 |
+
ARG UID=10001
|
| 24 |
+
RUN adduser \
|
| 25 |
+
--disabled-password \
|
| 26 |
+
--gecos "" \
|
| 27 |
+
--home "/nonexistent" \
|
| 28 |
+
--shell "/sbin/nologin" \
|
| 29 |
+
--no-create-home \
|
| 30 |
+
--uid "${UID}" \
|
| 31 |
+
appuser
|
| 32 |
+
|
| 33 |
+
# Download dependencies as a separate step to take advantage of Docker's caching.
|
| 34 |
+
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
|
| 35 |
+
# Leverage a bind mount to requirements.txt to avoid having to copy them into
|
| 36 |
+
# into this layer.
|
| 37 |
+
RUN --mount=type=cache,target=/root/.cache/pip \
|
| 38 |
+
--mount=type=bind,source=requirements.txt,target=requirements.txt \
|
| 39 |
+
python -m pip install -r requirements.txt
|
| 40 |
+
|
| 41 |
+
# Create a directory named 'data' and assign its ownership to appuser
|
| 42 |
+
RUN mkdir -p /data
|
| 43 |
+
RUN chown appuser /data
|
| 44 |
+
|
| 45 |
+
# Create a directory named 'images' and assign its ownership to appuser
|
| 46 |
+
RUN mkdir -p /images
|
| 47 |
+
RUN chown appuser /images
|
| 48 |
+
|
| 49 |
+
# Create the app.log file
|
| 50 |
+
RUN touch app.log
|
| 51 |
+
|
| 52 |
+
# Assign the ownership of app.log to appuser
|
| 53 |
+
RUN chown appuser app.log
|
| 54 |
+
|
| 55 |
+
# Switch to the non-privileged user to run the application.
|
| 56 |
+
USER appuser
|
| 57 |
+
|
| 58 |
+
# Set the TRANSFORMERS_CACHE environment variable
|
| 59 |
+
ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface
|
| 60 |
+
|
| 61 |
+
# Create the cache folder with appropriate permissions
|
| 62 |
+
RUN mkdir -p $TRANSFORMERS_CACHE && chmod -R 777 $TRANSFORMERS_CACHE
|
| 63 |
+
|
| 64 |
+
# Copy the source code into the container.
|
| 65 |
+
COPY . .
|
| 66 |
+
|
| 67 |
+
# Expose the port that the application listens on.
|
| 68 |
+
EXPOSE 7860
|
| 69 |
+
EXPOSE 8501
|
| 70 |
+
|
| 71 |
+
# Run the application.
|
| 72 |
+
# CMD uvicorn 'main:app' --host=0.0.0.0 --port=8000
|
| 73 |
+
CMD ["bash", "-c", "uvicorn main:app --host 0.0.0.0 --port 7860 & streamlit run BrainBot.py --server.port 8501"]
|