From 95d3525a4da798e4c101c29d193e88b83b1fe38c Mon Sep 17 00:00:00 2001 From: ALinuxNinja Date: Thu, 27 Apr 2017 04:29:03 -0400 Subject: [PATCH] many fixes... --- Dockerfile | 9 ++++++--- docker-compose.yml | 10 +++++++++- scripts/start.sh | 23 +++++++++++++++-------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index ee74e9a..c8851d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,17 +9,20 @@ RUN apt-get -y update \ RUN gem install bundler && gem install procodile ## Create user for postal -RUN useradd -r -m -d /opt/postal -s /bin/bash postal +RUN useradd -r -d /opt/postal -s /bin/bash postal ## Clone postal -RUN git clone https://github.com/atech/postal /opt/postal/app \ +RUN git clone https://github.com/atech/postal /opt/postal \ && chown -R postal:postal /opt/postal/ ## Install gems required by postal -RUN /opt/postal/app/bin/postal bundle /opt/postal/app/vendor/bundle +RUN /opt/postal/bin/postal bundle /opt/postal/vendor/bundle ## Stick in startup script ADD scripts/start.sh /start.sh +## Create docker folder for status keeping +RUN mkdir /opt/postal/docker + ## Startup CMD ["/start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 1e272d0..35d22b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,16 @@ services: build: . image: postal container_name: postal + links: + - mysql + - rabbitmq environment: - POSTAL_HOSTNAME=idontknow.nowhere.com + - 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 @@ -18,4 +26,4 @@ services: environment: - RABBITMQ_DEFAULT_USER=postal - RABBITMQ_DEFAULT_PASS=changeme - - RABBITMQ_DEFAULT_VHOST=postal + - RABBITMQ_DEFAULT_VHOST=/postal diff --git a/scripts/start.sh b/scripts/start.sh index 61a1e4a..b7285f9 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,7 +2,7 @@ ## Generate keys if they do not exist if [[ ! -f /opt/postal/config/signing.key ]]; then - /opt/postal/app/bin/postal initialize-config + /opt/postal/bin/postal initialize-config fi ## Set Hostname @@ -12,17 +12,24 @@ sed -i "s/postal\.example\.com/$POSTAL_HOSTNAME/" /opt/postal/config/postal.yml ### 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: <%= ENV['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: <%= ENV['MYSQL_DATABASE'] %>/;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: <%= ENV['MYSQL_ROOT_PASSWORD'] %>/;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: <%= ENV['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: <%= ENV['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: \/<%= ENV['RABBITMQ_DEFAULT_VHOST'] %>/;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 +### Initialize DB +if [[ ! -f /opt/postal/docker/postal_initialized ]]; then + /opt/postal/bin/postal initialize && touch /opt/postal/docker/postal_initialized +fi + +## Clean Up +rm -r /opt/postal/tmp/pids ## Run -/opt/postal/app/bin/postal run +/opt/postal/bin/postal run