From 818c1f5345c865529bdb625bf19272420454fd65 Mon Sep 17 00:00:00 2001 From: Aaron Su Date: Tue, 10 Dec 2024 07:58:58 -0500 Subject: [PATCH] Upgrade Django to 4.2 --- src/django/Dockerfile | 32 ++++++----- src/django/gunicorn.conf.py | 17 ++++++ .../0050_update_pfb_analysis_and_user.py | 56 +++++++++++++++++++ src/django/requirements.txt | 8 ++- .../0005_update_pfb_analysis_and_user.py | 35 ++++++++++++ 5 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 src/django/gunicorn.conf.py create mode 100644 src/django/pfb_analysis/migrations/0050_update_pfb_analysis_and_user.py create mode 100644 src/django/users/migrations/0005_update_pfb_analysis_and_user.py diff --git a/src/django/Dockerfile b/src/django/Dockerfile index b52fd50f..dd78ddfa 100644 --- a/src/django/Dockerfile +++ b/src/django/Dockerfile @@ -1,23 +1,29 @@ # Note: the Django and psycopg2 versions are repeated in requirements.txt for the benefit # of the analysis container. The base container and requirements file versions should be kept # in sync. -FROM quay.io/azavea/django:3.2-python3.10-slim - -MAINTAINER Azavea +FROM python:3.10-slim-bullseye +WORKDIR /usr/src COPY requirements.txt /tmp/ -RUN pip3 install --no-cache-dir -r /tmp/requirements.txt + +RUN set -ex \ + && buildDeps=" \ + build-essential \ + libpq-dev \ + " \ + && deps=" \ + gdal-bin \ + libgdal-dev \ + gettext \ + postgresql-client-13 \ + " \ + && apt-get update && apt-get install -y $buildDeps $deps --no-install-recommends \ + && pip install --no-cache-dir -r /tmp/requirements.txt \ + && apt-get purge -y --auto-remove $buildDeps \ + && rm -rf /tmp/requirements.txt /var/lib/apt/lists/* COPY . /usr/src -WORKDIR /usr/src EXPOSE 9202 -CMD ["-w", "1", \ - "-b", "0.0.0.0:9202", \ - "--reload", \ - "--log-level", "info", \ - "--error-logfile", "-", \ - "--forwarded-allow-ips", "*", \ - "-k", "gevent", \ - "pfb_network_connectivity.wsgi"] +ENTRYPOINT ["/usr/local/bin/gunicorn"] diff --git a/src/django/gunicorn.conf.py b/src/django/gunicorn.conf.py new file mode 100644 index 00000000..ce81cb2c --- /dev/null +++ b/src/django/gunicorn.conf.py @@ -0,0 +1,17 @@ +import os + +bind = ":9202" +accesslog = "-" +errorlog = "-" +workers = 3 +worker_class = 'gevent' +loglevel = "Info" + +ENVIRONMENT = os.getenv("DJANGO_ENV", "dev") + +if ENVIRONMENT == "development": + reload = True +else: + preload = True + +wsgi_app = "pfb_network_connectivity.wsgi" diff --git a/src/django/pfb_analysis/migrations/0050_update_pfb_analysis_and_user.py b/src/django/pfb_analysis/migrations/0050_update_pfb_analysis_and_user.py new file mode 100644 index 00000000..ff0fcfb0 --- /dev/null +++ b/src/django/pfb_analysis/migrations/0050_update_pfb_analysis_and_user.py @@ -0,0 +1,56 @@ +# Generated by Django 4.2.17 on 2024-12-19 21:54 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('pfb_analysis', '0049_neighborhood_geog'), + ] + + operations = [ + migrations.AlterField( + model_name='analysisbatch', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='analysisbatch', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='analysisjob', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='analysisjob', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='analysislocaluploadtask', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='analysislocaluploadtask', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='neighborhood', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='neighborhood', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/django/requirements.txt b/src/django/requirements.txt index a17880de..5548e92c 100644 --- a/src/django/requirements.txt +++ b/src/django/requirements.txt @@ -4,7 +4,7 @@ # Ideally these should be kept in sync with the versions in the base container # (https://github.com/azavea/docker-django/blob/master/3.2/requirements.txt) to avoid # downgrading when building the django container. -Django==3.2.13 +Django==4.2.17 psycopg2-binary==2.9.3 boto3==1.23.10 @@ -16,9 +16,11 @@ django-filter==2.4.0 django-q==1.3.9 django-storages==1.12.3 django-watchman==1.3.0 -djangorestframework==3.13.1 +djangorestframework==3.15.2 fiona==1.8.21 future==0.18.2 +gevent==24.11.1 +gunicorn==23.0.0 pycountry==22.3.5 pyuca==1.2 requests==2.27.1 @@ -26,4 +28,4 @@ us==2.0.2 # This been removed from application code but was used in old migrations, so it can't be removed # unless those migrations are refactored to not import it. -django-localflavor==2.2 +django-localflavor==4.0 diff --git a/src/django/users/migrations/0005_update_pfb_analysis_and_user.py b/src/django/users/migrations/0005_update_pfb_analysis_and_user.py new file mode 100644 index 00000000..9aed0224 --- /dev/null +++ b/src/django/users/migrations/0005_update_pfb_analysis_and_user.py @@ -0,0 +1,35 @@ +# Generated by Django 4.2.17 on 2024-12-19 21:54 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_auto_20170509_1559'), + ] + + operations = [ + migrations.AlterField( + model_name='organization', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='organization', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='pfbuser', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='pfbuser', + name='modified_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='%(app_label)s_%(class)s_related+', to=settings.AUTH_USER_MODEL), + ), + ]