summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.dockerignore5
-rw-r--r--.gitignore1
-rw-r--r--Dockerfile26
-rw-r--r--docker-compose.yml42
-rw-r--r--requirements.txt3
-rw-r--r--scripts/start.sh7
-rw-r--r--takahe/settings.py9
7 files changed, 90 insertions, 3 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..dac9df9
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,5 @@
+*.psql
+*.sqlite3
+notes.md
+.venv
+.pre-commit-config.yaml
diff --git a/.gitignore b/.gitignore
index d6bf26a..3853bb5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.psql
*.sqlite3
+.venv
notes.md
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..1f62240
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,26 @@
+FROM python:3.9-bullseye as builder
+
+RUN mkdir -p /takahe
+RUN python -m venv /takahe/.venv
+RUN apt-get update && apt-get -y install libpq-dev python3-dev
+
+WORKDIR /takahe
+
+COPY requirements.txt requirements.txt
+
+RUN . /takahe/.venv/bin/activate \
+ && pip install --upgrade pip \
+ && pip install --upgrade -r requirements.txt
+
+
+FROM python:3.9-slim-bullseye
+
+RUN apt-get update && apt-get install -y libpq5
+
+COPY --from=builder /takahe /takahe
+COPY . /takahe
+
+WORKDIR /takahe
+EXPOSE 8000
+
+CMD ["/takahe/scripts/start.sh"]
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..f64bfb6
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,42 @@
+version: "3"
+
+services:
+ db:
+ image: postgres:15-alpine
+ healthcheck:
+ test: ['CMD', 'pg_isready', '-U', 'postgres']
+ volumes:
+ - dbdata:/var/lib/postgresql/data
+ networks:
+ - internal_network
+ restart: always
+ environment:
+ - "POSTGRES_DB=tahake"
+ - "POSTGRES_USER=postgres"
+ - "POSTGRES_PASSWORD=insecure_password"
+
+ web:
+ build: .
+ image: tahake:latest
+ environment:
+ - "DJANGO_SETTINGS_MODULE=takahe.settings"
+ - "SECRET_KEY=insecure_secret"
+ - "POSTGRES_HOST=db"
+ - "POSTGRES_DB=tahake"
+ - "POSTGRES_USER=postgres"
+ - "POSTGRES_PASSWORD=insecure_password"
+ networks:
+ - external_network
+ - internal_network
+ restart: always
+ depends_on:
+ - db
+ ports:
+ - "8000:8000"
+
+networks:
+ internal_network:
+ external_network:
+
+volumes:
+ dbdata:
diff --git a/requirements.txt b/requirements.txt
index 09de1e6..53ab2b0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,3 +6,6 @@ django-crispy-forms~=1.14
cryptography~=38.0
httpx~=0.23
pyOpenSSL~=22.1.0
+uvicorn~=0.19
+gunicorn~=20.1.0
+psycopg2==2.9.5
diff --git a/scripts/start.sh b/scripts/start.sh
new file mode 100644
index 0000000..99f1ed0
--- /dev/null
+++ b/scripts/start.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. /takahe/.venv/bin/activate
+
+python manage.py migrate
+
+exec gunicorn takahe.asgi:application -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
diff --git a/takahe/settings.py b/takahe/settings.py
index fea5244..62065d2 100644
--- a/takahe/settings.py
+++ b/takahe/settings.py
@@ -1,10 +1,11 @@
+import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = "insecure_secret"
+SECRET_KEY = os.environ.get("SECRET_KEY", "insecure_secret")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@@ -64,8 +65,10 @@ WSGI_APPLICATION = "takahe.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
- "NAME": "takahe",
- "USER": "postgres",
+ "HOST": os.environ.get("POSTGRES_HOST", "localhost"),
+ "NAME": os.environ.get("POSTGRES_DB", "takahe"),
+ "USER": os.environ.get("POSTGRES_USER", "postgres"),
+ "PASSWORD": os.environ.get("POSTGRES_PASSWORD"),
}
}