Skip to content

Commit

Permalink
Merge pull request #46 from noisy/wait_script_for_docker
Browse files Browse the repository at this point in the history
Wait script for docker
  • Loading branch information
noisy authored Jul 6, 2016
2 parents 81d8b76 + 80013c9 commit 763c5ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compose/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.5

ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y cron rsyslog
RUN apt-get update && apt-get install -y cron rsyslog netcat

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements /requirements
Expand All @@ -16,6 +16,7 @@ RUN chown -R django /app
COPY ./compose/django/gunicorn.sh /gunicorn.sh
COPY ./compose/django/entrypoint.sh /entrypoint.sh
COPY ./compose/django/cron.sh /cron.sh
COPY ./compose/wait_to_start.sh /wait_to_start.sh
RUN sed -i 's/\r//' /entrypoint.sh
RUN sed -i 's/\r//' /gunicorn.sh
RUN sed -i 's/\r//' /cron.sh
Expand Down
7 changes: 6 additions & 1 deletion compose/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ services:
links:
- postgres
- redis
command: /gunicorn.sh
command: /wait_to_start.sh
network_mode: 'bridge'
env_file: ../.env
environment:
- WAIT_COMMAND=nc -z postgres 5432
- WAIT_START_CMD=/gunicorn.sh
- WAIT_SLEEP=2
- WAIT_LOOPS=20

django-chroniker:
build:
Expand Down
24 changes: 24 additions & 0 deletions compose/wait_to_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo $WAIT_COMMAND
echo $WAIT_START_CMD

is_ready() {
eval "$WAIT_COMMAND"
[[ $? -eq 0 ]]
}

# wait until is ready
i=0
while ! is_ready; do
i=`expr $i + 1`
if [ $i -ge $WAIT_LOOPS ]; then
echo "$(date) - still not ready, giving up"
exit 1
fi
echo "$(date) - waiting to be ready"
sleep $WAIT_SLEEP
done

#start the script
exec $WAIT_START_CMD 2>&1 | tee -a /logs

0 comments on commit 763c5ce

Please sign in to comment.