Dockerization, whitenoise serving static, refactor
This commit is contained in:
48
app_urls/Dockerfile
Normal file
48
app_urls/Dockerfile
Normal file
@@ -0,0 +1,48 @@
|
||||
FROM python:3.12
|
||||
|
||||
# Prevents Python from writing pyc files to disk
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
#Prevents Python from buffering stdout and stderr
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# User
|
||||
RUN useradd -m -r appuser && \
|
||||
mkdir /opt/app && \
|
||||
chown -R appuser /opt/app
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
# Copy the Django project and install dependencies
|
||||
COPY requirements.txt /opt/app/
|
||||
# run this command to install all dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY --chown=appuser:appuser . /opt/app/
|
||||
|
||||
RUN chmod -R 755 /opt/app
|
||||
RUN chown -R appuser:appuser /opt/app
|
||||
USER appuser
|
||||
|
||||
# Initialization script
|
||||
RUN echo '#!/bin/bash' > /opt/app/initialize.sh && \
|
||||
echo 'if [ "${INITIALIZE_DB}" = false ]; then' >> /opt/app/initialize.sh && \
|
||||
echo 'echo "Initialization not required"' >> /opt/app/initialize.sh && \
|
||||
echo 'else' >> /opt/app/initialize.sh && \
|
||||
echo 'echo "Initializating database"' >> /opt/app/initialize.sh && \
|
||||
echo 'sleep 5' >> /opt/app/initialize.sh && \
|
||||
echo 'python db.py --initialize_tables --initialize_data' >> /opt/app/initialize.sh && \
|
||||
echo 'python manage.py makemigrations fetcher; python manage.py migrate --fake-initial' >> /opt/app/initialize.sh && \
|
||||
echo 'python manage.py createsuperuser --noinput' >> /opt/app/initialize.sh && \
|
||||
echo 'python manage.py collectstatic --no-input' >> /opt/app/initialize.sh && \
|
||||
echo 'python manage.py import --filename scheduled_tasks.json' >> /opt/app/initialize.sh && \
|
||||
echo 'fi' >> /opt/app/initialize.sh && \
|
||||
chmod +x /opt/app/initialize.sh
|
||||
|
||||
# Serving script
|
||||
RUN echo '#!/bin/bash' > /opt/app/run.sh && \
|
||||
echo 'gunicorn core.wsgi:application --bind 0.0.0.0:8000 & python manage.py rqworker high default low' >> /opt/app/run.sh && \
|
||||
#echo 'python manage.py runserver & python manage.py rqworker high default low' >> /opt/app/run.sh && \
|
||||
chmod +x /opt/app/run.sh
|
||||
|
||||
# Run Django’s server & workers
|
||||
CMD ["sh", "-c", "/opt/app/initialize.sh && /opt/app/run.sh"]
|
||||
Reference in New Issue
Block a user