diff --git a/app/.dockerignore b/app/.dockerignore index 24d41b7..189bd3c 100644 --- a/app/.dockerignore +++ b/app/.dockerignore @@ -1 +1 @@ -*/local_settings.py \ No newline at end of file +app/local_settings.py \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile index e69de29..d73205d 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -0,0 +1,57 @@ +########### +# BUILDER # +########### + +# pull official base image +FROM python:3.10 as builder + +# set work directory +WORKDIR /usr/src/app + +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# install system dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends gcc + +# install python dependencies +COPY ./requirements.txt . +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt + + +######### +# FINAL # +######### + +# pull official base image +FROM python:3.10 + +# create directory for the app user +RUN mkdir -p /home/app + +# create the app user +RUN addgroup --system app && adduser --system --group app + +# create the appropriate directories +ENV HOME=/home/app +ENV APP_HOME=/home/app/web +RUN mkdir $APP_HOME +RUN mkdir $APP_HOME/static +WORKDIR $APP_HOME + +# install dependencies +RUN apt-get update && apt-get install -y --no-install-recommends netcat-traditional +RUN apt-get update && apt-get install -y libgl1-mesa-glx +COPY --from=builder /usr/src/app/wheels /wheels +COPY --from=builder /usr/src/app/requirements.txt . +RUN pip install --upgrade pip +RUN pip install --no-cache /wheels/* + +# copy project +COPY . $APP_HOME + +RUN chown -R app:app $APP_HOME + +USER app diff --git a/app/app/local_settings.py b/app/app/local_settings.py index daf035a..ba964d3 100644 --- a/app/app/local_settings.py +++ b/app/app/local_settings.py @@ -21,6 +21,9 @@ CHANNEL_LAYERS = { }, } -MIDDLEWARE = [ - "whitenoise.middleware.WhiteNoiseMiddleware", - ] \ No newline at end of file +# MIDDLEWARE = [ +# "whitenoise.middleware.WhiteNoiseMiddleware", +# ] + + +# STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" \ No newline at end of file diff --git a/app/app/settings.py b/app/app/settings.py index 67f109c..d9eb2f9 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -38,8 +38,6 @@ MIDDLEWARE = MIDDLEWARE + [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" - ROOT_URLCONF = 'app.urls' TEMPLATES = [ diff --git a/app/requirements.txt b/app/requirements.txt index 9faeac2..4cacbc0 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,8 @@ uvicorn==0.34.3 django==4.2 -dotenv==1.1.0 +dotenv channels==4.2.2 whitenoise==6.9.0 -websockets==15.0.1 \ No newline at end of file +websockets==15.0.1 +psycopg2-binary +django-redis==5.4.0 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 922ea27..c5111a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: web: - build: ./app/Dockerfile + build: ./app container_name: web command: > sh -c "python manage.py collectstatic --noinput &&