hf_flask_api_demo_k9 / Dockerfile
thinh-vu's picture
Update Dockerfile
73dd60f verified
Raw
History Blame Contribute Delete
1.44 kB
# Mã nguồn file Dockerfile trong Huggingface Docker Space
# Builder stage
FROM python:3.10-slim as builder
WORKDIR /build
# Install git
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
# Arguments for secrets
ARG GIT_USER
ARG GITHUB_TOKEN
ARG GIT_REPO
# Clone the private repository using secrets
RUN --mount=type=secret,id=GIT_USER,mode=0444,required=true \
--mount=type=secret,id=GITHUB_TOKEN,mode=0444,required=true \
--mount=type=secret,id=GIT_REPO,mode=0444,required=true \
git clone https://$(cat /run/secrets/GIT_USER):$(cat /run/secrets/GITHUB_TOKEN)@github.com/$(cat /run/secrets/GIT_USER)/$(cat /run/secrets/GIT_REPO) .
RUN ls -la
# Final stage
FROM python:3.10-slim
# Install git in the final image
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
# Add user and set up environment
RUN useradd -m vns
USER vns
WORKDIR /usr/src/app
# Copy the cloned repository from the builder stage
COPY --from=builder /build/private_repo .
RUN ls -la
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Install additional Python packages
RUN pip install --no-cache-dir flask-jwt-extended flask-security
# Set PATH environment variable
ENV PATH="/home/vns/.local/bin:${PATH}"
# Expose the application port
EXPOSE 7860
# Command to run the application
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]