FROM python:3.11-slim WORKDIR /app # Grant write permissions to /app so that git clone can create a subdirectory RUN chmod 777 /app # Install git RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* # Environment variables for the application ENV APP_DIR_NAME=vertex ENV GIT_REPO_URL=https://huggingface.co/spaces/bibibi12345/vertex ENV ACTUAL_APP_SUBDIR=app ENV PIP_PACKAGES_DIR=/app/pip_packages # Create a directory for the credentials (if needed by the cloned app) RUN mkdir -p /app/credentials # Expose the port EXPOSE 7860 # Command to clone/pull, install dependencies into a specific directory, and run the application CMD /bin/sh -c '\ set -e; \ CLONED_REPO_PATH="/app/$APP_DIR_NAME"; \ ACTUAL_APP_PATH="$CLONED_REPO_PATH/$ACTUAL_APP_SUBDIR"; \ \ echo "Target repository directory: $CLONED_REPO_PATH"; \ echo "Actual application directory: $ACTUAL_APP_PATH"; \ echo "Pip packages will be installed in: $PIP_PACKAGES_DIR"; \ \ mkdir -p "$PIP_PACKAGES_DIR"; \ export PYTHONPATH="$PIP_PACKAGES_DIR${PYTHONPATH:+:$PYTHONPATH}"; \ export PATH="$PIP_PACKAGES_DIR/bin${PATH:+:$PATH}"; \ \ if [ ! -d "$CLONED_REPO_PATH/.git" ]; then \ echo "Cloning repository $GIT_REPO_URL into $CLONED_REPO_PATH..."; \ git clone "$GIT_REPO_URL" "$CLONED_REPO_PATH"; \ else \ echo "Repository exists in $CLONED_REPO_PATH. Pulling latest changes..."; \ cd "$CLONED_REPO_PATH"; \ git config --global --add safe.directory "$CLONED_REPO_PATH"; \ git pull; \ fi; \ \ echo "Changing directory to actual application path: $ACTUAL_APP_PATH"; \ cd "$ACTUAL_APP_PATH"; \ \ echo "Current directory for dependencies and app launch: $(pwd)"; \ if [ -f "requirements.txt" ]; then \ echo "Installing dependencies from requirements.txt into $PIP_PACKAGES_DIR..."; \ pip install --no-cache-dir -r requirements.txt --target "$PIP_PACKAGES_DIR"; \ else \ echo "requirements.txt not found in $(pwd). Skipping pip install."; \ fi; \ \ echo "PYTHONPATH is: $PYTHONPATH"; \ echo "PATH is: $PATH"; \ echo "Looking for uvicorn:"; \ which uvicorn || echo "uvicorn not found in PATH"; \ \ echo "Starting application (uvicorn main:app) on port 7860 from $(pwd)..."; \ exec uvicorn main:app --host 0.0.0.0 --port 7860'