From 5b6f4e16ef143e21eb394425a7f7e2ec227b331e Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 10 Dec 2023 23:09:33 +0100 Subject: [PATCH 1/3] tinkered around to get this app running inside a container using alpine and socket based psql --- .dockerignore | 1 + Dockerfile | 6 ++++++ entrypoint.sh | 6 ++++++ requirements.txt | 3 ++- .../shimatta_kenkyusho/settings_production.py | 1 + start_server.sh | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 entrypoint.sh create mode 100755 start_server.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9bdbf6d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +start_server.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9ba421 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:latest +RUN apk add --no-cache python3 py3-pip python3-dev py3-setuptools gcc python3-dev jpeg-dev zlib-dev musl-dev py3-gunicorn +COPY . /home/shimatta/kenkyusho +WORKDIR /home/shimatta/kenkyusho +RUN python3 -m venv /home/shimatta/kenkyusho/.venv && . /home/shimatta/kenkyusho/.venv/bin/activate && pip install -r requirements.txt +ENTRYPOINT ["/home/shimatta/kenkyusho/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..b9c8dfb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh +source /home/shimatta/kenkyusho/.venv/bin/activate +cd /home/shimatta/kenkyusho/shimatta_kenkyusho +python manage.py migrate --settings shimatta_kenkyusho.settings_production +python manage.py collectstatic --settings shimatta_kenkyusho.settings_production +gunicorn -w 4 shimatta_kenkyusho.wsgi:application diff --git a/requirements.txt b/requirements.txt index 2916f34..4a6a537 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,6 @@ lazy-object-proxy==1.6.0 MarkupSafe==2.0.1 mccabe==0.6.1 Pillow==8.3.1 -psycopg2==2.9.1 pylint==2.9.6 pytz==2021.1 qrcode==7.2 @@ -23,3 +22,5 @@ six==1.16.0 sqlparse==0.4.1 toml==0.10.2 wrapt==1.12.1 +psycopg2-binary==2.9.9 +gunicorn==21.2.0 diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py index 43c9681..cb15634 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py @@ -138,6 +138,7 @@ DATABASES = { 'USER': db_user, 'PASSWORD': db_pw, 'HOST': get_env_value('DJANGO_POSTGRESQL_SOCKET'), + 'PORT': get_env_value('DJANGO_POSTGRESQL_PORT'), } } diff --git a/start_server.sh b/start_server.sh new file mode 100755 index 0000000..41be14e --- /dev/null +++ b/start_server.sh @@ -0,0 +1 @@ +podman run -it -e DJANGO_SECRET_KEY= -e DJANGO_ALLOWED_HOST=parts.shimatta.net -e DJANGO_STATIC_ROOT=/var/static -e DJANGO_MEDIA_URL=media -e DJANGO_MEDIA_ROOT=/var/media -e DJANGO_POSTGRESQL_SOCKET=host.docker.internal -e DJANGO_POSTGRESQL_PORT=2345 -e DJANGO_POSTGRESQL_USER= -e DJANGO_POSTGRESQL_PW= -v /var/parts/static:/var/static -v /var/parts/media:/var/media -p 8000:8000 --entrypoint /bin/sh localhost/kenkyusho:0.1 -- 2.47.0 From 7a1bf054f51f2dc936af6c042ab8b7821445aa28 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 11 Dec 2023 00:23:36 +0100 Subject: [PATCH 2/3] disabling django ssl redirection in order to run this in docker (without ssl obviously) --- shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py index cb15634..901bdc1 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py @@ -230,6 +230,6 @@ CRISPY_TEMPLATE_PACK = "bootstrap5" SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True -SECURE_SSL_REDIRECT = True +SECURE_SSL_REDIRECT = False SECURE_HSTS_SECONDS = get_env_value('DJANGO_SECURE_HSTS_SECONDS', default=120) \ No newline at end of file -- 2.47.0 From 7e0fc86b7f08d389c3fc6d047d86341d4118bd49 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 11 Dec 2023 00:34:43 +0100 Subject: [PATCH 3/3] running migration without interaction in entrypoint script --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b9c8dfb..42b543c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,5 +2,5 @@ source /home/shimatta/kenkyusho/.venv/bin/activate cd /home/shimatta/kenkyusho/shimatta_kenkyusho python manage.py migrate --settings shimatta_kenkyusho.settings_production -python manage.py collectstatic --settings shimatta_kenkyusho.settings_production +python manage.py collectstatic --settings shimatta_kenkyusho.settings_production --noinput gunicorn -w 4 shimatta_kenkyusho.wsgi:application -- 2.47.0