From ac941a1c0c24af34bc227a7659b6afa8b1542220 Mon Sep 17 00:00:00 2001 From: Cassowary Rusnov Date: Mon, 10 Jul 2023 11:37:23 -0700 Subject: [PATCH] Initial checkin (mostly works) --- .env.sample | 21 ++++++++ README.md | 6 +-- abra.sh | 2 + compose.yml | 89 +++++++++++++++++++++++++++++++-- coopcloud-entrypoint.sh | 107 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 7 deletions(-) create mode 100644 abra.sh create mode 100755 coopcloud-entrypoint.sh diff --git a/.env.sample b/.env.sample index f960600..188a88a 100644 --- a/.env.sample +++ b/.env.sample @@ -6,3 +6,24 @@ DOMAIN=phpbb.example.com #EXTRA_DOMAINS=', `www.phpbb.example.com`' LETS_ENCRYPT_ENV=production + +PHPBB_USERNAME=admin +PHPBB_EMAIL=forum@example.com +PHPBB_FORUM_NAME=My Forum +PHPBB_FORUM_DESCRIPTION=A very nice forum + +# PHPBB_COOKIE_SECURE=yes + +# Can be enabled after initial startup? +# PHPBB_SKIP_BOOTSTRAP=yes + +# Email setup +# PHPBB_SMTP_HOST= +# PHPBB_SMTP_PORT= +# PHPBB_SMTP_USER= +# Set SMTP password as the 'smtp_password' secret on the 'app' container. + + +SECRET_ADMIN_PASSWORD_VERSION=v1 +SECRET_DB_PASSWORD_VERSION=v1 +SECRET_DB_ROOT_PASSWORD_VERSION=v1 \ No newline at end of file diff --git a/README.md b/README.md index 53f76b2..e3e2d9b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # phpbb -> One line description of the recipe +> The venerable, ancient php forum system, now in coöp cloud! * **Category**: Apps * **Status**: 0 -* **Image**: [`phpbb`](https://hub.docker.com/r/phpbb), 4, upstream +* **Image**: [`phpbb`](https://hub.docker.com/r/bitnami/phpbb/), 4, upstream * **Healthcheck**: No * **Backups**: No * **Email**: No @@ -17,7 +17,7 @@ ## Quick start -* `abra app new phpbb --secrets` +* `abra app new phpbb` * `abra app config ` * `abra app deploy ` diff --git a/abra.sh b/abra.sh new file mode 100644 index 0000000..5c50d6f --- /dev/null +++ b/abra.sh @@ -0,0 +1,2 @@ +export APP_ENTRYPOINT_VERSION=v0 +export DB_ENTRYPOINT_VERSION=v0 diff --git a/compose.yml b/compose.yml index a2c3805..a1a6fbd 100644 --- a/compose.yml +++ b/compose.yml @@ -1,17 +1,41 @@ --- +# Heavily cribbed from https://raw.githubusercontent.com/bitnami/containers/main/bitnami/phpbb/docker-compose.yml version: "3.8" services: app: - image: nginx:1.20.0 + image: bitnami/phpbb:3.3.10 networks: - proxy + - internal + environment: + - COOPCLOUD_ENTRYPOINT=/opt/bitnami/scripts/phpbb/entrypoint.sh + - COOPCLOUD_ENTRYPOINT_ORIGINAL=/opt/bitnami/scripts/phpbb/entrypoint.sh + - COOPCLOUD_LOAD_PHPBB_DATABASE_PASSWORD=/run/secrets/db_password + - COOPCLOUD_LOAD_PHPBB_PASSWORD=/run/secrets/admin_password + # - COOPCLOUD_LOAD_PHPBB_SMTP_PASSWORD=/run/secrets/smtp_password # you need to setup this secret fixme + - PHPBB_DATABASE_HOST=${STACK_NAME}_db + - PHPBB_DATABASE_USER=phpbb + - PHPBB_DATABASE_NAME=phpbb + - PHPBB_HOST=${DOBMAIN} + # User configurations + - PHPBB_USERNAME + - PHPBB_EMAIL + - PHPBB_FORUM_NAME + - PHPBB_FORUM_DESCRIPTION + - PHPBB_COOKIE_SECURE + - PHPBB_SKIP_BOOTSTRAP + - PHPBB_SMTP_HOST + - PHPBB_SMTP_PORT + - PHPBB_SMTP_USER + volumes: + - 'phpbb_data:/bitnami/phpbb' deploy: restart_policy: condition: on-failure labels: - "traefik.enable=true" - - "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=80" + - "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=8080" - "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`${EXTRA_DOMAINS})" - "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure" - "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}" @@ -19,14 +43,71 @@ services: #- "traefik.http.routers.${STACK_NAME}.middlewares=${STACK_NAME}-redirect" #- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLForceHost=true" #- "traefik.http.middlewares.${STACK_NAME}-redirect.headers.SSLHost=${DOMAIN}" - - "coop-cloud.${STACK_NAME}.version=" + - "coop-cloud.${STACK_NAME}.version=0.1.0+3.3.10" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost"] + test: ["CMD", "curl", "-f", "http://localhost:8080"] interval: 30s timeout: 10s retries: 10 start_period: 1m + entrypoint: ["/coopcloud-entrypoint.sh", "/opt/bitnami/scripts/apache/run.sh"] + depends_on: + - db + secrets: + - db_password + - admin_password + configs: + - source: app_entrypoint + target: /coopcloud-entrypoint.sh + mode: 0555 + + db: + image: docker.io/bitnami/mariadb:10.6 + networks: + - internal + environment: + - COOPCLOUD_ENTRYPOINT=/opt/bitnami/scripts/mariadb/entrypoint.sh + - COOPCLOUD_ENTRYPOINT_ORIGINAL=/opt/bitnami/scripts/mariadb/entrypoint.sh + - MARIADB_USER=phpbb + - MARIADB_DATABASE=phpbb + - COOPCLOUD_LOAD_MARIADB_ROOT_PASSWORD=/run/secrets/db_root_password + - COOPCLOUD_LOAD_MARIADB_PASSWORD=/run/secrets/db_password + entrypoint: ["/coopcloud-entrypoint.sh", "/opt/bitnami/scripts/mariadb/run.sh"] + configs: + - source: db_entrypoint + target: /coopcloud-entrypoint.sh + mode: 0555 + secrets: + - db_password + - db_root_password + volumes: + - 'mariadb_data:/bitnami/mariadb' + +secrets: + db_password: + name: ${STACK_NAME}_db_password_${SECRET_DB_PASSWORD_VERSION} + external: true + admin_password: + name: ${STACK_NAME}_admin_password_${SECRET_ADMIN_PASSWORD_VERSION} + external: true + db_root_password: + name: ${STACK_NAME}_db_root_password_${SECRET_DB_ROOT_PASSWORD_VERSION} + external: true + + +configs: + app_entrypoint: + name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION} + file: coopcloud-entrypoint.sh + db_entrypoint: + name: ${STACK_NAME}_db_entrypoint_${DB_ENTRYPOINT_VERSION} + file: coopcloud-entrypoint.sh + +volumes: + mariadb_data: + phpbb_data: networks: proxy: external: true + internal: diff --git a/coopcloud-entrypoint.sh b/coopcloud-entrypoint.sh new file mode 100755 index 0000000..1d63f1b --- /dev/null +++ b/coopcloud-entrypoint.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# Configurations etc. +COOPCLOUD_MAX_LOAD_SIZE=1024 +export COOPCLOUD_ENTRYPOINT_VERSION=0.1.0 + +# Functions +logn () { + echo -n "[COOP]["$(date +%FT%T%Z)"]" "$@" +} + +log () { + logn "$@" + echo " " +} + +DOCS=$(cat <<-__DOCS__ + +EOF +Loading files into environment: + Max size is 1 kbyte, files larger than that will not be loaded. + + Environment variables in the format COOPCLOUD_LOAD_=; the contents of + are loaded into + +Startup Scripts: + Extra scripts included with the + +Entrypoint: + The default entrypoint is communicated from the parent environment with COOPCLOUD_ENTRYPOINT; we expect + COOPCLOUD_ENTRYPOINT_ORIGINAL to be set also. If COOPCLOUD_ENTRYPOINT is being overriden for this execution, + this provides a fall-back and also can communicate to the child environment that the entrypoint has been + overriden. + +__DOCS__ + ) + +cat <<-__TURT__ + .-=++++==-: + .=+***+*******+=. + =****++%+:+*******- + =#****:-+-.********+: + . .*****+.. .:*******+=. + =*-: .:****++=--=+*******= + =+*==+++-=#***++++++*******+=- + .+*++****==*****+++++++=++=++: + .-++++++-. :++******+=++**********++*+. + =**********: -=-+++******-+++++******++: + =#**++++****+ -===:=+++***-+%%#*+++++==+*++-. +.++*****-=****..====:*======**+*#%%%%%%#=******+= + =++***#--#**+::-==-+@=**#*+%%#**++*+**+-*******= + .=+++==-****=:-:==#@++%%%#+%##%%#%*=##*.:-----: + .-===+*****=:-:-%#+*%#%%*=#%%%##%=#%%- + -++++****+:-:=+=++##*+*#++**#%=+%%= + :=+++***=.=*****-=##%%%#**+-=*+-: + :-==+-+*******-*#####%%++*+=+#= + =********=-+++++=--==+***#- + .********+:.:::...-++******- + -********= :=+++***=- + .-**+**+: :===-:. + :. .=. + [HACK THE PLANET] +__TURT__ + +# echo that we're running the show +log "#### Coop Cloud Entrypoint $COOPCLOUD_ENTRYPOINT_VERSION ###" + +# load specified files into environment variables +while read ENVIRON_VAR; do + file=${!ENVIRON_VAR} + logn "Loading $ENVIRON_VAR ($file)" + if test -e "$file"; then + # file exists! + fsize=$(wc -c < "$file") + if [ $fsize -lt $COOPCLOUD_MAX_LOAD_SIZE ]; then + target=$(echo $ENVIRON_VAR | cut -d_ -f3-) + val="$(cat $file)" + eval export $target=\"$val\" + echo " -> $target." + else + echo " File too big ($fsize bytes > $COOPCLOUD_MAX_LOAD_SIZE)." + fi + else + echo " File Not Found." + fi +done < <(printenv |grep ^COOPCLOUD_LOAD_ | cut -d= -f1) +### fixme we should support some sort of startup script / 1st time script thing here + +# warn about overridden entrypoint +if [ "$COOPCLOUD_ENTRYPOINT" != "$COOPCLOUD_ENTRYPOINT_ORIGINAL" ]; then + log "#### Warning: Entrypoint apparently overriden to $COOPCLOUD_ENTRYPOINT ####" +fi + +# call the specified entrypoint (if possible) +if [ ! -x "$COOPCLOUD_ENTRYPOINT" ]; then + log "$COOPCLOUD_ENTRYPOINT cannot be executed." + if [ -x "$COOPCLOUD_ENTRYPOINT_ORIGINAL" ]; then + log "Launching original entrypoint ..." + echo "" + exec $COOPCLOUD_ENTRYPOINT_ORIGINAL + else + log "$COOPCLOUD_ENTRYPOINT_ORIGINAL cannot be executed. Giving up." + exit -1 + fi +fi +log "Launching entrypoint ..." +exec $COOPCLOUD_ENTRYPOINT "$@"