Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
FROM phusion/baseimage
FROM python:3.7.1-alpine3.8

RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y python3 python-pip python3-dev libpq-dev postgresql-client
RUN apt-get install -y libssl-dev
RUN apt-get install build-essential
RUN apk update && apk add postgresql-dev gcc musl-dev
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r /app/requirements.txt

ADD ./ /app/

WORKDIR /app/

RUN pip install -r requirements.txt
WORKDIR /app
5 changes: 2 additions & 3 deletions blog/blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost','0.0.0.0']


# Application definition
Expand All @@ -45,13 +45,12 @@
'events'
]

MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2'
version: '3'
services:
postgres_db:
image: postgres
Expand All @@ -13,5 +13,5 @@ services:
depends_on:
- postgres_db
- mongo_db
entrypoint: /app/docker/web/entrypoint.sh
privileged: true
command: sh "/app/docker/web/entrypoint.sh"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gogobook I am curious as to what this change achieves. In command you are executing the same file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it raise an error when I using "entrypoint" way, so I changed it to command.

# privileged: true
9 changes: 5 additions & 4 deletions docker/web/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

set -e

until psql -h "postgres_db" -U "postgres" -c '\l'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
# until psql -h "postgres_db" -U "postgres" -c '\l'; do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gogobook What is the reason for removing this ?

This makes sure that postgres is up and running before we run any migrations.

Copy link
Author

@gogobook gogobook Dec 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error in my trying, it raise 'Postgres is unavailable - sleeping', when comment these code, it will be fine.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and I am getting the error that postgres is not available. The Postgres check is required.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Run 'docker-compose restart web'. And 'web' container will start normally. The error message is 'Is the server running on host "postgres_db" (172.19.0.3) and accepting TCP/IP connections on port 5432?', and add "sleep 3" to entrypoint.sh can solve it. The 'psql' is not exist in 'web' container.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep 3 doesn't solve the problem, as it assumes that postgres will be up within 3 seconds. We can't make that assumption.

If psql is not available why don't you add it to Dockerfile ?

Docker docs themselves suggest to use this method.
Check the example in this https://docs.docker.com/compose/startup-order/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need psql, we have to install postgresql to web container, and I don't like this way. If we don't like 'sleep 3', maybe the better solution is 'wait-for' script, action like the example.

# >&2 echo "Postgres is unavailable - sleeping"
# sleep 1
# done


# Run python migrations
python blog/manage.py migrate
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
argcomplete==1.0.0
argcomplete
asd==1.3.2
Django==1.10
mongoengine==0.10.6
psycopg2==2.6.2
pymongo==3.3.0
voidpp-tools==1.8.1
Django==2.1.3
mongoengine==0.16.2
psycopg2-binary==2.7.6
pymongo==3.7.2
voidpp-tools==1.11.0
docker-compose