pda / Dockerfile
thinh-vu's picture
Upload 2 files
6624ced verified
Raw
History Blame Contribute Delete
3.29 kB
# ---------------------
# Builder Stage
# ---------------------
FROM python:3.10-slim as builder
WORKDIR /build
# Install git and other dependencies
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
# Arguments for secrets
ARG GIT_USER
ARG GIT_TOKEN
ARG GIT_REPO_LIST
# Clone private repositories using build-time secrets
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
--mount=type=secret,id=GIT_TOKEN,mode=0444,required=true \
--mount=type=secret,id=GIT_REPO_LIST,mode=0444,required=true \
repos=$(cat /run/secrets/GIT_REPO_LIST) && \
first_repo=true && \
for repo in $repos; do \
echo "Cloning repository -> $repo" && \
git clone https://$(cat /run/secrets/GIT_USER):$(cat /run/secrets/GIT_TOKEN)@github.com/$(cat /run/secrets/GIT_USER)/$repo.git; \
if [ "$first_repo" = true ]; then \
echo "$repo" > /build/main_repo_dir.txt && \
first_repo=false; \
else \
echo "Installing dependency repository: $repo" && \
pip install --no-cache-dir /build/$repo; \
fi; \
done
# Debug: List out the structure
RUN echo "Cloned repositories in builder stage:" && ls -la /build && \
echo "Primary repository directory name:" && cat /build/main_repo_dir.txt && \
echo "Contents of the primary repository:" && ls -la /build/$(cat /build/main_repo_dir.txt)
# ---------------------
# Final Stage
# ---------------------
FROM python:3.10-slim
# Set the working directory
WORKDIR /usr/src/app
# Install git in the final image
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
# Copy from builder
COPY --from=builder /build /usr/src/app
# Reinstall the numerology app (assuming the main code is in /usr/src/app/numerology_reading)
RUN pip install --no-cache-dir /usr/src/app/numerology_reading
# Ensure Python can find your code
ENV PYTHONPATH="/usr/src/app:$PYTHONPATH"
# Read the main repo directory
RUN MAIN_REPO_DIR=$(cat /usr/src/app/main_repo_dir.txt) && \
echo "Primary repository is $MAIN_REPO_DIR" && \
cp -r /usr/src/app/$MAIN_REPO_DIR /usr/src/app/main_app && \
if [ -f /usr/src/app/main_app/private_repo/requirements.txt ]; then \
pip install --no-cache-dir -r /usr/src/app/main_app/private_repo/requirements.txt; \
fi
# -----------------------------------------------
# Grant system-wide permissions to /usr/src/app
# -----------------------------------------------
RUN chmod -R 777 /usr/src/app
# Expose port for your numerology API
EXPOSE 7860
# Switch to the final directory (if your "app.py" or "app:app" is here)
WORKDIR /usr/src/app/main_app/private_repo
RUN echo "Installed packages in the workdir:" && pip freeze
# Debug: List files
RUN echo "Files in /usr/src/app/main_app/private_repo:" && ls -la
# Start uvicorn on container run
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]