Browse Source

wait for db's tcp port to become available before initializing koel
(fixes high-frequency container restart loop);
koel src now in submodule

Fabian Peter Hammerle 5 years ago
parent
commit
adb573b057
5 changed files with 17 additions and 7 deletions
  1. 3 0
      .gitmodules
  2. 4 6
      Dockerfile
  3. 1 1
      docker-compose.yml
  4. 1 0
      koel
  5. 8 0
      run-koel.sh

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "koel"]
+	path = koel
+	url = https://github.com/phanan/koel/

+ 4 - 6
Dockerfile

@@ -2,12 +2,9 @@ FROM composer:1.7 as php-build
 RUN apk add git
 RUN adduser -S dev
 RUN mkdir /koel && chown dev /koel
+COPY --chown=dev:nogroup ./koel /koel
 WORKDIR /koel
 USER dev
-ENV KOEL_VERSION 3.7.2
-RUN git clone --recurse-submodules --quiet \
-    --branch "v${KOEL_VERSION}" \
-    https://github.com/phanan/koel .
 RUN composer install --no-interaction
 
 FROM node:8.12.0-alpine as js-build
@@ -29,7 +26,8 @@ RUN find / -xdev -type f -perm /u+s -exec chmod --changes u-s {} \; \
 # zlib1g-dev: required by zip module
 RUN apt-get update && apt-get install --yes \
     libpq-dev \
-    zlib1g-dev
+    zlib1g-dev \
+    netcat
 RUN docker-php-ext-install -j$(nproc) \
     exif \
     pdo_pgsql \
@@ -41,7 +39,7 @@ RUN chmod o+r /etc/apache2/apache2.conf
 EXPOSE 8080
 # https://github.com/docker-library/docs/blob/master/php/README.md
 RUN mv $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
-COPY --from=js-build /koel /koel
+COPY --from=js-build --chown=root:www-data /koel /koel
 WORKDIR /koel
 RUN chown --changes --recursive www-data .env storage/
 COPY ./run-koel.sh /

+ 1 - 1
docker-compose.yml

@@ -21,7 +21,7 @@ services:
       test: echo 'SELECT 1' | psql --username koel --dbname koel || exit 1
     restart: unless-stopped
   web:
-    image: fphammerle/koel:3.7.2-amd64
+    image: fphammerle/koel:3.7.2-wait-amd64
     environment:
       DB_CONNECTION: pgsql
       DB_HOST: db

+ 1 - 0
koel

@@ -0,0 +1 @@
+Subproject commit cd67609c9ef70bb3d0cc5c62a6ee88f0ee7e1f94

+ 8 - 0
run-koel.sh

@@ -4,6 +4,14 @@ if [ "$(id -u)" = "0" ]; then
     exit 1
 fi
 
+if [ ! -z "$DB_HOST" ] && [ ! -z "$DB_PORT" ]; then
+    while : ; do
+        nc -z "$DB_HOST" "$DB_PORT" && break
+        echo waiting for db at "$DB_HOST":"$DB_PORT"
+        sleep 5
+    done
+fi
+
 set -x
 
 # TODO run non-interactively