Skip to content

Commit

Permalink
Merge pull request #1 from illuin-tech/add-wait-for-db
Browse files Browse the repository at this point in the history
add wait for database
  • Loading branch information
Jrmyy authored Feb 10, 2020
2 parents 7e6c886 + 492d0d7 commit 35049df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ WORKDIR /luigi
COPY . /luigi

RUN apt-get update -y && \
apt-get install -y build-essential libpq-dev python3-dev python-dev && \
apt-get install -y \
build-essential \
libpq-dev \
python3-dev \
python-dev \
wait-for-it \
&& \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
pip install -r /luigi/requirements.txt

RUN chmod +x /luigi/entrypoint.sh
RUN chmod +x /luigi/docker-start.sh

ENTRYPOINT [ "/luigi/entrypoint.sh" ]
CMD [ "/luigi/docker-start.sh" ]
24 changes: 24 additions & 0 deletions docker-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e

function wait_for_it {
HOST=$1
PORT=$2
TIMEOUT=$3
until wait-for-it --host=${HOST} --port=${PORT} --timeout=${TIMEOUT} --quiet; do
>&2 echo "Connection not available on ${HOST}:${PORT} - waiting ${TIMEOUT} seconds"
done
echo "Connection is available on ${HOST}:${PORT}."
}

if (echo ${luigi_database_url} | grep -Eq ^.+\:\/\/.+\:.+\@.+\:[0-9]+\/.*$); then
# DATABASE_URI is in prot://user:pass@host:port/db format
HOST=$(echo ${luigi_database_url} | cut -d@ -f2 | cut -d/ -f1 | cut -d: -f1)
PORT=$(echo ${luigi_database_url} | cut -d@ -f2 | cut -d/ -f1 | cut -d: -f2)
TIMEOUT=5

wait_for_it ${HOST} ${PORT} ${TIMEOUT}
fi

echo "Starting luigi"
luigid
3 changes: 2 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -e

j2 /luigi/luigi.cfg.j2 > luigi.cfg

luigid
exec "$@"

0 comments on commit 35049df

Please sign in to comment.