Add basic docker support

This commit is contained in:
Michael Manfre 2022-11-08 23:05:51 -05:00 committed by GitHub
parent 54e1b1f93a
commit 8a0a755889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 3 deletions

5
.dockerignore Normal file
View file

@ -0,0 +1,5 @@
*.psql
*.sqlite3
notes.md
.venv
.pre-commit-config.yaml

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.psql
*.sqlite3
.venv
notes.md

26
Dockerfile Normal file
View file

@ -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"]

42
docker-compose.yml Normal file
View file

@ -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:

View file

@ -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

7
scripts/start.sh Normal file
View file

@ -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

View file

@ -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"),
}
}