From a7ef0fe5123d6fda6deef7efd3ec2b81652c127f Mon Sep 17 00:00:00 2001 From: CatDeployed Date: Sat, 26 May 2018 19:42:52 -0400 Subject: [PATCH] Move to circleci + more reliable formating --- .circleci/config.yml | 22 ++++++++++ Dockerfile | 18 ++++---- build_timestamp | 1 - codeship-services.yml | 4 -- codeship-steps.yml | 7 --- dockercfg.encrypted | 1 - nginx.conf | 23 ---------- src/docker-entrypoint.sh | 24 +++++++++++ src/templates/postal.example.yml.j2 | 66 +++++++++++++++++++++++++++++ wrapper.sh | 42 ------------------ 10 files changed, 122 insertions(+), 86 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 build_timestamp delete mode 100644 codeship-services.yml delete mode 100644 codeship-steps.yml delete mode 100644 dockercfg.encrypted delete mode 100644 nginx.conf create mode 100755 src/docker-entrypoint.sh create mode 100644 src/templates/postal.example.yml.j2 delete mode 100755 wrapper.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..5bce319 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,22 @@ +version: 2 +jobs: + build: + machine: true + steps: + - checkout + - run: docker build -t postal:latest . +workflows: + version: 2 + nightly: + triggers: + - schedule: + cron: "0 * * * *" + filters: + branches: + only: + - master + jobs: + - build + commit: + jobs: + - build diff --git a/Dockerfile b/Dockerfile index df8ec68..6c4c3d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,25 @@ FROM ruby:2.4 -## Clone postal -COPY src /opt/postal - RUN apt-get -y update \ - && apt-get -y install nodejs mysql-client \ + && apt-get -y install nodejs mysql-client git-core python-minimal python-pip python-dev libcap2-bin \ + && 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 \ && useradd -r -d /opt/postal -s /bin/bash postal \ && chown -R postal:postal /opt/postal/ \ - && /opt/postal/bin/postal bundle /opt/postal/vendor/bundle \ - && mv /opt/postal/config /opt/postal/config-original + && /opt/postal/bin/postal bundle /opt/postal/vendor/bundle + +## Adjust permissions +RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/ruby ## Stick in required files -ADD wrapper.sh /wrapper.sh +ADD src/docker-entrypoint.sh /docker-entrypoint.sh +ADD src/templates /templates ## Expose EXPOSE 5000 ## Startup -ENTRYPOINT ["/bin/bash", "-c", "/wrapper.sh ${*}", "--"] +ENTRYPOINT ["/bin/bash", "-c", "/docker-entrypoint.sh ${*}", "--"] diff --git a/build_timestamp b/build_timestamp deleted file mode 100644 index 2998daa..0000000 --- a/build_timestamp +++ /dev/null @@ -1 +0,0 @@ -Tue Sep 12 12:00:06 EDT 2017 diff --git a/codeship-services.yml b/codeship-services.yml deleted file mode 100644 index 97432ed..0000000 --- a/codeship-services.yml +++ /dev/null @@ -1,4 +0,0 @@ -app: - build: - image: alinuxninja/postal - dockerfile: Dockerfile diff --git a/codeship-steps.yml b/codeship-steps.yml deleted file mode 100644 index db3b0cf..0000000 --- a/codeship-steps.yml +++ /dev/null @@ -1,7 +0,0 @@ -- service: app - type: push - image_name: alinuxninja/postal - registry: https://index.docker.io/v1/ - encrypted_dockercfg_path: dockercfg.encrypted - tag: master - image_tag: latest diff --git a/dockercfg.encrypted b/dockercfg.encrypted deleted file mode 100644 index 2c6a6d1..0000000 --- a/dockercfg.encrypted +++ /dev/null @@ -1 +0,0 @@ -do3fXlgx/znajtHioPJFLQ4biXCFLSZDnt3jzf02HdAEUJIAJIwSojMOl0wCiKDYlnWN75KxixTLPN8Acvb0VjeRsxYKHp5zR1We2eNFbyxPxFRvCra1FFrJ+B6fSK3HfwkRdPyxIMWnxKMsX//OzbwEQDbDHhh8hwzfHBsgaYaYeHFGzoSMD8F4PU8jnlLUY/2nyIvoj/k2aTLqUJkarJg8umKzJ/nNehLAeOoGXf7Mln7pVmJFfUeafesemgY= \ No newline at end of file diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index 6e6e638..0000000 --- a/nginx.conf +++ /dev/null @@ -1,23 +0,0 @@ -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/docker-entrypoint.sh b/src/docker-entrypoint.sh new file mode 100755 index 0000000..485c165 --- /dev/null +++ b/src/docker-entrypoint.sh @@ -0,0 +1,24 @@ +#!/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 + +## 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/src/templates/postal.example.yml.j2 b/src/templates/postal.example.yml.j2 new file mode 100644 index 0000000..a817f91 --- /dev/null +++ b/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/wrapper.sh b/wrapper.sh deleted file mode 100755 index 2b62dab..0000000 --- a/wrapper.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -## Refresh config -cp -R /opt/postal/config-original/* /opt/postal/config - -## Generate keys -/opt/postal/bin/postal initialize-config - -if [[ $(cat /opt/postal/config/postal.yml| grep -i web_server |wc -l) == 0 ]]; then -cat >> /opt/postal/config/postal.yml << EOF -web_server: - bind_address: 0.0.0.0 -EOF -fi - -## Set MySQL/RabbitMQ usernames/passwords -### MySQL Main DB -sed -i -e '/main_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e'/main_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e'/main_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e'/main_db:/!b' -e ':a' -e "s/database.*/database: $MYSQL_DATABASE/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -### MySQL Message DB -sed -i -e '/message_db:/!b' -e ':a' -e "s/host.*/host: mysql/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e'/message_db:/!b' -e ':a' -e "s/username.*/username: root/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e'/message_db:/!b' -e ':a' -e "s/password.*/password: $MYSQL_ROOT_PASSWORD/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -### RabbitMQ -sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/host.*/host: rabbitmq/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/username.*/username: $RABBITMQ_DEFAULT_USER/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/password.*/password: $RABBITMQ_DEFAULT_PASS/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /opt/postal/config/postal.yml -sed -i -e '/rabbitmq:/!b' -e ':a' -e "s/vhost.*/vhost: \/$RABBITMQ_DEFAULT_VHOST/;t trail" -e 'n;ba' -e ':trail' -e 'n;btrail' /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 "$@"