forked from coop-cloud/listmonk
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37f41adc1a | ||
|
|
f94b8cbe9f
|
||
|
|
ade1d1191d
|
||
|
|
78cb8281c4
|
||
|
|
c51126fce2
|
||
|
|
cee9b4986f | ||
|
|
9049f72956 | ||
|
|
63d122855f | ||
|
|
52ca435ce5 | ||
|
|
7f343a96c4 | ||
|
|
cfce5e6f79 |
@@ -3,4 +3,12 @@ TYPE=listmonk
|
||||
DOMAIN=listmonk.example.com
|
||||
LETS_ENCRYPT_ENV=production
|
||||
|
||||
COMPOSE_FILE="compose.yml"
|
||||
|
||||
SECRET_DB_PASSWORD_VERSION=v1
|
||||
|
||||
# Admin bootstrap (only used on the very first --install run; without it, the first visitor
|
||||
# to the login page gets a create admin user form)
|
||||
#COMPOSE_FILE="$COMPOSE_FILE:compose.adminbootstrap.yml"
|
||||
#LISTMONK_ADMIN_USER=admin
|
||||
#SECRET_ADMIN_PW_VERSION=v1
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* **Category**: Development
|
||||
* **Status**: 2, beta
|
||||
* **Image**: [`listmonk/listmonk`](https://hub.docker.com/r/listmonk/listmonk/), 2, upstream
|
||||
* **Healthcheck**: No
|
||||
* **Healthcheck**: Yes
|
||||
* **Backups**: Yes
|
||||
* **Email**: Yes
|
||||
* **Tests**: 2
|
||||
@@ -17,8 +17,9 @@
|
||||
|
||||
1. Set up Docker Swarm and [`abra`][abra]
|
||||
2. Deploy [`coop-cloud/traefik`][cc-traefik]
|
||||
3. `abra app new listmonk --secrets` (optionally with `--pass` if you'd like
|
||||
to save secrets in `pass`)
|
||||
4. `abra app config YOURAPPDOMAIN` - be sure to change `$DOMAIN` to something that resolves to your Docker swarm box. Nothing to change apart from the DOMAIN at the moment.
|
||||
5. `abra app deploy YOURAPPDOMAIN`
|
||||
6. To make media uploads work, go to Settings->Media uploads and set upload path to "/uploads" and click the Save-button.
|
||||
3. `abra app new listmonk`
|
||||
4. `abra app config YOURAPPDOMAIN`
|
||||
5. (optional) To set the admin user yourself instead of letting the welcome form create one, uncomment the admin bootstrap lines in `.env`.
|
||||
6. `abra app secret generate YOURAPPDOMAIN`
|
||||
7. `abra app deploy YOURAPPDOMAIN`
|
||||
8. To make media uploads work, go to Settings->Media uploads and set upload path to "/uploads" and click the Save-button.
|
||||
|
||||
@@ -1,2 +1,51 @@
|
||||
export CONFIG_TOML_VERSION=v2
|
||||
export APP_ENTRYPOINT_VERSION=v1
|
||||
export APP_ENTRYPOINT_VERSION=v2
|
||||
export PG_BACKUP_VERSION=v3
|
||||
|
||||
# Writes one row of listmonk's flat key/value `settings` table (key TEXT UNIQUE, value JSONB).
|
||||
#
|
||||
# VALUE is an unquoted scalar/array/object, not pre-quoted JSON text: true/false, numbers
|
||||
# and [...]/{...} pass straight through as-is; anything else is treated as a string and
|
||||
# wrapped via Postgres's to_jsonb().
|
||||
# For array/object values, escape ", { and } with a \.
|
||||
#
|
||||
# Usage: db set_setting <key> <raw_value>
|
||||
# db set_setting app.cache_slow_queries true
|
||||
# db set_setting upload.max_file_size 6000
|
||||
# db set_setting app.root_url example.com
|
||||
# db set_setting upload.extensions [\"jpg\",\"jpeg\",\"png\"]
|
||||
# db set_setting security.oidc \{\"enabled\":true,\"provider_name\":\"SSO\"\}
|
||||
set_setting() {
|
||||
if [ "$TARGET" != "db" ]; then
|
||||
echo "ERROR: set_setting must run in the db container -- call it as 'db set_setting ...'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local KEY="$1" VALUE="$2"
|
||||
|
||||
if [ -z "$KEY" ] || [ -z "$VALUE" ]; then
|
||||
echo "Usage: set_setting <key> <raw_value>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local ESCAPED_VALUE
|
||||
ESCAPED_VALUE="$(printf '%s' "$VALUE" | sed "s/'/''/g")"
|
||||
|
||||
local VALUE_EXPR
|
||||
if [ "$VALUE" = "true" ] || [ "$VALUE" = "false" ] || [[ "$VALUE" =~ ^-?[0-9]+(\.[0-9]+)?$ ]] \
|
||||
|| [[ "$VALUE" == \[*\] ]] || [[ "$VALUE" == \{*\} ]]; then
|
||||
VALUE_EXPR="'${ESCAPED_VALUE}'::jsonb"
|
||||
else
|
||||
VALUE_EXPR="to_jsonb('${ESCAPED_VALUE}'::text)"
|
||||
fi
|
||||
|
||||
if ! PGPASSWORD="$(cat "$POSTGRES_PASSWORD_FILE")" psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" <<SQL | grep -qx "UPDATE 1"
|
||||
UPDATE settings SET value = ${VALUE_EXPR}, updated_at = now() WHERE key = '${KEY}';
|
||||
SQL
|
||||
then
|
||||
echo "ERROR: no row matched key '${KEY}' in settings, or '${VALUE}' isn't valid" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Set '${KEY}'"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
app:
|
||||
environment:
|
||||
- LISTMONK_ADMIN_USER=${LISTMONK_ADMIN_USER:-admin}
|
||||
secrets:
|
||||
- admin_pw
|
||||
|
||||
secrets:
|
||||
admin_pw:
|
||||
name: ${STACK_NAME}_admin_pw_${SECRET_ADMIN_PW_VERSION}
|
||||
external: true
|
||||
+18
-8
@@ -3,7 +3,7 @@ version: "3.8"
|
||||
|
||||
services:
|
||||
app:
|
||||
image: listmonk/listmonk:v6.1.0
|
||||
image: listmonk/listmonk:v6.2.0
|
||||
networks:
|
||||
- internal
|
||||
- proxy
|
||||
@@ -14,6 +14,11 @@ services:
|
||||
- db_password
|
||||
depends_on:
|
||||
- db
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://localhost:9000/health"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 6
|
||||
configs:
|
||||
- source: config_toml
|
||||
target: /listmonk/config.toml
|
||||
@@ -31,7 +36,7 @@ services:
|
||||
- "traefik.http.routers.${STACK_NAME}.entrypoints=web-secure"
|
||||
- "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=9000"
|
||||
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${LETS_ENCRYPT_ENV}"
|
||||
- "coop-cloud.${STACK_NAME}.version=5.1.0+v6.1.0"
|
||||
- "coop-cloud.${STACK_NAME}.version=5.3.0+v6.2.0"
|
||||
volumes:
|
||||
- "uploads:/uploads"
|
||||
|
||||
@@ -54,12 +59,14 @@ services:
|
||||
- "postgres:/var/lib/postgresql"
|
||||
deploy:
|
||||
labels:
|
||||
backupbot.backup: "true"
|
||||
backupbot.backup.pre-hook: sh -c 'pg_dump -U "$$POSTGRES_USER" -Fc "$$POSTGRES_DB" | gzip > "/postgres.dump.gz"'
|
||||
backupbot.backup.path: "/postgres.dump.gz"
|
||||
backupbot.backup.post-hook: "rm -f /postgres.dump.gz"
|
||||
backupbot.restore: "true"
|
||||
backupbot.restore.post-hook: sh -c 'gzip -d /postgres.dump.gz && pg_restore --clean -U "$$POSTGRES_USER" --dbname="$$POSTGRES_DB" < /postgres.dump && rm -f /postgres.dump'
|
||||
backupbot.backup: ${ENABLE_BACKUPS:-true}
|
||||
backupbot.backup.volumes.postgres.path: "backup.sql"
|
||||
backupbot.backup.pre-hook: "/pg_backup.sh backup"
|
||||
backupbot.restore.post-hook: '/pg_backup.sh restore'
|
||||
configs:
|
||||
- source: pg_backup
|
||||
target: /pg_backup.sh
|
||||
mode: 0555
|
||||
|
||||
secrets:
|
||||
db_password:
|
||||
@@ -74,6 +81,9 @@ configs:
|
||||
app_entrypoint:
|
||||
name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION}
|
||||
file: docker-entrypoint.sh
|
||||
pg_backup:
|
||||
name: ${STACK_NAME}_pg_backup_${PG_BACKUP_VERSION}
|
||||
file: pg_backup.sh
|
||||
|
||||
networks:
|
||||
internal:
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
cd /listmonk
|
||||
|
||||
# listmonk's admin bootstrap vars have no *_FILE support
|
||||
if [ -f /run/secrets/admin_pw ]; then
|
||||
export LISTMONK_ADMIN_PASSWORD="$(cat /run/secrets/admin_pw)"
|
||||
fi
|
||||
|
||||
./listmonk --install --yes --idempotent
|
||||
./listmonk --upgrade --yes
|
||||
./listmonk
|
||||
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DATADIR="${PGDATA:-/var/lib/postgresql/18/docker}"
|
||||
LATEST_BACKUP_FILE="/var/lib/postgresql/backup.sql"
|
||||
|
||||
function backup {
|
||||
if [ -f "$POSTGRES_PASSWORD_FILE" ]; then
|
||||
export PGPASSWORD=$(cat "$POSTGRES_PASSWORD_FILE")
|
||||
fi
|
||||
|
||||
echo "Creating backup at ${LATEST_BACKUP_FILE}..."
|
||||
pg_dump -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}" > "${LATEST_BACKUP_FILE}"
|
||||
|
||||
echo "Backup done. You will find it at ${LATEST_BACKUP_FILE}"
|
||||
}
|
||||
|
||||
function restore {
|
||||
echo "Restoring database from ${LATEST_BACKUP_FILE}..."
|
||||
|
||||
cd ${DATADIR}
|
||||
|
||||
function restore_config {
|
||||
echo "Restoring original pg_hba.conf configuration..."
|
||||
cat pg_hba.conf.bak > pg_hba.conf
|
||||
su postgres -c 'pg_ctl reload'
|
||||
}
|
||||
|
||||
# Don't allow any other connections than local
|
||||
echo "Setting up temporary pg_hba.conf to only allow local connections..."
|
||||
cp pg_hba.conf pg_hba.conf.bak
|
||||
echo "local all all trust" > pg_hba.conf
|
||||
su postgres -c 'pg_ctl reload'
|
||||
trap restore_config EXIT INT TERM
|
||||
|
||||
# Recreate Database
|
||||
echo "Dropping existing database ${POSTGRES_DB:-postgres}..."
|
||||
psql -U "${POSTGRES_USER:-postgres}" -d postgres -c "DROP DATABASE \"${POSTGRES_DB:-postgres}\" WITH (FORCE);"
|
||||
|
||||
echo "Creating fresh database ${POSTGRES_DB:-postgres}..."
|
||||
createdb -U "${POSTGRES_USER:-postgres}" "${POSTGRES_DB:-postgres}"
|
||||
|
||||
echo "Restoring data from ${LATEST_BACKUP_FILE}..."
|
||||
psql -U "${POSTGRES_USER:-postgres}" -d "${POSTGRES_DB:-postgres}" -1 -f "${LATEST_BACKUP_FILE}"
|
||||
|
||||
trap - EXIT INT TERM
|
||||
restore_config
|
||||
|
||||
echo "Database restore completed successfully."
|
||||
}
|
||||
|
||||
# Execute the function passed as argument
|
||||
case "$1" in
|
||||
backup)
|
||||
backup
|
||||
;;
|
||||
restore)
|
||||
restore
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {backup|restore}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,4 @@
|
||||
- Optional admin-bootstrap overlay: sets the initial admin user/password before first install
|
||||
- set_setting abra.sh helper for writing Listmonk's settings directly to db
|
||||
- Healthcheck for the app service.
|
||||
- Fix Postgres backup: wrong volume label
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user