From aa1e3a65ae43ccca6f1211ea659043ba586da655 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sun, 3 Dec 2023 12:50:23 +0100 Subject: [PATCH] Customize Pretix for our use --- .gitlab-ci.yml | 13 +++++++++++++ Dockerfile | 13 +++++++++++++ README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 entrypoint.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..8cd427e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,13 @@ +build-image: + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - mkdir -p /kaniko/.docker + - echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json + - >- + /kaniko/executor + --context "${CI_PROJECT_DIR}" + --dockerfile "${CI_PROJECT_DIR}/Dockerfile" + --destination "${IMAGE}" + --destination "${CI_REGISTRY_IMAGE}/ccchh-pretix:23.10.0" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..af3f69d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM docker.io/pretix/standalone:2023.10.0 + +USER root +COPY entrypoint.sh / +RUN true \ + && chmod +x /entrypoint.sh \ + && touch /etc/pretix/pretix.cfg \ + && chown pretixuser /etc/pretix/pretix.cfg \ + && true + +USER pretixuser + +ENTRYPOINT /entrypoint.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..edf1bfd --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Pretix Customized for CCCHH + +The image adds an entrypoint script that creates `/etc/pretix/pretix.cfg` from environment variables at startup. The file is only created if it doesn't exist or is empty; this means that you can still mount your own config file into the container as with the original image. + +The script will fail and point out if required variables are not set. + +## Configuration + +The config file is created from a template, with environment variables substituted. + +```ini +[pretix] +instance_name=${PRETIX_INSTANCE_NAME} +url=${PRETIX_URL} +currency=${PRETIX_CURRENCY:-EUR} +datadir=${PRETIX_DATADIR:-/data} +trust_x_forwarded_for=${PRETIX_TRUST_X_FORWARDED_FOR:-on} +trust_x_forwarded_proto=${PRETIX_TRUST_X_FORWARDED_PROTO:-on} + +[database] +backend=${DATABASE_BACKEND} +name=${DATABASE_NAME} +user=${DATABASE_USER} +password=${DATABASE_PASSWORD} +host=${DATABASE_HOST} + +[mail] +from=${MAIL_FROM} +host=${MAIL_HOST} + +[redis] +location=${REDIS_LOCATION} +sessions=${REDIS_SESSION:-true} + +[celery] +backend=${CELERY_BACKEND} +broker=${CELERY_BROKER} +EOF +``` + +## Updating the image + +You will need to look up the latest tag at https://hub.docker.com/r/pretix/standalone/tags and change it in both the `Dockerfile`` and in ``.gitlab-ci.yml`. + +## Testing the build + +```shell +docker build -t ccchh-pretix:latest . +``` + +```shell +docker run -it --rm --name pretix -e PRETIX_INSTANCE_NAME=foo -e PRETIX_URL=http://localhost -e DATABASE_BACKEND=postgresql -e DATABASE_NAME=postgres -e DATABASE_USER=postgres -e DATABASE_PASSWORD=geheim -e DATABASE_HOST=postgres -e MAIL_FROM=foo@example.com -e MAIL_HOST=mail -e REDIS_LOCATION=redis://redis/0 -e CELERY_BACKEND=redis://redis/0 -e CELERY_BROKER=redis://redis/1 ccchh-pretix``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..4c60ca7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +set -e + +if [ ! -s /etc/pretix/pretix.cfg ]; then + echo "Creating /etc/pretix/pretix.cfg from environment" >&2 + missing="" + for i in PRETIX_INSTANCE_NAME PRETIX_URL DATABASE_BACKEND DATABASE_NAME DATABASE_USER DATABASE_PASSWORD DATABASE_HOST MAIL_FROM MAIL_HOST REDIS_LOCATION CELERY_BACKEND CELERY_BROKER; do + if eval "[ -z \"\${$i}\" ]"; then + missing="${missing} $i" + fi + done + if [ -n "${missing}" ]; then + echo "You need to set these environment variables to configure Pretix:$missing" >&2 + exit 1 + fi + cat >/etc/pretix/pretix.cfg <