From 40506d7a70be8776807a83db95950af71e33dc85 Mon Sep 17 00:00:00 2001 From: CatDeployed Date: Mon, 23 Jul 2018 18:22:42 -0400 Subject: [PATCH] split into alpine/ubuntu --- .DS_Store | Bin 0 -> 6148 bytes .circleci/config.yml | 12 ++-- .gitignore | 11 +-- Dockerfile => alpine/Dockerfile | 0 {data => alpine/data}/.gitkeep | 0 .../docker-compose.yml | 2 +- {src => alpine/src}/docker-entrypoint.sh | 0 alpine/src/nginx.conf | 22 ++++++ .../src}/templates/postal.example.yml.j2 | 0 alpine/src/templates/postal.yml.j2 | 68 ++++++++++++++++++ ubuntu/Dockerfile | 27 +++++++ {data/postal => ubuntu/data}/.gitkeep | 0 ubuntu/docker-compose.yml | 52 ++++++++++++++ ubuntu/src/docker-entrypoint.sh | 25 +++++++ ubuntu/src/nginx.conf | 22 ++++++ ubuntu/src/templates/postal.example.yml.j2 | 66 +++++++++++++++++ ubuntu/src/templates/postal.yml.j2 | 68 ++++++++++++++++++ 17 files changed, 364 insertions(+), 11 deletions(-) create mode 100644 .DS_Store rename Dockerfile => alpine/Dockerfile (100%) rename {data => alpine/data}/.gitkeep (100%) rename docker-compose.yml => alpine/docker-compose.yml (95%) rename {src => alpine/src}/docker-entrypoint.sh (100%) create mode 100644 alpine/src/nginx.conf rename {src => alpine/src}/templates/postal.example.yml.j2 (100%) create mode 100644 alpine/src/templates/postal.yml.j2 create mode 100644 ubuntu/Dockerfile rename {data/postal => ubuntu/data}/.gitkeep (100%) create mode 100644 ubuntu/docker-compose.yml create mode 100755 ubuntu/src/docker-entrypoint.sh create mode 100644 ubuntu/src/nginx.conf create mode 100644 ubuntu/src/templates/postal.example.yml.j2 create mode 100644 ubuntu/src/templates/postal.yml.j2 diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0d2fd5702dc4feccfd4f449f5ac0ebc79bca6242 GIT binary patch literal 6148 zcmeHK%}&BV5Z(pU1!Lr3g2%mh;{XBWWYSbTcr&TdgBoa4B2BO*v`Dnp^fB~}d;?#{ zncam*X1(g(Nfah-5Dq3PIq(M%a&r}gel)YAY3Rpl9!EQbD2sBhT1(UB zVO=&`?W``-PNz|q?bcD2l|}8Kd3@Hte|$=xvzJ#*FbDpX>>8ZI8z_tV9-K)yio!b> zo5#=N2#En=fEXYK)`tOe28iwTDVZuI28e+lGJyMogobDt%r&a513J7uqrZfR0y@4W z5T!xOV6G87AY7*c>Qru?7+j~rxHNH=!Ca$GXI!le^O%+Aj~A|1hjFRG8Mic2PYe(P z%M28?S;h1J6n>eNkNo8nvWNj<;GZ$TOI@dHLs8~z{Z<~HwGvt%8VbhcsDOaJbO`_h h_mO?&)P9LN#90P&jW`RAt8_rR2q;3RBL;qffloouP)Ps) literal 0 HcmV?d00001 diff --git a/.circleci/config.yml b/.circleci/config.yml index 41bdf7b..3649abe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,12 +1,14 @@ version: 2 jobs: - build: + build-alpine: machine: true + working_directory: ~/repo/alpine steps: - - checkout + - checkout: + path: ~/repo - run: name: Build Postal Docker Container - command: docker build -t catdeployed/postal:latest . + command: cd alpine && docker build -t catdeployed/postal:latest -t catdeployed/postal:alpine . - run: name: Skip this job for Pull Requests command: '[[ -v CIRCLE_PR_NUMBER ]] && circleci step halt || true' @@ -27,7 +29,7 @@ workflows: only: - master jobs: - - build + - build-alpine commit: jobs: - - build + - build-alpine diff --git a/.gitignore b/.gitignore index 94f4143..78333c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -data/* -!data/.gitkeep -!data/postal/.gitkeep -codeship.aes -daily.sh +alpine/data/* +!alpine/data/.gitkeep +!alpine/data/postal/.gitkeep +ubuntu/data/* +!ubuntu/data/.gitkeep +!ubuntu/data/postal/.gitkeep diff --git a/Dockerfile b/alpine/Dockerfile similarity index 100% rename from Dockerfile rename to alpine/Dockerfile diff --git a/data/.gitkeep b/alpine/data/.gitkeep similarity index 100% rename from data/.gitkeep rename to alpine/data/.gitkeep diff --git a/docker-compose.yml b/alpine/docker-compose.yml similarity index 95% rename from docker-compose.yml rename to alpine/docker-compose.yml index 0c7299a..3a770c2 100644 --- a/docker-compose.yml +++ b/alpine/docker-compose.yml @@ -44,7 +44,7 @@ services: depends_on: - postal volumes: - - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + - ./src/nginx.conf:/etc/nginx/conf.d/default.conf:ro - static_assets:/opt/postal/public:ro - ./data/postal/assets:/opt/postal/public/assets:ro volumes: diff --git a/src/docker-entrypoint.sh b/alpine/src/docker-entrypoint.sh similarity index 100% rename from src/docker-entrypoint.sh rename to alpine/src/docker-entrypoint.sh diff --git a/alpine/src/nginx.conf b/alpine/src/nginx.conf new file mode 100644 index 0000000..216a801 --- /dev/null +++ b/alpine/src/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 80; + + root /opt/postal/public; + + location / { + client_max_body_size 50M; + try_files $uri $uri/index.html $uri.html @puma; + } + + location /assets { + add_header Cache-Control max-age=3600; + } + + location @puma { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://postal:5000; + } +} diff --git a/src/templates/postal.example.yml.j2 b/alpine/src/templates/postal.example.yml.j2 similarity index 100% rename from src/templates/postal.example.yml.j2 rename to alpine/src/templates/postal.example.yml.j2 diff --git a/alpine/src/templates/postal.yml.j2 b/alpine/src/templates/postal.yml.j2 new file mode 100644 index 0000000..3728075 --- /dev/null +++ b/alpine/src/templates/postal.yml.j2 @@ -0,0 +1,68 @@ +web: + # The host that the management interface will be available on + host: postal.example.com + # The protocol that requests to the management interface should happen on + protocol: https + +fast_server: + # This can be enabled to enable click & open tracking on emails. It is disabled by + # default as it requires a separate static IP address on your server. + enabled: false + bind_address: + +general: + # This can be changed to allow messages to be sent from multiple IP addresses + use_ip_pools: false + +main_db: + # Specify the connection details for your MySQL database + host: mysql + username: root + password: {{ MYSQL_ROOT_PASSWORD }} + database: {{ MYSQL_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 + +rabbitmq: + # Specify the connection details for your RabbitMQ server. + host: rabbitmq + username: {{ RABBITMQ_DEFAULT_USER }} + password: {{ RABBITMQ_DEFAULT_PASS }} + vhost: /{{ RABBITMQ_DEFAULT_VHOST }} + +dns: + # Specifies the DNS record that you have configured. Refer to the documentation at + # https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further + # information about these. + mx_records: + - mx.postal.example.com + smtp_server_hostname: postal.example.com + spf_include: spf.postal.example.com + return_path: rp.postal.example.com + route_domain: routes.postal.example.com + track_domain: track.postal.example.com + +smtp: + # Specify an SMTP server that can be used to send messages from the Postal management + # system to users. You can configure this to use a Postal mail server once the + # your installation has been set up. + host: 127.0.0.1 + port: 2525 + username: # Complete when Postal is running and you can + password: # generate the credentials within the interface. + from_name: Postal + from_address: postal@yourdomain.com + +rails: + # This is generated automatically by the config initialization. It should be a random + # string unique to your installation. + secret_key: {{secretkey}} + +web_server: + bind_address: 0.0.0.0 diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile new file mode 100644 index 0000000..f684885 --- /dev/null +++ b/ubuntu/Dockerfile @@ -0,0 +1,27 @@ +FROM ruby:2.4-alpine + +RUN apk --no-cache add nodejs mysql-client git bash python libcap py-setuptools py-pip build-base python-dev mariadb-dev tzdata \ + && pip install j2cli \ + && git clone https://github.com/atech/postal.git /opt/postal \ + && rm -rf /var/lib/apt/lists/* \ + && gem install bundler \ + && gem install procodile \ + && gem install tzinfo-data \ + && addgroup -S postal \ + && adduser -S -G postal -h /opt/postal -s /bin/bash postal \ + && chown -R postal:postal /opt/postal/ \ + && /opt/postal/bin/postal bundle /opt/postal/vendor/bundle \ + && rm -rf /var/cache/apk/* + +## Adjust permissions +RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/ruby + +## Stick in required files +ADD src/docker-entrypoint.sh /docker-entrypoint.sh +ADD src/templates /templates + +## Expose +EXPOSE 5000 + +## Startup +ENTRYPOINT ["/bin/bash", "-c", "/docker-entrypoint.sh ${*}", "--"] diff --git a/data/postal/.gitkeep b/ubuntu/data/.gitkeep similarity index 100% rename from data/postal/.gitkeep rename to ubuntu/data/.gitkeep diff --git a/ubuntu/docker-compose.yml b/ubuntu/docker-compose.yml new file mode 100644 index 0000000..3a770c2 --- /dev/null +++ b/ubuntu/docker-compose.yml @@ -0,0 +1,52 @@ +version: "3" +services: + postal: + image: catdeployed/postal:latest + container_name: postal + command: run + ports: + - 127.0.0.1:25:25 + depends_on: + - "mysql" + - "rabbitmq" + volumes: + - static_assets:/opt/postal/public + - ./data/postal/assets:/opt/postal/public/assets + - ./src/templates/:/templates + environment: + - MYSQL_ROOT_PASSWORD=changeme + - MYSQL_DATABASE=postal + - RABBITMQ_DEFAULT_USER=postal + - RABBITMQ_DEFAULT_PASS=changeme + - RABBITMQ_DEFAULT_VHOST=postal + mysql: + image: mariadb:10 + container_name: postal_mysql + volumes: + - ./data/mysql:/var/lib/mysql + environment: + - MYSQL_ROOT_PASSWORD=changeme + - MYSQL_DATABASE=postal + rabbitmq: + image: rabbitmq:3-alpine + container_name: postal_rabbitmq + environment: + - RABBITMQ_DEFAULT_USER=postal + - RABBITMQ_DEFAULT_PASS=changeme + - RABBITMQ_DEFAULT_VHOST=/postal + nginx: + image: nginx + restart: always + ports: + - 127.0.0.1:80:80 + links: + - postal + depends_on: + - postal + volumes: + - ./src/nginx.conf:/etc/nginx/conf.d/default.conf:ro + - static_assets:/opt/postal/public:ro + - ./data/postal/assets:/opt/postal/public/assets:ro +volumes: + static_assets: + diff --git a/ubuntu/src/docker-entrypoint.sh b/ubuntu/src/docker-entrypoint.sh new file mode 100755 index 0000000..3a82aca --- /dev/null +++ b/ubuntu/src/docker-entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +## Generate config +if [ ! -f /opt/postal/config/postal.yml ] || [[ $(cat /opt/postal/config/postal.yml | wc -l) < 2 ]]; then + ## Build Jinja2 Template + j2 /templates/postal.example.yml.j2 > /opt/postal/config/postal.example.yml + ## Add in secret key building + echo "rails:" >> /opt/postal/config/postal.example.yml + echo " secret_key: {{secretkey}}" >> /opt/postal/config/postal.example.yml + ## Generate config and keys + /opt/postal/bin/postal initialize-config +fi +cat /opt/postal/config/postal.yml + +## Clean Up +rm -rf /opt/postal/tmp/pids/* + +## Wait for MySQL to start up +echo "== Waiting for MySQL to start up ==" +while ! mysqladmin ping -h mysql --silent; do + sleep 0.5 +done + +## Start Postal +/opt/postal/bin/postal "$@" diff --git a/ubuntu/src/nginx.conf b/ubuntu/src/nginx.conf new file mode 100644 index 0000000..216a801 --- /dev/null +++ b/ubuntu/src/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 80; + + root /opt/postal/public; + + location / { + client_max_body_size 50M; + try_files $uri $uri/index.html $uri.html @puma; + } + + location /assets { + add_header Cache-Control max-age=3600; + } + + location @puma { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://postal:5000; + } +} diff --git a/ubuntu/src/templates/postal.example.yml.j2 b/ubuntu/src/templates/postal.example.yml.j2 new file mode 100644 index 0000000..a817f91 --- /dev/null +++ b/ubuntu/src/templates/postal.example.yml.j2 @@ -0,0 +1,66 @@ +web_server: + bind_address: 0.0.0.0 + port: 5000 + max_threads: 5 + +web: + # The host that the management interface will be available on + host: postal.example.com + # The protocol that requests to the management interface should happen on + protocol: https + +fast_server: + # This can be enabled to enable click & open tracking on emails. It is disabled by + # default as it requires a separate static IP address on your server. + enabled: false + bind_address: + +general: + # This can be changed to allow messages to be sent from multiple IP addresses + use_ip_pools: false + +main_db: + # Specify the connection details for your MySQL database + host: mysql + username: root + password: {{ MYSQL_ROOT_PASSWORD }} + database: {{ MYSQL_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 + +rabbitmq: + # Specify the connection details for your RabbitMQ server. + host: rabbitmq + username: {{ RABBITMQ_DEFAULT_USER }} + password: {{ RABBITMQ_DEFAULT_PASS }} + vhost: /{{ RABBITMQ_DEFAULT_VHOST }} + +dns: + # Specifies the DNS record that you have configured. Refer to the documentation at + # https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further + # information about these. + mx_records: + - mx.postal.example.com + smtp_server_hostname: postal.example.com + spf_include: spf.postal.example.com + return_path: rp.postal.example.com + route_domain: routes.postal.example.com + track_domain: track.postal.example.com + +smtp: + # Specify an SMTP server that can be used to send messages from the Postal management + # system to users. You can configure this to use a Postal mail server once the + # your installation has been set up. + host: 127.0.0.1 + port: 2525 + username: # Complete when Postal is running and you can + password: # generate the credentials within the interface. + from_name: Postal + from_address: postal@yourdomain.com + diff --git a/ubuntu/src/templates/postal.yml.j2 b/ubuntu/src/templates/postal.yml.j2 new file mode 100644 index 0000000..3728075 --- /dev/null +++ b/ubuntu/src/templates/postal.yml.j2 @@ -0,0 +1,68 @@ +web: + # The host that the management interface will be available on + host: postal.example.com + # The protocol that requests to the management interface should happen on + protocol: https + +fast_server: + # This can be enabled to enable click & open tracking on emails. It is disabled by + # default as it requires a separate static IP address on your server. + enabled: false + bind_address: + +general: + # This can be changed to allow messages to be sent from multiple IP addresses + use_ip_pools: false + +main_db: + # Specify the connection details for your MySQL database + host: mysql + username: root + password: {{ MYSQL_ROOT_PASSWORD }} + database: {{ MYSQL_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 + +rabbitmq: + # Specify the connection details for your RabbitMQ server. + host: rabbitmq + username: {{ RABBITMQ_DEFAULT_USER }} + password: {{ RABBITMQ_DEFAULT_PASS }} + vhost: /{{ RABBITMQ_DEFAULT_VHOST }} + +dns: + # Specifies the DNS record that you have configured. Refer to the documentation at + # https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further + # information about these. + mx_records: + - mx.postal.example.com + smtp_server_hostname: postal.example.com + spf_include: spf.postal.example.com + return_path: rp.postal.example.com + route_domain: routes.postal.example.com + track_domain: track.postal.example.com + +smtp: + # Specify an SMTP server that can be used to send messages from the Postal management + # system to users. You can configure this to use a Postal mail server once the + # your installation has been set up. + host: 127.0.0.1 + port: 2525 + username: # Complete when Postal is running and you can + password: # generate the credentials within the interface. + from_name: Postal + from_address: postal@yourdomain.com + +rails: + # This is generated automatically by the config initialization. It should be a random + # string unique to your installation. + secret_key: {{secretkey}} + +web_server: + bind_address: 0.0.0.0