diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4871d64..551d750 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ test-docker-alpine: - cd alpine - docker load -i postal-alpine-container.tar - docker-compose up -d - - docker-compose run postal initialize + - for i in {1..10}; do [ $(docker inspect postal | jq '.[].State.Health.Status') == "healthy" ] && break || sleep 30; done after_script: - cd alpine - docker-compose rm -sfv diff --git a/alpine/docker-compose.yml b/alpine/docker-compose.yml index 2dfcd48..7334403 100644 --- a/alpine/docker-compose.yml +++ b/alpine/docker-compose.yml @@ -19,6 +19,15 @@ services: - RABBITMQ_DEFAULT_USER=postal - RABBITMQ_DEFAULT_PASS=changeme - RABBITMQ_DEFAULT_VHOST=postal + - POSTAL_FNAME=Sia + - POSTAL_LNAME=Cat + - POSTAL_PASSWORD=SecretCatPassword + - POSTAL_EMAIL=myemail@catsworld.com + healthcheck: + test: curl -sS http://127.0.0.1:5000 || exit 1 + interval: 5s + timeout: 10s + retries: 3 mysql: image: mariadb:10 container_name: postal_mysql diff --git a/alpine/src/docker-entrypoint.sh b/alpine/src/docker-entrypoint.sh index e866ed0..c31cee2 100755 --- a/alpine/src/docker-entrypoint.sh +++ b/alpine/src/docker-entrypoint.sh @@ -1,25 +1,42 @@ #!/bin/bash -## Generate config -if [ ! -f /opt/postal/config/postal.yml ] || [[ $(cat /opt/postal/config/postal.yml | wc -l) < 2 ]]; then - ## Build Jinja2 Template - p2 -t /templates/postal.example.yml.j2 -o /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/* rm -rf /tmp/postal -## Wait for MySQL to start up -echo "== Waiting for MySQL to start up ==" -while ! mysqladmin ping -h mysql --silent; do - sleep 0.5 -done +## Generate config +if [ ! -f /opt/postal/config/postal.yml ] || [[ $(cat /opt/postal/config/postal.yml | wc -l) < 2 ]]; then + ## Build Jinja2 Template + p2 -t /templates/postal.example.yml.j2 -o /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 + ## Wait for MySQL to start up + echo "== Waiting for MySQL to start up ==" + while ! mysqladmin ping -h mysql --silent; do + sleep 0.5 + done + while ! mysql -hmysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "use $MYSQL_DATABASE" 2> /dev/null; do + sleep 0.5 + done + /opt/postal/bin/postal initialize + /opt/postal/bin/postal make-user <<-EOF +$POSTAL_EMAIL +$POSTAL_FNAME +$POSTAL_LNAME +$POSTAL_PASSWORD +EOF +else + ## Wait for MySQL to start up + echo "== Waiting for MySQL to start up ==" + while ! mysqladmin ping -h mysql --silent; do + sleep 0.5 + done + while ! mysql -hmysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "use $MYSQL_DATABASE" 2> /dev/null; do + sleep 0.5 + done +fi ## Start Postal /opt/postal/bin/postal "$@"