diff --git a/alpine/Dockerfile b/alpine/Dockerfile index eb2ef23..8c4973e 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -1,9 +1,11 @@ FROM ruby:2.6-alpine +ENV DOCKERIZE_VERSION v0.6.1 + RUN wget https://github.com/wrouesnel/p2cli/releases/download/r5/p2 -O /usr/local/bin/p2 \ && chmod +x /usr/local/bin/p2 -RUN apk --no-cache add nodejs mariadb-client git bash libcap build-base mariadb-dev tzdata mariadb-connector-c \ +RUN apk --no-cache add nodejs mariadb-client git bash libcap build-base mariadb-dev tzdata mariadb-connector-c openssl \ && git clone https://github.com/atech/postal.git /opt/postal \ && rm -rf /var/lib/apt/lists/* \ && gem install bundler \ @@ -16,6 +18,11 @@ RUN apk --no-cache add nodejs mariadb-client git bash libcap build-base mariadb- && apk del git mariadb-dev \ && rm -rf /var/cache/apk/* +## Install jwilder/dockerize +RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz + ## Adjust permissions RUN setcap 'cap_net_bind_service=+ep' /usr/local/bin/ruby diff --git a/alpine/src/docker-entrypoint.sh b/alpine/src/docker-entrypoint.sh index c31cee2..d651426 100755 --- a/alpine/src/docker-entrypoint.sh +++ b/alpine/src/docker-entrypoint.sh @@ -13,14 +13,9 @@ if [ ! -f /opt/postal/config/postal.yml ] || [[ $(cat /opt/postal/config/postal. 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 + ## Wait for MySQL and RabbitMQ to start up + echo "== Waiting for MySQL and RabbitMQ to start up ==" + dockerize -wait tcp://mysql:3306 -wait http://rabbitmq:5672/api/aliveness-test /opt/postal/bin/postal initialize /opt/postal/bin/postal make-user <<-EOF $POSTAL_EMAIL @@ -29,14 +24,9 @@ $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 + ## Wait for MySQL and RabbitMQ to start up + echo "== Waiting for MySQL and RabbitMQ to start up ==" + dockerize -wait tcp://mysql:3306 -wait http://rabbitmq:5672/api/aliveness-test fi ## Start Postal /opt/postal/bin/postal "$@" diff --git a/ubuntu/Dockerfile b/ubuntu/Dockerfile index 4975d16..37a63dd 100644 --- a/ubuntu/Dockerfile +++ b/ubuntu/Dockerfile @@ -1,4 +1,5 @@ FROM ruby:2.6 + ENV DOCKERIZE_VERSION v0.6.1 RUN curl -L https://github.com/wrouesnel/p2cli/releases/download/r5/p2 -o /usr/local/bin/p2 \ @@ -21,6 +22,7 @@ RUN apt-get -y update \ && apt-get -y autoremove \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +## Install jwilder/dockerize RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz