From b55e5e45779cc28a623dffe6dfe5288878aef606 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Thu, 27 May 2021 19:09:16 +0200 Subject: [PATCH] Adapt for Networ7 environment - Add clamav - Use nlss/mariadb - Add healthchecks - Overall improvements --- alpine/docker-compose.yml | 156 ++++++++++++++++----- alpine/src/docker-entrypoint.sh | 2 +- alpine/src/templates/postal.example.yml.j2 | 21 +-- alpine/src/templates/postal.yml.j2 | 21 +-- 4 files changed, 146 insertions(+), 54 deletions(-) diff --git a/alpine/docker-compose.yml b/alpine/docker-compose.yml index f06a614..cd0514c 100644 --- a/alpine/docker-compose.yml +++ b/alpine/docker-compose.yml @@ -1,64 +1,146 @@ version: "3" services: - postal: - image: catdeployed/postal:alpine - container_name: postal - command: run - ports: - - 127.0.0.1:25:25 + + nginx: + image: nginx:mainline-alpine + links: + - service depends_on: - - "mysql" - - "rabbitmq" + - service volumes: - - persistent_assets:/storage + - ./src/nginx.conf:/etc/nginx/conf.d/default.conf:ro + - static_assets:/opt/postal/public:ro + - assets:/opt/postal/public/assets:ro + networks: + default: {aliases: [ postal_nginx, nginx ]} + http: + restart: unless-stopped + healthcheck: + test: [ "CMD", "curl", "--fail", "http://127.0.0.1" ] + interval: 15s + timeout: 10s + retries: 3 + + service: + image: catdeployed/postal:alpine + build: + context: . + command: run + depends_on: + - systemdb + - messagedb + - queue + - clamav + volumes: + - storage:/storage - static_assets:/opt/postal/public - - postal_assets:/opt/postal/public/assets + - assets:/opt/postal/public/assets - ./src/templates/:/templates environment: - - MYSQL_ROOT_PASSWORD=changeme - - MYSQL_DATABASE=postal + - CLAMAV_HOST=clamav + - CLAMAV_PORT=3310 + - SYSTEMDB_HOST=systemdb + - SYSTEMDB_DATABASE=postal + - SYSTEMDB_USER=root + - SYSTEMDB_PASSWORD=SQtDHUD7spitQQvoQ^2vSCTZBg5nX^ + - MESSAGEDB_HOST=messagedb + - MESSAGEDB_DATABASE=messages + - MESSAGEDB_USER=root + - MESSAGEDB_PASSWORD=SQtDHUD7spitQQvoQ^2vSCTZBg5nX^ - RABBITMQ_DEFAULT_USER=postal - RABBITMQ_DEFAULT_PASS=changeme - RABBITMQ_DEFAULT_VHOST=postal - POSTAL_FNAME=Sia - POSTAL_LNAME=Cat - - POSTAL_PASSWORD=SecretCatPassword - - POSTAL_EMAIL=myemail@catsworld.com + - POSTAL_PASSWORD=hDzqLsP5hEXuBinpQ3KHSknvgTxRu6 + - POSTAL_EMAIL=aleksandar@puharic.com + networks: + default: { aliases: [ postal, service ] } + client: { aliases: [ postal, mailer, mailer-service ] } healthcheck: test: curl -sS http://127.0.0.1:5000 || exit 1 interval: 5s timeout: 10s retries: 3 - mysql: - image: mariadb:10 - container_name: postal_mysql + restart: unless-stopped + + systemdb: + image: nlss/mariadb volumes: - - mysql_data:/var/lib/mysql + - systemdb_data:/var/lib/mysql + - systemdb_backup:/var/lib/backup + - systemdb_log:/var/log/mysql environment: - - MYSQL_ROOT_PASSWORD=changeme - - MYSQL_DATABASE=postal - rabbitmq: + - MARIADB_ROOT_PASSWORD=SQtDHUD7spitQQvoQ^2vSCTZBg5nX^ + - MARIADB_DATABASE=postal + networks: + default: { aliases: [ postal_mysql, mysql, mariadb, database ] } + restart: unless-stopped + healthcheck: + test: [ "CMD", "/usr/bin/healthcheck" ] + interval: 30s + timeout: 20s + retries: 3 + + messagedb: + image: nlss/mariadb + volumes: + - messagedb_data:/var/lib/mysql + - messagedb_backup:/var/lib/backup + - messagedb_log:/var/log/mysql + environment: + - MARIADB_ROOT_PASSWORD=SQtDHUD7spitQQvoQ^2vSCTZBg5nX^ + - MARIADB_DATABASE=messages + networks: + default: { aliases: [ postal_mysql, mysql, mariadb, database ] } + restart: unless-stopped + healthcheck: + test: [ "CMD", "/usr/bin/healthcheck" ] + interval: 30s + timeout: 20s + retries: 3 + + queue: image: rabbitmq:3-alpine - container_name: postal_rabbitmq environment: - RABBITMQ_DEFAULT_USER=postal - RABBITMQ_DEFAULT_PASS=changeme - RABBITMQ_DEFAULT_VHOST=/postal - nginx: - image: nginx - container_name: postal_nginx - ports: - - 80:80 - links: - - postal - depends_on: - - postal + networks: + default: { aliases: [ postal_rabbitmq, rabbitmq, queue ] } + restart: unless-stopped + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 30s + timeout: 30s + retries: 3 + + clamav: + image: mkodockx/docker-clamav:alpine volumes: - - ./src/nginx.conf:/etc/nginx/conf.d/default.conf:ro - - static_assets:/opt/postal/public:ro - - postal_assets:/opt/postal/public/assets:ro + - clamav_data:/var/lib/clamav + networks: + default: { aliases: [ clamav ] } + healthcheck: + test: [ "CMD", "./check.sh" ] + interval: 60s + retries: 3 + start_period: 120s + restart: unless-stopped + +networks: + default: + client: + http: + volumes: static_assets: - postal_assets: - mysql_data: - persistent_assets: + assets: + clamav_data: + systemdb_data: + systemdb_backup: + systemdb_log: + messagedb_data: + messagedb_backup: + messagedb_log: + storage: diff --git a/alpine/src/docker-entrypoint.sh b/alpine/src/docker-entrypoint.sh index 54948f4..cad859e 100755 --- a/alpine/src/docker-entrypoint.sh +++ b/alpine/src/docker-entrypoint.sh @@ -22,7 +22,7 @@ elif [ ! -f /opt/postal/config/postal.yml ] || [[ $(cat /opt/postal/config/posta ## Generate config and keys /opt/postal/bin/postal initialize-config /opt/postal/bin/postal initialize - /create-user.sh + #/create-user.sh ## Copy over config to persistent storage cp -p /opt/postal/config/postal.yml /storage/postal.yml rm /opt/postal/config/postal.yml diff --git a/alpine/src/templates/postal.example.yml.j2 b/alpine/src/templates/postal.example.yml.j2 index a817f91..45c1b37 100644 --- a/alpine/src/templates/postal.example.yml.j2 +++ b/alpine/src/templates/postal.example.yml.j2 @@ -21,18 +21,18 @@ general: main_db: # Specify the connection details for your MySQL database - host: mysql - username: root - password: {{ MYSQL_ROOT_PASSWORD }} - database: {{ MYSQL_DATABASE }} + host: {{ SYSTEMDB_HOST }} + username: {{ SYSTEMDB_USER }} + password: {{ SYSTEMDB_PASSWORD }} + database: {{ SYSTEMDB_DATABASE }} message_db: # Specify the connection details for your MySQL server that will be house the # message databases for mail servers. - host: mysql - username: root - password: {{ MYSQL_ROOT_PASSWORD }} - prefix: postal + host: {{ MESSAGEDB_HOST }} + username: {{ MESSAGEDB_USER }} + password: {{ MESSAGEDB_PASSWORD }} + database: {{ MESSAGEDB_DATABASE }} rabbitmq: # Specify the connection details for your RabbitMQ server. @@ -64,3 +64,8 @@ smtp: from_name: Postal from_address: postal@yourdomain.com +clamav: + enabled: true + host: {{ CLAMAV_HOST }} + port: {{ CLAMAV_PORT }} + diff --git a/alpine/src/templates/postal.yml.j2 b/alpine/src/templates/postal.yml.j2 index 3728075..9daae0c 100644 --- a/alpine/src/templates/postal.yml.j2 +++ b/alpine/src/templates/postal.yml.j2 @@ -16,18 +16,18 @@ general: main_db: # Specify the connection details for your MySQL database - host: mysql - username: root - password: {{ MYSQL_ROOT_PASSWORD }} - database: {{ MYSQL_DATABASE }} + host: {{ SYSTEMDB_HOST }} + username: {{ SYSTEMDB_USER }} + password: {{ SYSTEMDB_PASSWORD }} + database: {{ SYSTEMDB_DATABASE }} message_db: # Specify the connection details for your MySQL server that will be house the # message databases for mail servers. - host: mysql - username: root - password: {{ MYSQL_ROOT_PASSWORD }} - prefix: postal + host: {{ MESSAGEDB_HOST }} + username: {{ MESSAGEDB_USER }} + password: {{ MESSAGEDB_PASSWORD }} + database: {{ MESSAGEDB_DATABASE }} rabbitmq: # Specify the connection details for your RabbitMQ server. @@ -66,3 +66,8 @@ rails: web_server: bind_address: 0.0.0.0 + +clamav: + enabled: true + host: {{ CLAMAV_HOST }} + port: {{ CLAMAV_PORT }} \ No newline at end of file