diff --git a/Dockerfile b/Dockerfile index 53985fa..da871e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,10 @@ COPY root / # Note: Tweak this line if you're running anything other than x86 AMD64 (64-bit). RUN curl -L -s https://github.com/just-containers/s6-overlay/releases/download/v1.19.1.1/s6-overlay-amd64.tar.gz | tar xvzf - -C / +# Add wait-for-it.sh +ADD https://raw.githubusercontent.com/Eficode/wait-for/master/wait-for /srv +RUN chmod 755 /srv/wait-for + # Expose Nginx ports. EXPOSE 8080 EXPOSE 4443 diff --git a/root/etc/cont-init.d/98-wait-for-db b/root/etc/cont-init.d/98-wait-for-db new file mode 100644 index 0000000..ee6774a --- /dev/null +++ b/root/etc/cont-init.d/98-wait-for-db @@ -0,0 +1,28 @@ +#!/usr/bin/with-contenv sh + +# Wait for the DB to be reachable before proceeding. This avoids race condition +# whereby database is not ready (yet), and so TTRSS config isn't correctly created + +############# +# This simply duplicates the logic from ttrss-configure-db.php +ename='DB'; +eport=5432; + +if [ '$DB_TYPE' = 'mysql' ]; +then + eport=3306; + dbhost=$DB_PORT_3306_TCP_ADDR +else + eport=5432; + dbhost=$DB_PORT_5432_TCP_ADDR +fi +############# + +# Run wait-for to confirm DB comes up before we proceed +# Reduce default timeout to 1s because if the DB is not instantly available, +# Then it's even if it _happens_ to become available while we're testing, +# it won't be ready for us yet. Better to exit and restart the container altogether, +# So set "S6_BEHAVIOUR_IF_STAGE2_FAILS=2" in docker-compose.yml if you need this (i.e., in swarm mode, where dependencies don't work) + +echo "Checking database responds within 1s on $dbhost:$eport..." +/srv/wait-for $dbhost:$eport --timeout=1 diff --git a/root/srv/setup-ttrss.sh b/root/srv/setup-ttrss.sh index 7364fb4..619fd56 100755 --- a/root/srv/setup-ttrss.sh +++ b/root/srv/setup-ttrss.sh @@ -43,19 +43,25 @@ setup_nginx() setup_ttrss() { - TTRSS_PATH=/var/www/ttrss + if [ -z "$TTRSS_REPO" ]; then + TTRSS_HOST=https://git.tt-rss.org/git/tt-rss.git + fi + if [ -z "$TTRSS_PATH" ]; then + TTRSS_PATH=/var/www/ttrss + fi + if [ ! -d ${TTRSS_PATH} ]; then mkdir -p ${TTRSS_PATH} if [ -n "$TTRSS_GIT_TAG" ]; then echo "Setup: Setting up Tiny Tiny RSS '$TTRSS_GIT_TAG' ..." cd ${TTRSS_PATH} git init . - git fetch --depth=1 https://tt-rss.org/gitlab/fox/tt-rss.git refs/tags/${TTRSS_GIT_TAG}:refs/tags/${TTRSS_GIT_TAG} - git checkout tags/${TTRSS_GIT_TAG} + git fetch --depth=1 $TTRSS_REPO refs/tags/${TTRSS_GIT_TAG}:refs/tags/${TTRSS_GIT_TAG} + git checkout tags/${TTRSS_GIT_TAG} else echo "Setup: Setting up Tiny Tiny RSS (latest revision) ..." - git clone --depth=1 https://tt-rss.org/gitlab/fox/tt-rss.git ${TTRSS_PATH} + git clone --depth=1 $TTRSS_REPO ${TTRSS_PATH} fi git clone --depth=1 https://github.com/sepich/tt-rss-mobilize.git ${TTRSS_PATH}/plugins/mobilize git clone --depth=1 https://github.com/hrk/tt-rss-newsplus-plugin.git ${TTRSS_PATH}/plugins/api_newsplus @@ -97,9 +103,13 @@ setup_ttrss() TTRSS_PORT=:8080 fi fi - - # Construct the final URL TTRSS will use. - TTRSS_SELF_URL=${TTRSS_PROTO}://${TTRSS_URL}${TTRSS_PORT}/ + + # If we've been passed $TTRSS_SELF_URL as an env variable, then use that, + # otherwise use the URL we constructed above. + if [ -z "$TTRSS_SELF_URL" ]; then + # Construct the final URL TTRSS will use. + TTRSS_SELF_URL=${TTRSS_PROTO}://${TTRSS_URL}${TTRSS_PORT}/ + fi echo "Setup: URL is: $TTRSS_SELF_URL"