Merge pull request #219 from jtr860830/master

Fix docker-compose start up order
This commit is contained in:
jagadeeshv16 2019-03-28 19:15:27 +05:30 committed by GitHub
commit da0513a7c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View file

@ -7,11 +7,13 @@ COPY . /app/
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt update && \
apt install -y git ruby-dev nodejs && \
apt install -y git ruby-dev nodejs postgresql-client && \
apt clean && \
gem install compass sass && \
npm -g install less && \
pip install -r requirements.txt && \
pip install redis coveralls
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir redis
RUN chmod +x /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh \
/app/wait-for-postgres.sh
ENTRYPOINT ["/app/entrypoint.sh"]

6
db.env Normal file
View file

@ -0,0 +1,6 @@
# Database environment variables
POSTGRES_USER=postgres
POSTGRES_PASSWORD=root
POSTGRES_DB=dj_crm
DB_HOST=db
DB_PORT=5432

View file

@ -5,17 +5,14 @@ services:
image: postgres
# volumes:
# - /home/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: "root"
POSTGRES_USER: "postgres"
POSTGRES_DB: "dj_crm"
env_file:
- ./db.env
web:
build: .
image: micropyramid/django-crm:1
environment:
DB_HOST: db
DB_PORT: 5432
env_file:
- ./db.env
ports:
- "8001:8000"
depends_on:

View file

@ -1,6 +1,7 @@
#!/bin/bash
# Execute startup scripts
./wait-for-postgres.sh $DB_HOST
python manage.py collectstatic --noinput
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

18
wait-for-postgres.sh Normal file
View file

@ -0,0 +1,18 @@
#!/bin/bash
# wait-for-postgres.sh
set -e
host="$1"
shift
cmd="$@"
echo "Testing Postgres connection with psql ..."
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do
#~ >&2 echo "Postgres is unavailable - sleeping"
>&2 echo -n .
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd