Spaces:
Paused
Paused
Upload Dockerfile
Browse files- Dockerfile +64 -20
Dockerfile
CHANGED
|
@@ -1,20 +1,64 @@
|
|
| 1 |
-
FROM python:3.11-slim
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Grant write permissions to /app so that git clone can create a subdirectory
|
| 6 |
+
RUN chmod 777 /app
|
| 7 |
+
|
| 8 |
+
# Install git
|
| 9 |
+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
# Environment variables for the application
|
| 12 |
+
ENV APP_DIR_NAME=vertex
|
| 13 |
+
ENV GIT_REPO_URL=https://huggingface.co/spaces/bibibi12345/vertex
|
| 14 |
+
ENV ACTUAL_APP_SUBDIR=app
|
| 15 |
+
ENV PIP_PACKAGES_DIR=/app/pip_packages
|
| 16 |
+
|
| 17 |
+
# Create a directory for the credentials (if needed by the cloned app)
|
| 18 |
+
RUN mkdir -p /app/credentials
|
| 19 |
+
|
| 20 |
+
# Expose the port
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# Command to clone/pull, install dependencies into a specific directory, and run the application
|
| 24 |
+
CMD /bin/sh -c '\
|
| 25 |
+
set -e; \
|
| 26 |
+
CLONED_REPO_PATH="/app/$APP_DIR_NAME"; \
|
| 27 |
+
ACTUAL_APP_PATH="$CLONED_REPO_PATH/$ACTUAL_APP_SUBDIR"; \
|
| 28 |
+
\
|
| 29 |
+
echo "Target repository directory: $CLONED_REPO_PATH"; \
|
| 30 |
+
echo "Actual application directory: $ACTUAL_APP_PATH"; \
|
| 31 |
+
echo "Pip packages will be installed in: $PIP_PACKAGES_DIR"; \
|
| 32 |
+
\
|
| 33 |
+
mkdir -p "$PIP_PACKAGES_DIR"; \
|
| 34 |
+
export PYTHONPATH="$PIP_PACKAGES_DIR${PYTHONPATH:+:$PYTHONPATH}"; \
|
| 35 |
+
export PATH="$PIP_PACKAGES_DIR/bin${PATH:+:$PATH}"; \
|
| 36 |
+
\
|
| 37 |
+
if [ ! -d "$CLONED_REPO_PATH/.git" ]; then \
|
| 38 |
+
echo "Cloning repository $GIT_REPO_URL into $CLONED_REPO_PATH..."; \
|
| 39 |
+
git clone "$GIT_REPO_URL" "$CLONED_REPO_PATH"; \
|
| 40 |
+
else \
|
| 41 |
+
echo "Repository exists in $CLONED_REPO_PATH. Pulling latest changes..."; \
|
| 42 |
+
cd "$CLONED_REPO_PATH"; \
|
| 43 |
+
git config --global --add safe.directory "$CLONED_REPO_PATH"; \
|
| 44 |
+
git pull; \
|
| 45 |
+
fi; \
|
| 46 |
+
\
|
| 47 |
+
echo "Changing directory to actual application path: $ACTUAL_APP_PATH"; \
|
| 48 |
+
cd "$ACTUAL_APP_PATH"; \
|
| 49 |
+
\
|
| 50 |
+
echo "Current directory for dependencies and app launch: $(pwd)"; \
|
| 51 |
+
if [ -f "requirements.txt" ]; then \
|
| 52 |
+
echo "Installing dependencies from requirements.txt into $PIP_PACKAGES_DIR..."; \
|
| 53 |
+
pip install --no-cache-dir -r requirements.txt --target "$PIP_PACKAGES_DIR"; \
|
| 54 |
+
else \
|
| 55 |
+
echo "requirements.txt not found in $(pwd). Skipping pip install."; \
|
| 56 |
+
fi; \
|
| 57 |
+
\
|
| 58 |
+
echo "PYTHONPATH is: $PYTHONPATH"; \
|
| 59 |
+
echo "PATH is: $PATH"; \
|
| 60 |
+
echo "Looking for uvicorn:"; \
|
| 61 |
+
which uvicorn || echo "uvicorn not found in PATH"; \
|
| 62 |
+
\
|
| 63 |
+
echo "Starting application (uvicorn main:app) on port 7860 from $(pwd)..."; \
|
| 64 |
+
exec uvicorn main:app --host 0.0.0.0 --port 7860'
|