make container more versatile

This commit is contained in:
ALinuxNinja 2017-05-05 22:31:47 -04:00
parent 2e4e66766e
commit a08c83165c
5 changed files with 26 additions and 59 deletions

View File

@ -1,8 +1,8 @@
FROM ruby:2.4 FROM ruby:2.4
## Install nodejss ## Install nodejs
RUN apt-get -y update \ RUN apt-get -y update \
&& apt-get -y install nodejs mysql-client\ && apt-get -y install nodejs \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
## Install required gems ## Install required gems
@ -21,11 +21,11 @@ RUN /opt/postal/bin/postal bundle /opt/postal/vendor/bundle
## Move config folder ## Move config folder
RUN mv /opt/postal/config /opt/postal/config-original RUN mv /opt/postal/config /opt/postal/config-original
## Stick in startup script ## Stick in required files
ADD scripts/start.sh /start.sh ADD wrapper.sh /wrapper.sh
## Expose ## Expose
EXPOSE 5000 EXPOSE 5000
## Startup ## Startup
CMD ["/start.sh"] ENTRYPOINT ["/bin/bash", "-c", "/wrapper.sh ${*}", "--"]

View File

@ -4,15 +4,25 @@
Change configuration in docker-compose.yml to update passwords for MySQL/RabbitMQ. 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. 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 docker-compose up -d
``` ```
### Using the `postal` tool.
To use the `postal` tool, simply run
```
docker-compose run postal <parameter>
```
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 ### Migrations
See https://github.com/atech/postal/wiki/Upgrading.
### 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
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. 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.

View File

@ -1,3 +0,0 @@
web_server:
bind_address: 0.0.0.0

View File

@ -4,9 +4,13 @@ services:
build: . build: .
image: postal image: postal
container_name: postal container_name: postal
command: run
ports: ports:
- 80:5000 - 127.0.0.1:80:5000
- 25:2525 - 127.0.0.1:25:2525
depends_on:
- "mysql"
- "rabbitmq"
volumes: volumes:
- ./data/postal:/opt/postal/config - ./data/postal:/opt/postal/config
- ./data/docker:/docker - ./data/docker:/docker

View File

@ -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