aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-03-25 20:04:43 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-03-25 20:04:43 +0100
commitb4fb50ebf2127aff85d30871fd4b13af1edd52c7 (patch)
tree0232df9ff22f3deaf6319c4a746fb3821c2f29bb
parent897d53087a4c3c3338738cf6c297d4a551216e01 (diff)
downloadfietsboek-b4fb50ebf2127aff85d30871fd4b13af1edd52c7.tar.gz
fietsboek-b4fb50ebf2127aff85d30871fd4b13af1edd52c7.tar.bz2
fietsboek-b4fb50ebf2127aff85d30871fd4b13af1edd52c7.zip
add an initial Dockerfile
-rw-r--r--Dockerfile17
-rw-r--r--container/entrypoint56
-rw-r--r--container/gunicorn.conf.py1
3 files changed, 74 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..22e0717
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,17 @@
+FROM python:3.11
+RUN pip install gunicorn
+
+RUN mkdir /package
+WORKDIR /package/
+COPY ["fietsboek", "fietsboek"]
+COPY ["pyproject.toml", "README.md", "LICENSE.txt", "CHANGELOG.rst", "production.ini", "."]
+RUN pip install .
+
+COPY --chmod=755 ["container/entrypoint", "/bin/entrypoint"]
+COPY ["container/gunicorn.conf.py", "/fietsboek/gunicorn.conf.py"]
+
+VOLUME /fietsboek/data /fietsboek/database /fietsboek/pages
+WORKDIR /fietsboek
+
+ENTRYPOINT ["/bin/entrypoint"]
+CMD ["gunicorn", "--paste", "/fietsboek/fietsboek.ini"]
diff --git a/container/entrypoint b/container/entrypoint
new file mode 100644
index 0000000..0d404d6
--- /dev/null
+++ b/container/entrypoint
@@ -0,0 +1,56 @@
+#!/bin/bash
+set -euo pipefail
+
+error() {
+ >&2 echo "[ERROR] $1"
+}
+
+CONFIG="/fietsboek/fietsboek.ini"
+if [[ ! -f "$CONFIG" ]] ; then
+ # Copy the default config over
+ cp /package/production.ini "$CONFIG"
+ # Change default settings
+ : ${SQLALCHEMY_URL:=sqlite:////fietsboek/database/fietsboek.sqlite}
+ sed -i '/^sqlalchemy\.url = /c sqlalchemy.url = '"$SQLALCHEMY_URL" "$CONFIG"
+
+ if [[ ! -v REDIS_URL ]] ; then
+ error "need REDIS_URL set"
+ exit 1
+ fi
+ sed -i '/^\[app:main\]/a redis.url = '"$REDIS_URL" "$CONFIG"
+
+ : ${DATA_DIR:=/fietsboek/data}
+ mkdir -p "$DATA_DIR"
+ sed -i '/^\[app:main\]/a fietsboek.data_dir = '"$DATA_DIR" "$CONFIG"
+
+ : ${SESSION_KEY:=$(openssl rand -hex 20)}
+ sed -i '/^session_key = /c session_key = '"$SESSION_KEY" "$CONFIG"
+
+ sed -i '/^\[app:main\]/a fietsboek.pages = /fietsboek/pages' "$CONFIG"
+
+ : ${ENABLE_ACCOUNT_REGISTRATION:=true}
+ sed -i '/^enable_account_registration =/c enable_account_registration = '"$ENABLE_ACCOUNT_REGISTRATION" "$CONFIG"
+
+ if [[ -v DEFAULT_LOCALE_NAME ]] ; then
+ sed -i '/^pyramid\.default_locale_name =/c pyramid.default_locale_name = '"$DEFAULT_LOCALE_NAME" "$CONFIG"
+ fi
+
+ if [[ -v EMAIL_FROM ]] ; then
+ sed -i '/^email\.from =/c email.from = '"$EMAIL_FROM" "$CONFIG"
+ fi
+ if [[ -v EMAIL_SMTP_URL ]] ; then
+ sed -i '/^email\.smtp_url =/c email.smtp_url = '"$EMAIL_SMTP_URL" "$CONFIG"
+ fi
+ if [[ -v EMAIL_USERNAME ]] ; then
+ sed -i '/^email\.username =/c email.username = '"$EMAIL_USERNAME" "$CONFIG"
+ fi
+ if [[ -v EMAIL_PASSWORD ]] ; then
+ sed -i '/^email\.password =/c email.password = '"$EMAIL_PASSWORD" "$CONFIG"
+ fi
+fi
+
+# Make sure the data schema is up to date, or rather initialize it if this is
+# the first time
+(cd /package && fietsupdate update -fc "$CONFIG")
+
+exec "$@"
diff --git a/container/gunicorn.conf.py b/container/gunicorn.conf.py
new file mode 100644
index 0000000..dc574f2
--- /dev/null
+++ b/container/gunicorn.conf.py
@@ -0,0 +1 @@
+bind = "0.0.0.0:8000"