markdown_seo / Dockerfile
thinh-vu's picture
fix installation of seo_analyzer
2392ff5
Raw
History Blame Contribute Delete
2.77 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 the private repositories using 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..." && \
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 && \
echo "Processing primary repository..." && \
first_repo=false; \
else \
echo "Processing dependency repository..." && \
pip install --no-cache-dir /build/$repo; \
fi; \
done
# Debug to confirm structure in builder stage
RUN echo "Cloned repositories:" && ls -la /build && \
echo "Primary repository directory:" && cat /build/main_repo_dir.txt && \
echo "Contents of primary repository:" && ls -la /build/$(cat /build/main_repo_dir.txt)
# Final stage
FROM python:3.10-slim
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 the cloned repositories from the builder stage to the final image
COPY --from=builder /build /usr/src/app
# Reinstall `seo-analyzer` in the final stage
RUN pip install --no-cache-dir /usr/src/app/hf_seo_core_engine
# Set PYTHONPATH to ensure `seo-analyzer` is accessible
ENV PYTHONPATH="/usr/src/app:$PYTHONPATH"
# Debug to confirm `seo-analyzer` installation
RUN python -m pip show seo-analyzer
# Read the dynamically determined primary repository 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
# Expose the application port
EXPOSE 7860
# Set working directory to dynamically copied app directory
WORKDIR /usr/src/app/main_app/private_repo
# Confirm files in the application directory
RUN echo "Listing files in the application directory:" && ls -la
# Command to run the main application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]