From 12027a5a808634c2dda1c52deb8622756bcc4980 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 15 Sep 2017 20:11:44 +0300 Subject: [PATCH] Fix things --- docker-compose.yml | 2 +- setup.sh | 17 ++++++++++---- sikweb/settings-sample.py | 39 ++++++++++++++++++++----------- .wait-for-it.sh => wait-for-it.sh | 0 4 files changed, 40 insertions(+), 18 deletions(-) rename .wait-for-it.sh => wait-for-it.sh (100%) diff --git a/docker-compose.yml b/docker-compose.yml index cf9ed4c..3f64c09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: web: build: . image: 86.50.143.82:5000/web20 - command: ["bash", "-c", "./.wait-for-it.sh db:5432 -- bash setup.py --no-input"] + command: ["bash", "-c", "cd /code && ./wait-for-it.sh db:5432 -- bash setup.sh --no-input --no-npm && python manage.py runserver 0.0.0.0:8080"] volumes: - .:/code ports: diff --git a/setup.sh b/setup.sh index 1e295e3..8f71754 100755 --- a/setup.sh +++ b/setup.sh @@ -6,10 +6,17 @@ echo "=========================================================" echo "Dependencies: postgresql>9.5, python>3.5" INTERACTIVE="true" +USE_NPM="true" if [[ $* == *--no-input* ]] then INTERACTIVE="false" fi +if [[ $* == *--no-npm* ]] +then + USE_NPM="false" +fi + +$INTERACTIVE || echo "Running in non-interactive mode." && env $INTERACTIVE && read -p "Are these programs installed? [y/n]" -n 1 -r || REPLY="y" echo "" @@ -56,11 +63,13 @@ then fi set -e -(set -x; pip install -r requirements.txt) -(set -x; npm install) -(set -x; python manage.py migrate) -(set -x; python manage.py createdefaultadmin) +set -x +pip install -r requirements.txt +$USE_NPM && npm install +python manage.py migrate +python manage.py createdefaultadmin set +e +set +x echo "Done." echo "Run 'python manage.py runserver 0.0.0.0:8000' to start the development server!" diff --git a/sikweb/settings-sample.py b/sikweb/settings-sample.py index a7fe312..e2fb412 100644 --- a/sikweb/settings-sample.py +++ b/sikweb/settings-sample.py @@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +IS_DOCKER = bool(os.getenv('IS_DOCKER', None)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ @@ -106,20 +107,32 @@ WSGI_APPLICATION = 'sikweb.wsgi.application' # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'sik', - 'USER': 'sik', - 'PASSWORD': 'password123', - 'HOST': 'localhost', - 'PORT': '5432', - 'TEST': { - 'NAME': 'sik_test', +if not IS_DOCKER: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'sik', + 'USER': 'sik', + 'PASSWORD': 'password123', + 'HOST': 'localhost', + 'PORT': '5432', + 'TEST': { + 'NAME': 'sik_test', + }, }, - }, -} - + } +else: + logging.info('Using docker database configuration') + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'postgres', + 'USER': 'postgres', + 'PASSWORD': 'postgres', + 'HOST': 'db', + 'PORT': '5432', + }, + } # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators diff --git a/.wait-for-it.sh b/wait-for-it.sh similarity index 100% rename from .wait-for-it.sh rename to wait-for-it.sh