From a08c83165c7e9200c25ce50a91427480b46f4ab2 Mon Sep 17 00:00:00 2001 From: ALinuxNinja Date: Fri, 5 May 2017 22:31:47 -0400 Subject: [PATCH] make container more versatile --- Dockerfile | 10 ++++---- README.md | 20 ++++++++++++---- data/docker/webserver_bind.yml | 3 --- docker-compose.yml | 8 +++++-- scripts/start.sh | 44 ---------------------------------- 5 files changed, 26 insertions(+), 59 deletions(-) delete mode 100644 data/docker/webserver_bind.yml delete mode 100755 scripts/start.sh diff --git a/Dockerfile b/Dockerfile index 61c125f..68d2b30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM ruby:2.4 -## Install nodejss +## Install nodejs RUN apt-get -y update \ -&& apt-get -y install nodejs mysql-client\ +&& apt-get -y install nodejs \ && rm -rf /var/lib/apt/lists/* ## Install required gems @@ -21,11 +21,11 @@ RUN /opt/postal/bin/postal bundle /opt/postal/vendor/bundle ## Move config folder RUN mv /opt/postal/config /opt/postal/config-original -## Stick in startup script -ADD scripts/start.sh /start.sh +## Stick in required files +ADD wrapper.sh /wrapper.sh ## Expose EXPOSE 5000 ## Startup -CMD ["/start.sh"] +ENTRYPOINT ["/bin/bash", "-c", "/wrapper.sh ${*}", "--"] diff --git a/README.md b/README.md index 8891658..ac3625f 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,25 @@ Change configuration in docker-compose.yml to update passwords for MySQL/RabbitMQ. Both passwords in the `postal` service, `mysql` service and `rabbitmq` service have to be changed. -Then, start postal by running +Then, begin by following the directions at https://github.com/atech/postal/wiki/Installation#initialize-database--assets. +Postal can be accessed by checking the section below. Note that "intialize-config" is already run for you, as the database parameters need to be configured before the postal tool can be used. + +After configuration is done, run the following to bring the container up. ``` docker-compose up -d ``` +### Using the `postal` tool. +To use the `postal` tool, simply run +``` +docker-compose run postal +``` +For example, the following command runs `postal initialize` inside the container. +``` +docker-compose run postal initialize +``` -Default password is avaliable at https://github.com/atech/postal/wiki/Installation#accessing-the-web-interface - -### Configuration -Configuration is located at data/postal after the first start. Note that non-config files (i.e. files in https://github.com/atech/postal/tree/master/config) will be overwritten each time the container starts up. See https://github.com/atech/postal/blob/master/config/postal.defaults.yml for all possible configuration options +### Migrations +See https://github.com/atech/postal/wiki/Upgrading. Be sure to do some port mappings to allow your SMTP server and HTTP(s) server to be accessed. I suggest simply port mapping the SMTP server and using [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy) to proxy the HTTP server. diff --git a/data/docker/webserver_bind.yml b/data/docker/webserver_bind.yml deleted file mode 100644 index 6226c20..0000000 --- a/data/docker/webserver_bind.yml +++ /dev/null @@ -1,3 +0,0 @@ - -web_server: - bind_address: 0.0.0.0 diff --git a/docker-compose.yml b/docker-compose.yml index e5b3b8c..69e8d1b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,13 @@ services: build: . image: postal container_name: postal + command: run ports: - - 80:5000 - - 25:2525 + - 127.0.0.1:80:5000 + - 127.0.0.1:25:2525 + depends_on: + - "mysql" + - "rabbitmq" volumes: - ./data/postal:/opt/postal/config - ./data/docker:/docker diff --git a/scripts/start.sh b/scripts/start.sh deleted file mode 100755 index 89ddb1a..0000000 --- a/scripts/start.sh +++ /dev/null @@ -1,44 +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 /docker/webserver_bind.yml >> /opt/postal/config/postal.yml -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/* - -## Initialize DB -echo "== Waiting for MySQL to start up ==" -while ! mysqladmin ping -h mysql --silent; do - sleep 1 -done -if [[ $(mysql -h mysql -uroot -p$MYSQL_ROOT_PASSWORD -s --skip-column-names -e "SELECT COUNT(DISTINCT table_name) FROM information_schema.columns WHERE table_schema = 'postal'") == 0 ]]; then - /opt/postal/bin/postal initialize -else - /opt/postal/bin/postal upgrade -fi - -## Run -/opt/postal/bin/postal run