mq-quiz / Dockerfile
Teddy Xinyuan Chen
Revert "2024-10-08T22-01-58Z"
65866d3
# Use the official Python 3.11 image from the Docker Hub
FROM python:3.11
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements-dev.txt
# RUN pip install --no-cache-dir -r requirements-dev.txt
# my frozen requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 8000 available to the world outside this container
EXPOSE 8000
# Set environment variables (non-sensitive)
ENV DJANGO_SETTINGS_MODULE=quizsite.settings
ENV STATIC_BACKEND=whitenoise.storage.CompressedManifestStaticFilesStorage
ENV DEBUG=True
# Set environment variables (sensitive) using Hugging Face secrets management
RUN --mount=type=secret,id=DBHOST,mode=0444,required=true \
--mount=type=secret,id=DBNAME,mode=0444,required=true \
--mount=type=secret,id=DBUSER,mode=0444,required=true \
--mount=type=secret,id=DBPASS,mode=0444,required=true \
--mount=type=secret,id=DBSSL,mode=0444,required=true \
--mount=type=secret,id=SECRET_KEY,mode=0444,required=true \
--mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=true \
export DBHOST=$(cat /run/secrets/DBHOST) && \
export DBNAME=$(cat /run/secrets/DBNAME) && \
export DBUSER=$(cat /run/secrets/DBUSER) && \
export DBPASS=$(cat /run/secrets/DBPASS) && \
export DBSSL=$(cat /run/secrets/DBSSL) && \
export SECRET_KEY=$(cat /run/secrets/SECRET_KEY) && \
export OPENAI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY)
# Run the Django application
CMD ["python3", "src/manage.py", "runserver", "0.0.0.0:8000"]