-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dockerfile | ||
docker-compose.yml | ||
venv/ | ||
VENV/ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
__pycache__ | ||
.env | ||
interna/media/ | ||
venv/ | ||
VENV/ | ||
.mypy_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Docker image for Interna. | ||
# | ||
# Please set the following env vars: | ||
# | ||
# - SECRET_KEY=... | ||
# - DATABASE_URL='postgres://<postgres-host>/<database-name>' | ||
# - SITE_DOMAIN='https://<domain>[:<port>]' | ||
# - ALLOWED_HOST='<domain>' | ||
# - SMTP_HOST=... | ||
# - SMTP_PORT=... | ||
# - SMTP_USER=... | ||
# - SMTP_PASS=... | ||
# | ||
# See docker-compose.yml as an example on how to run this image. | ||
|
||
FROM docker.io/python:3.9-slim-bullseye | ||
|
||
# Add requirements file | ||
ADD requirements.txt /code/requirements.txt | ||
WORKDIR /code | ||
|
||
# Install dependencies | ||
RUN apt-get update -qq \ | ||
&& apt-get install -yq --no-install-recommends \ | ||
dumb-init \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
RUN pip install -r requirements.txt | ||
|
||
# Add code | ||
ADD . /code | ||
|
||
# Set env vars | ||
ENV DJANGO_DEBUG=False | ||
|
||
# Collect static files | ||
RUN SECRET_KEY=tmp interna/manage.py collectstatic | ||
|
||
# Entry point | ||
ENTRYPOINT ["/usr/bin/dumb-init", "--"] | ||
CMD ["/bin/bash", "entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Note: This config is not currently set up for development, | ||
# it's meant mostly as an example for a productive deployment. | ||
# | ||
# This setup currently does not serve static files. In order to serve static | ||
# files, mount the /code/interna/static directory to a directory on the host | ||
# and configure your web server to serve these files on /static/. | ||
|
||
version: "3.9" | ||
|
||
volumes: | ||
interna-data: | ||
|
||
services: | ||
db: | ||
image: docker.io/postgres:14-alpine | ||
volumes: | ||
- interna-data:/var/lib/postgresql/data | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U interna"] | ||
interval: 30s | ||
timeout: 30s | ||
retries: 3 | ||
environment: | ||
- POSTGRES_DB=interna | ||
- POSTGRES_USER=interna | ||
- POSTGRES_PASSWORD=TODO-CHANGEME | ||
web: | ||
build: . | ||
ports: | ||
- "8000:8000" | ||
environment: | ||
SECRET_KEY: TODO-CHANGEME | ||
DATABASE_URL: postgres://interna:TODO-CHANGEME@db/interna | ||
SITE_DOMAIN: http://localhost:8000 | ||
ALLOWED_HOST: localhost | ||
SMTP_HOST: TODO-CHANGEME | ||
SMTP_PORT: 1234 | ||
SMTP_USER: TODO-CHANGEME | ||
SMTP_PASS: TODO-CHANGEME | ||
depends_on: | ||
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Entry point script for Docker | ||
set -euo pipefail | ||
|
||
if [ -z "${SECRET_KEY:-}" ]; then | ||
echo 'Error: Missing SECRET_KEY env variable.' | ||
echo 'You can generate a secret key with `openssl rand -hex 32`.' | ||
exit 1 | ||
fi | ||
if [ -z "${DATABASE_URL:-}" ]; then | ||
echo 'Error: Missing DATABASE_URL env variable.' | ||
exit 1 | ||
fi | ||
if [ -z "${SITE_DOMAIN:-}" ]; then | ||
echo 'Error: Missing SITE_DOMAIN env variable.' | ||
exit 1 | ||
fi | ||
if [ -z "${SMTP_HOST:-}" ] || [ -z "${SMTP_USER:-}" ] || [ -z "${SMTP_PASS:-}" ] || [ -z "${SMTP_PORT:-}" ]; then | ||
echo 'Error: Missing SMTP_* env variables.' | ||
exit 1 | ||
fi | ||
|
||
cd interna | ||
|
||
# We need to wait for the database to be ready until we can run migrations. | ||
# To do this, retry up to 15 times to run the migrations. Once that worked, | ||
# we can assume that the database is up and ready. | ||
success=0 | ||
retries=15 | ||
for i in $(seq $retries); do | ||
echo "Running migrations…" | ||
./manage.py migrate && success=1 && break || true | ||
echo "Database not yet ready, waiting ($i/$retries)…" | ||
sleep 1 | ||
done | ||
if [ "$success" -eq 1 ]; then | ||
echo "Database is up, all migrations applied" | ||
else | ||
echo "Timed out waiting for database" | ||
exit 1 | ||
fi | ||
|
||
echo "Create cache table…" | ||
./manage.py createcachetable | ||
|
||
echo "Start server…" | ||
gunicorn config.wsgi:application -n interna -b 0.0.0.0:8000 -w 4 --log-level warning |