mq-quiz / Dockerfile
Teddy Xinyuan Chen
2024-10-08T22-01-58Z
0824581
raw
history blame
1.12 kB
# 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.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=False
# Create a script to read secrets and run the application
RUN echo '#!/bin/bash\n\
export DBHOST=$(cat /run/secrets/DBHOST)\n\
export DBNAME=$(cat /run/secrets/DBNAME)\n\
export DBUSER=$(cat /run/secrets/DBUSER)\n\
export DBPASS=$(cat /run/secrets/DBPASS)\n\
export DBSSL=$(cat /run/secrets/DBSSL)\n\
export SECRET_KEY=$(cat /run/secrets/SECRET_KEY)\n\
export OPENAI_API_KEY=$(cat /run/secrets/OPENAI_API_KEY)\n\
python3 src/manage.py runserver 0.0.0.0:8000\n'\
> /app/run.sh && chmod +x /app/run.sh
# Run the script
CMD ["/app/run.sh"]