aboutsummaryrefslogtreecommitdiff
path: root/container
diff options
context:
space:
mode:
Diffstat (limited to 'container')
-rw-r--r--container/entrypoint62
-rw-r--r--container/gunicorn.conf.py1
2 files changed, 63 insertions, 0 deletions
diff --git a/container/entrypoint b/container/entrypoint
new file mode 100644
index 0000000..c7f3b2d
--- /dev/null
+++ b/container/entrypoint
@@ -0,0 +1,62 @@
+#!/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
+
+ if [[ -v LOGLEVEL ]] ; then
+ # We are only changing the fietsboek log level here, as SQLAlchemy
+ # produces a lot of noise.
+ sed -i '/\[logger_fietsboek\]/{N;s/level = .*/level = '"$LOGLEVEL"'/}' "$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"