sepsis-fastapi / Dockerfile
gabcares's picture
Expose the secret SECRETS at build-time
3e986da verified
FROM python:3.11.9-slim
# Expose the secret SECRETS at build-time
RUN --mount=type=secret,id=REDIS_URL,mode=0444,required=true
RUN --mount=type=secret,id=REDIS_USERNAME,mode=0444,required=true
RUN --mount=type=secret,id=REDIS_PASSWORD,mode=0444,required=true
# Read secrets and set environment variables
RUN export REDIS_URL=$(cat /run/secrets/REDIS_URL) \
&& export REDIS_USERNAME=$(cat /run/secrets/REDIS_USERNAME) \
&& export REDIS_PASSWORD=$(cat /run/secrets/REDIS_PASSWORD) \
&& echo "REDIS_URL=$REDIS_URL" >> /etc/environment \
&& echo "REDIS_USERNAME=$REDIS_USERNAME" >> /etc/environment \
&& echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> /etc/environment
# Source the environment file
RUN . /etc/environment
# Copy requirements file
COPY requirements.txt .
# Update pip
RUN pip --timeout=3000 install --no-cache-dir --upgrade pip
# Install dependecies
RUN pip --timeout=3000 install --no-cache-dir -r requirements.txt
# Make project directory
RUN mkdir -p /src/api/
# Set working directory
WORKDIR /src/api
# Copy API
COPY . .
# Expose app port
EXPOSE 7860
# Start application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]