Add compose setup

* Use a dedicated postgresql container as database
* Controlled via .env file
* Ecample script for interactive container startup
This commit is contained in:
Mario Hüttel 2024-11-17 16:37:23 +01:00
parent 64d0a1bfb3
commit d2ce635f05
4 changed files with 75 additions and 0 deletions

29
.env.example Normal file
View File

@ -0,0 +1,29 @@
####################################################################################################
# Example configuration. Must be edited and copied to ".env" next to the compose.yaml
####################################################################################################
# Path to to mount as the directory for static data. Must be served by a webserver on the /static path
DJANGO_STATIC_VOL=/path/to/static/root
# Path to the media root. Must be served by a webserver on the media URL
DJANGO_MEDIA_VOL=/path/to/media/root
# Port to serve the App
PORT=8000
# Secret Key. Must be edited before deployment
DJANGO_SECRET_KEY=534hj5jgh4365ghj35jgh245jgh24
# Allowed host be be accessed. Currently it is only possible to specify a single URL
DJANGO_ALLOWED_HOST=lab.example.com
# Media URL for images and other content
DJANGO_MEDIA_URL=media.lab.example.com/
# DO NOT SET DEBUG MODE IN PRODUCTION
# DJANGO_FORCE_DEV_MODE=True
# Set this password if you want to use a custom postgres password. The db should be condifed inside the docker network.
# Using the standard PW is therefore not a problem
# DJANGO_POSTGRESQL_PW=myfancynewpassword123donotsharemewithanyone

3
.gitignore vendored
View File

@ -125,3 +125,6 @@ dmypy.json
myenv/*
run/*
.env

36
compose.yaml Normal file
View File

@ -0,0 +1,36 @@
services:
shimatta-kenkyusho-web:
build: .
volumes:
- "${DJANGO_STATIC_VOL:-./run/static}:/var/static"
- "${DJANGO_MEDIA_VOL:-./run/media}:/var/media"
environment:
DJANGO_POSTGRESQL_PW: "${DJANGO_POSTGRESQL_PW:-p4ssw0rd}"
DJANGO_POSTGRESQL_USER: "postgres"
DJANGO_SECRET_KEY: "${DJANGO_SECRET_KEY}"
DJANGO_ALLOWED_HOST: "${DJANGO_ALLOWED_HOST}"
DJANGO_STATIC_ROOT: "/var/static"
DJANGO_MEDIA_URL: "${DJANGO_MEDIA_URL}"
DJANGO_MEDIA_ROOT: "/var/media"
DJANGO_POSTGRESQL_SOCKET: "shimatta-kenkyusho-db"
DJANGO_POSTGRESQL_PORT: "5432"
DJANGO_FORCE_DEV_MODE: ${DJANGO_FORCE_DEV_MODE:-False}
ports:
- "${PORT}:8000"
networks:
- backendnet
depends_on:
- "shimatta-kenkyusho-db"
shimatta-kenkyusho-db:
image: postgres:16.5-alpine
environment:
POSTGRES_PASSWORD: "${DJANGO_POSTGRESQL_PW:-p4ssw0rd}"
POSTGRES_DB: "shimatta_kenkyusho"
volumes:
- "${PGDATA:-./run/pgdata}:/var/lib/postgresql/data"
networks:
- backendnet
networks:
backendnet:

View File

@ -0,0 +1,7 @@
#!/bin/bash
# Startup the db container
docker-compose start shimatta-kenkyusho-db
# Override entrypoint to get interactive shell
docker-compose run --entrypoint="/bin/sh" -p 8000:8000 shimatta-kenkyusho-web