From 81f1adfa068ae8ee092d8333f63674298e8acec6 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 10 Jun 2024 11:51:56 +0200 Subject: [PATCH 1/6] Simplify ENV handling by using default values in the YAML --- .env | 30 ++++++++++++++--------------- docker-compose.yml | 48 +++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.env b/.env index 3560132..08955cd 100644 --- a/.env +++ b/.env @@ -1,19 +1,19 @@ -ELASTICSEARCH_VERSION=8.12.2 -IMAGE_REPO=ghcr.io/zammad/zammad -MEMCACHE_SERVERS=zammad-memcached:11211 -MEMCACHE_VERSION=1.6.25-alpine -POSTGRES_DB=zammad_production -POSTGRES_PASS=zammad -POSTGRES_USER=zammad -POSTGRES_HOST=zammad-postgresql -POSTGRES_PORT=5432 -POSTGRES_VERSION=15.6-alpine -POSTGRESQL_OPTIONS=?pool=50 -REDIS_URL=redis://zammad-redis:6379 -REDIS_VERSION=7.2.4-alpine -RESTART=always +# ELASTICSEARCH_VERSION=8.12.2 +# IMAGE_REPO=ghcr.io/zammad/zammad +# MEMCACHE_SERVERS=zammad-memcached:11211 +# MEMCACHE_VERSION=1.6.25-alpine +# POSTGRES_DB=zammad_production +# POSTGRES_PASS=zammad +# POSTGRES_USER=zammad +# POSTGRES_HOST=zammad-postgresql +# POSTGRES_PORT=5432 +# POSTGRES_VERSION=15.6-alpine +# POSTGRESQL_OPTIONS=?pool=50 +# REDIS_URL=redis://zammad-redis:6379 +# REDIS_VERSION=7.2.4-alpine +# RESTART=always # Use a fixed version. You are responsible to update this to newer patch level versions yourself. -VERSION=6.3.1 +# VERSION=6.3.1 # You can also use floating versions that will give you automatic updates: # VERSION=6.2 # all patchlevel updates # VERSION=6 # including minor updates diff --git a/docker-compose.yml b/docker-compose.yml index 5438794..2ea006d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,13 +4,15 @@ version: '3.8' x-shared: zammad-service: &zammad-service environment: &zammad-environment - MEMCACHE_SERVERS: ${MEMCACHE_SERVERS} - POSTGRESQL_DB: ${POSTGRES_DB} - POSTGRESQL_HOST: ${POSTGRES_HOST} - POSTGRESQL_USER: ${POSTGRES_USER} - POSTGRESQL_PASS: ${POSTGRES_PASS} - POSTGRESQL_PORT: ${POSTGRES_PORT} - REDIS_URL: ${REDIS_URL} + MEMCACHE_SERVERS: ${MEMCACHE_SERVERS:-zammad-memcached:11211} + POSTGRESQL_DB: ${POSTGRES_DB:-zammad_production} + POSTGRESQL_HOST: ${POSTGRES_HOST:-zammad-postgresql} + POSTGRESQL_USER: ${POSTGRES_USER:-zammad} + POSTGRESQL_PASS: ${POSTGRES_PASS:-zammad} + POSTGRESQL_PORT: ${POSTGRES_PORT:-5432} + POSTGRESQL_OPTIONS: ${POSTGRESQL_OPTIONS:-?pool=50} + POSTGRESQL_DB_CREATE: + REDIS_URL: ${REDIS_URL:-redis://zammad-redis:6379} # Allow passing in these variables via .env: AUTOWIZARD_JSON: AUTOWIZARD_RELATIVE_PATH: @@ -24,15 +26,13 @@ x-shared: NGINX_PORT: NGINX_SERVER_NAME: NGINX_SERVER_SCHEME: - POSTGRESQL_DB_CREATE: - POSTGRESQL_OPTIONS: RAILS_TRUSTED_PROXIES: ZAMMAD_WEB_CONCURRENCY: ZAMMAD_SESSION_JOBS: ZAMMAD_PROCESS_SCHEDULED: ZAMMAD_PROCESS_DELAYED_JOBS_WORKERS: - image: ${IMAGE_REPO}:${VERSION} - restart: ${RESTART} + image: ${IMAGE_REPO:-ghcr.io/zammad/zammad}:${VERSION:-6.3.1} + restart: ${RESTART:-always} volumes: - zammad-storage:/opt/zammad/storage depends_on: @@ -53,16 +53,16 @@ services: BACKUP_TIME: "03:00" HOLD_DAYS: "10" TZ: Europe/Berlin - image: postgres:${POSTGRES_VERSION} - restart: ${RESTART} + image: postgres:${POSTGRES_VERSION:-15.6-alpine} + restart: ${RESTART:-always} volumes: - zammad-backup:/var/tmp/zammad - zammad-storage:/opt/zammad/storage:ro - ./scripts/backup.sh:/usr/local/bin/backup.sh:ro zammad-elasticsearch: - image: bitnami/elasticsearch:${ELASTICSEARCH_VERSION} - restart: ${RESTART} + image: bitnami/elasticsearch:${ELASTICSEARCH_VERSION:-8.12.2} + restart: ${RESTART:-always} volumes: - elasticsearch-data:/bitnami/elasticsearch/data @@ -78,8 +78,8 @@ services: zammad-memcached: command: memcached -m 256M - image: memcached:${MEMCACHE_VERSION} - restart: ${RESTART} + image: memcached:${MEMCACHE_VERSION:-1.6.25-alpine} + restart: ${RESTART:-always} zammad-nginx: <<: *zammad-service @@ -91,11 +91,11 @@ services: zammad-postgresql: environment: - POSTGRES_DB: ${POSTGRES_DB} - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASS} - image: postgres:${POSTGRES_VERSION} - restart: ${RESTART} + POSTGRES_DB: ${POSTGRES_DB:-zammad_production} + POSTGRES_USER: ${POSTGRES_USER:-zammad} + POSTGRES_PASSWORD: ${POSTGRES_PASS:-zammad} + image: postgres:${POSTGRES_VERSION:-15.6-alpine} + restart: ${RESTART:-always} volumes: - postgresql-data:/var/lib/postgresql/data @@ -104,8 +104,8 @@ services: command: ["zammad-railsserver"] zammad-redis: - image: redis:${REDIS_VERSION} - restart: ${RESTART} + image: redis:${REDIS_VERSION:-7.2.4-alpine} + restart: ${RESTART:-always} volumes: - redis-data:/data From 6a5974f3021aa6ff96c4f8a25e6605cd7c529d24 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 10 Jun 2024 12:09:22 +0200 Subject: [PATCH 2/6] Improve handling of NGINX port settings. --- .env | 2 ++ docker-compose.override.yml | 12 ++++++------ docker-compose.yml | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 08955cd..c102001 100644 --- a/.env +++ b/.env @@ -2,6 +2,8 @@ # IMAGE_REPO=ghcr.io/zammad/zammad # MEMCACHE_SERVERS=zammad-memcached:11211 # MEMCACHE_VERSION=1.6.25-alpine +# NGINX_PORT=8080 +# NGINX_EXPOSE_PORT=8080 # POSTGRES_DB=zammad_production # POSTGRES_PASS=zammad # POSTGRES_USER=zammad diff --git a/docker-compose.override.yml b/docker-compose.override.yml index cccfd4d..3192485 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,8 +1,8 @@ ---- -version: '3.8' +# --- +# version: '3.8' -services: +# services: - zammad-nginx: - ports: - - "8080:8080" +# zammad-nginx: +# ports: +# - "8080:8080" diff --git a/docker-compose.yml b/docker-compose.yml index 2ea006d..4283829 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -85,7 +85,9 @@ services: <<: *zammad-service command: ["zammad-nginx"] expose: - - "8080" + - ":${NGINX_PORT:-8080}" + ports: + - "${NGINX_EXPOSE_PORT:-8080}:${NGINX_PORT:-8080}" depends_on: - zammad-railsserver From 1191e1df087bb905b77c49107eef108c51a24905 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 10 Jun 2024 12:16:09 +0200 Subject: [PATCH 3/6] Remove obsolete override file. --- docker-compose.override.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 docker-compose.override.yml diff --git a/docker-compose.override.yml b/docker-compose.override.yml deleted file mode 100644 index 3192485..0000000 --- a/docker-compose.override.yml +++ /dev/null @@ -1,8 +0,0 @@ -# --- -# version: '3.8' - -# services: - -# zammad-nginx: -# ports: -# - "8080:8080" From d93195e8d1e21d27b8b18da47be6046009b8999f Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 10 Jun 2024 12:19:37 +0200 Subject: [PATCH 4/6] Fix typo. --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4283829..6ee5951 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -85,7 +85,7 @@ services: <<: *zammad-service command: ["zammad-nginx"] expose: - - ":${NGINX_PORT:-8080}" + - "${NGINX_PORT:-8080}" ports: - "${NGINX_EXPOSE_PORT:-8080}:${NGINX_PORT:-8080}" depends_on: From b88f5441c62a6731595420d0d5e45c07170f852a Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Tue, 11 Jun 2024 08:28:48 +0200 Subject: [PATCH 5/6] Remove duplicate volume definition --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6ee5951..48dfe43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -73,8 +73,6 @@ services: - zammad-postgresql restart: on-failure user: 0:0 - volumes: - - zammad-storage:/opt/zammad/storage zammad-memcached: command: memcached -m 256M From 7c2295adb72eb09b0dc8799db95740213e6d61d4 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Tue, 11 Jun 2024 11:12:55 +0200 Subject: [PATCH 6/6] Switch to docker backup script that was added to the Zammad image. --- .env | 2 +- docker-compose.override-local.yml | 3 ++ docker-compose.yml | 21 ++++----- scripts/backup.sh | 74 ------------------------------- 4 files changed, 12 insertions(+), 88 deletions(-) delete mode 100755 scripts/backup.sh diff --git a/.env b/.env index c102001..5e9a6c8 100644 --- a/.env +++ b/.env @@ -15,7 +15,7 @@ # REDIS_VERSION=7.2.4-alpine # RESTART=always # Use a fixed version. You are responsible to update this to newer patch level versions yourself. -# VERSION=6.3.1 +# VERSION=6.3.1-38 # You can also use floating versions that will give you automatic updates: # VERSION=6.2 # all patchlevel updates # VERSION=6 # including minor updates diff --git a/docker-compose.override-local.yml b/docker-compose.override-local.yml index b42070b..ccd3a1c 100644 --- a/docker-compose.override-local.yml +++ b/docker-compose.override-local.yml @@ -3,6 +3,9 @@ version: '3.8' services: + zammad-backup: + image: zammad-local + zammad-init: image: zammad-local diff --git a/docker-compose.yml b/docker-compose.yml index 48dfe43..b4d927a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,11 @@ x-shared: POSTGRESQL_OPTIONS: ${POSTGRESQL_OPTIONS:-?pool=50} POSTGRESQL_DB_CREATE: REDIS_URL: ${REDIS_URL:-redis://zammad-redis:6379} + # Backup settings + BACKUP_DIR: "${BACKUP_DIR:-/var/tmp/zammad}" + BACKUP_TIME: "${BACKUP_TIME:-03:00}" + HOLD_DAYS: "${HOLD_DAYS:-10}" + TZ: "${TZ:-Europe/Berlin}" # Allow passing in these variables via .env: AUTOWIZARD_JSON: AUTOWIZARD_RELATIVE_PATH: @@ -31,7 +36,7 @@ x-shared: ZAMMAD_SESSION_JOBS: ZAMMAD_PROCESS_SCHEDULED: ZAMMAD_PROCESS_DELAYED_JOBS_WORKERS: - image: ${IMAGE_REPO:-ghcr.io/zammad/zammad}:${VERSION:-6.3.1} + image: ${IMAGE_REPO:-ghcr.io/zammad/zammad}:${VERSION:-6.3.1-38} restart: ${RESTART:-always} volumes: - zammad-storage:/opt/zammad/storage @@ -43,22 +48,12 @@ x-shared: services: zammad-backup: + <<: *zammad-service command: ["zammad-backup"] - depends_on: - - zammad-railsserver - - zammad-postgresql - entrypoint: /usr/local/bin/backup.sh - environment: - <<: *zammad-environment - BACKUP_TIME: "03:00" - HOLD_DAYS: "10" - TZ: Europe/Berlin - image: postgres:${POSTGRES_VERSION:-15.6-alpine} - restart: ${RESTART:-always} volumes: - zammad-backup:/var/tmp/zammad - zammad-storage:/opt/zammad/storage:ro - - ./scripts/backup.sh:/usr/local/bin/backup.sh:ro + user: 0:0 zammad-elasticsearch: image: bitnami/elasticsearch:${ELASTICSEARCH_VERSION:-8.12.2} diff --git a/scripts/backup.sh b/scripts/backup.sh deleted file mode 100755 index e0bf4a2..0000000 --- a/scripts/backup.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -set -e - -: "${ZAMMAD_DIR:=/opt/zammad/storage}" -: "${BACKUP_DIR:=/var/tmp/zammad}" -: "${BACKUP_TIME:=03:00}" -: "${HOLD_DAYS:=10}" -: "${ZAMMAD_RAILSSERVER_HOST:=zammad-railsserver}" -: "${ZAMMAD_RAILSSERVER_PORT:=3000}" -: "${POSTGRESQL_DB:=zammad_production}" -: "${POSTGRESQL_HOST:=zammad-postgresql}" -: "${POSTGRESQL_PORT:=5432}" -: "${POSTGRESQL_USER:=zammad}" -: "${POSTGRESQL_PASS:=zammad}" - - -function check_railsserver_available { - until (echo > "/dev/tcp/$ZAMMAD_RAILSSERVER_HOST/$ZAMMAD_RAILSSERVER_PORT") &> /dev/null; do - echo "waiting for railsserver to be ready..." - sleep 60 - done -} - -function zammad_backup { - TIMESTAMP="$(date +'%Y%m%d%H%M%S')" - - echo "${TIMESTAMP} - backing up zammad..." - - # delete old backups - if [ -d "${BACKUP_DIR}" ] && [ -n "$(ls "${BACKUP_DIR}")" ]; then - find "${BACKUP_DIR}"/*_zammad_*.gz -type f -mtime +"${HOLD_DAYS}" -delete - fi - - if [ "${NO_FILE_BACKUP}" != "yes" ]; then - # tar files - tar -czf "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_files.tar.gz "${ZAMMAD_DIR}" - fi - - #db backup - pg_dump --dbname=postgresql://"${POSTGRESQL_USER}:${POSTGRESQL_PASS}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}" | gzip > "${BACKUP_DIR}"/"${TIMESTAMP}"_zammad_db.psql.gz - - echo "backup finished :)" -} - -if [ "$1" = 'zammad-backup' ]; then - - check_railsserver_available - - while true; do - NOW_TIMESTAMP=$(date +%s) - TOMORROW_DATE=$(date -d@"$((NOW_TIMESTAMP + 24*60*60))" +%Y-%m-%d) - - zammad_backup - - NEXT_TIMESTAMP=$(date -d "$TOMORROW_DATE $BACKUP_TIME" +%s) - NOW_TIMESTAMP=$(date +%s) - - sleep $((NEXT_TIMESTAMP - NOW_TIMESTAMP)) - done - -elif [ "$1" = 'zammad-backup-once' ]; then - check_railsserver_available - - zammad_backup - -elif [ "$1" = 'zammad-backup-db' ]; then - NO_FILE_BACKUP="yes" - - zammad_backup - -else - exec "$@" -fi