Rodrigo Schmidt Nurmberg
commited on
Commit
·
745fe4a
1
Parent(s):
93bd6ae
build: Enhance Docker build configuration
Browse filesThis commit improves the Docker build process in three ways:
- The Dockerfile now runs `gradio cc build` to force the recompilation of project components, ensuring that any changes are always reflected in the final build.
- A `requirements.txt` file has been added to streamline dependency management, which simplifies the multi-stage build process.
- A `.dockerignore` file is now included to prevent unnecessary files and directories (like `.git`, `__pycache__`) from being copied into the build context.
- .dockerignore +39 -0
- Dockerfile +43 -7
- src/requirements.txt +1 -0
.dockerignore
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Include any files or directories that you don't want to be copied to your
|
| 2 |
+
# container here (e.g., local build artifacts, temporary files, etc.).
|
| 3 |
+
#
|
| 4 |
+
# For more help, visit the .dockerignore file reference guide at
|
| 5 |
+
# https://docs.docker.com/go/build-context-dockerignore/
|
| 6 |
+
|
| 7 |
+
**/.DS_Store
|
| 8 |
+
**/__pycache__
|
| 9 |
+
**/.venv
|
| 10 |
+
**/.classpath
|
| 11 |
+
**/.dockerignore
|
| 12 |
+
**/.env
|
| 13 |
+
**/.git
|
| 14 |
+
**/.github
|
| 15 |
+
**/.gitignore
|
| 16 |
+
**/.gitmodules
|
| 17 |
+
**/.gitattributes
|
| 18 |
+
**/.project
|
| 19 |
+
**/.settings
|
| 20 |
+
**/.toolstarget
|
| 21 |
+
**/.vs
|
| 22 |
+
**/.vscode
|
| 23 |
+
**/*.*proj.user
|
| 24 |
+
**/*.dbmdl
|
| 25 |
+
**/*.jfm
|
| 26 |
+
**/*.env
|
| 27 |
+
**/docker-compose*
|
| 28 |
+
**/compose*.y*ml
|
| 29 |
+
**/Dockerfile*
|
| 30 |
+
**/nginx
|
| 31 |
+
**/node_modules
|
| 32 |
+
**/npm-debug.log
|
| 33 |
+
**/obj
|
| 34 |
+
**/secrets.dev.yaml
|
| 35 |
+
**/values.dev.yaml
|
| 36 |
+
**/LICENSE
|
| 37 |
+
**/CHANGELOG.md
|
| 38 |
+
**/INSTALL.md
|
| 39 |
+
|
Dockerfile
CHANGED
|
@@ -1,16 +1,52 @@
|
|
| 1 |
|
| 2 |
-
FROM python:3.11
|
| 3 |
|
| 4 |
WORKDIR /code
|
| 5 |
|
| 6 |
-
COPY --
|
| 7 |
|
| 8 |
-
RUN
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
RUN pip install --
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
|
| 2 |
+
FROM python:3.11-slim as builder
|
| 3 |
|
| 4 |
WORKDIR /code
|
| 5 |
|
| 6 |
+
COPY --chown=1000 . .
|
| 7 |
|
| 8 |
+
RUN apt-get update \
|
| 9 |
+
&& apt-get install npm -y --no-install-recommends \
|
| 10 |
+
&& apt-get clean \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
RUN python -m pip install --upgrade pip \
|
| 14 |
+
&& pip install build \
|
| 15 |
+
&& pip install -r /code/src/requirements.txt
|
| 16 |
|
| 17 |
+
RUN cd /code/src \
|
| 18 |
+
&& cd frontend \
|
| 19 |
+
&& npm i -D @gradio/preview@0.11.2 \
|
| 20 |
+
&& cd .. \
|
| 21 |
+
&& gradio cc install \
|
| 22 |
+
&& gradio cc build
|
| 23 |
|
| 24 |
+
FROM python:3.11-slim as final
|
| 25 |
+
|
| 26 |
+
RUN groupadd -r appgroup \
|
| 27 |
+
&& useradd -r -g appgroup -d /home/appuser -m appuser
|
| 28 |
+
|
| 29 |
+
WORKDIR /home/appuser/app
|
| 30 |
+
|
| 31 |
+
RUN mkdir -p /tmp/cache/ \
|
| 32 |
+
&& chmod a+rwx -R /tmp/cache/
|
| 33 |
+
|
| 34 |
+
COPY --chown=appuser:appgroup . .
|
| 35 |
+
COPY --from=builder --chown=appuser:appgroup /code/src/dist/*.whl ./
|
| 36 |
+
|
| 37 |
+
USER appuser
|
| 38 |
+
|
| 39 |
+
ENV PATH="/home/appuser/.local/bin:$PATH" \
|
| 40 |
+
TRANSFORMERS_CACHE=/tmp/cache/ \
|
| 41 |
+
PYTHONUNBUFFERED=1 \
|
| 42 |
+
GRADIO_ALLOW_FLAGGING=never \
|
| 43 |
+
GRADIO_NUM_PORTS=1 \
|
| 44 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
| 45 |
+
GRADIO_SERVER_PORT=7860 \
|
| 46 |
+
SYSTEM=spaces
|
| 47 |
+
|
| 48 |
+
RUN python -m pip install --upgrade pip \
|
| 49 |
+
&& pip install ./gradio_highlightedtextbox*.whl
|
| 50 |
+
|
| 51 |
+
EXPOSE 7860
|
| 52 |
CMD ["python", "app.py"]
|
src/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio<5.0,>=4.0
|