diff options
-rw-r--r-- | Dockerfile | 44 | ||||
-rw-r--r-- | Dockerfile_postgresql | 6 | ||||
-rw-r--r-- | Makefile | 22 | ||||
-rw-r--r-- | conf/settings/base.py (renamed from ded/settings.py) | 0 | ||||
-rw-r--r-- | conf/settings/local.py | 12 | ||||
-rwxr-xr-x | manage.py | 1 | ||||
-rw-r--r-- | requirements.txt | 1 |
7 files changed, 49 insertions, 37 deletions
@@ -1,45 +1,23 @@ -# Builder stage -FROM registry.access.redhat.com/ubi9/python-311:1-52.1712567218 AS builder - -# Add application sources -USER 0 -COPY . /app -RUN mkdir -p /app/static/css /app/static/js /app/static/img -RUN chown -R 1001:0 /app -USER 1001 - -WORKDIR /app - -# Install dependencies -RUN pip install -U "pip>=24.0.0" && \ - pip install -r requirements.txt && \ - python manage.py collectstatic --noinput - -# Final stage FROM python:3.11-slim # Set working directory WORKDIR /app -# Copy from builder -COPY --from=builder /app /app - -# Install packages -RUN pip install -r requirements.txt +# Copy application code +COPY . /app -# Copy across db file and set permissions -COPY db.sqlite3 /app/db.sqlite3 -RUN chown 1001:0 /app && \ - chmod 664 /app/db.sqlite3 +# Install system dependencies +RUN apt-get update && apt-get install -y \ + libpq-dev \ + gcc \ + && rm -rf /var/lib/apt/lists/* -# Set user -USER 1001 +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt -# Migrate database -RUN python manage.py migrate +ENV DJANGO_SETTINGS_MODULE=conf.settings.local -# Expose port EXPOSE 8000 -# Start app +# Start gunicorn CMD ["gunicorn", "ded.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/Dockerfile_postgresql b/Dockerfile_postgresql new file mode 100644 index 0000000..9111660 --- /dev/null +++ b/Dockerfile_postgresql @@ -0,0 +1,6 @@ +FROM registry.redhat.io/rhel9/postgresql-16 + +ENV POSTGRESQL_USER=postgres \ + POSTGRESQL_PASSWORD=postgres + +CMD ["/usr/bin/run-postgresql"] @@ -1,12 +1,26 @@ +all: stop create-network build-postgres run-postgres build-django run-django + +CONFIG := conf.settings.local + runserver: python manage.py runserver 0.0.0.0:8000 -runserver-docker: - docker run -it --name ded -d --rm -p 8000:8000 ded:latest +create-network: + -docker network create dednetwork +stop: + -docker stop ded-web postgres runserver-docker-with-vol: docker run -it --name ded -d --rm -p 8000:8000 -v $(PWD):/app ded:latest sync: git pull && git checkout main && git pull && git merge pyswitch && git checkout pyswitch && git rebase main && git push -build: - docker build -t ded:latest . +build-django: + docker build -f Dockerfile -t ded-web:latest . +build-postgres: + docker build -t dso-quay-registry-quay-quay-enterprise.apps.ocp1.azure.dso.digital.mod.uk/defnucsyr-dev-team-a/postgresql:v1.0.0 . -f Dockerfile_postgresql +run-postgres: + docker run -it --name postgres -d --rm -e POSTGRESQL_PASSWORD=ded -e POSTGRESQL_USER=ded -e POSTGRESQL_DATABASE=ded -p 5432:5432 --network dednetwork dso-quay-registry-quay-quay-enterprise.apps.ocp1.azure.dso.digital.mod.uk/defnucsyr-dev-team-a/postgresql:v1.0.0 +run-django: + docker run -d -it --name ded-web -e DJANGO_SETTINGS_MODULE=$(CONFIG) -p 8000:8000 --network dednetwork --rm ded-web:latest test: python manage.py test +migrate-and-superuser: + docker exec -it ded-web sh -c "python manage.py migrate && python manage.py createsuperuser" diff --git a/ded/settings.py b/conf/settings/base.py index a16c488..a16c488 100644 --- a/ded/settings.py +++ b/conf/settings/base.py diff --git a/conf/settings/local.py b/conf/settings/local.py new file mode 100644 index 0000000..0992726 --- /dev/null +++ b/conf/settings/local.py @@ -0,0 +1,12 @@ +from .base import * + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": "ded", + "USER": "ded", + "PASSWORD": "ded", + "HOST": "postgres", + "PORT": 5432, + } +} @@ -1,5 +1,6 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys diff --git a/requirements.txt b/requirements.txt index f3dae6d..9d62c5a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ django-crispy-forms #faker>=13.14.0,<14.0.0 django-htmx==1.17.3 gunicorn==22.0.0 +psycopg2==2.9.9 |