From bb63f19de33925a3eb7ca5af31fdeb43d2ad680e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Mon, 19 Jun 2017 20:18:37 +0200 Subject: [PATCH 01/46] creating Dockerfile, .dockerignore and docket-compose --- .dockerignore | 10 ++++++++++ Dockerfile | 14 ++++++++++++++ docker-compose.yml | 14 ++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2bd7b91 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.github/ +.vscode/ +env/ +logs/ +.coverage +.coveragerc +.gitignore +.pylintrc +.travis.yml + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..171fa65 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Start with a python 3 image +FROM python:3 +ENV PYTHONUNBUFFERED 1 + +# Creates src folder in container +RUN mkdir /src +# Makes src dir the working directory +WORKDIR /src + +# Install requirements +ADD requirements.txt /src/ +RUN pip install -r requirements.txt + +ADD . /src/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..44a6615 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + db: + image: postgres + backend: + build: . + command: python3 manage.py runserver 0.0.0.0:8000 + volumes: + - .:/src + ports: + - "8000:8000" + depends_on: + - db \ No newline at end of file From 789dc6309a5a78b33d9797075fb16c2dca1d2866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Mon, 19 Jun 2017 22:37:46 +0200 Subject: [PATCH 02/46] put everything in an src folder. Dockerfile can now migrate --- Dockerfile | 16 +++++++++++----- README.md | 13 +++++++++++++ docker-compose.yml | 15 +++++++++++---- {case_gather => src/case_gather}/__init__.py | 0 {case_gather => src/case_gather}/admin.py | 0 {case_gather => src/case_gather}/apps.py | 0 {case_gather => src/case_gather}/cron_jobs.py | 0 .../case_gather}/migrations/0001_initial.py | 0 .../migrations/0002_auto_20170428_1922.py | 0 .../case_gather}/migrations/__init__.py | 0 {case_gather => src/case_gather}/models.py | 0 {case_gather => src/case_gather}/serializers.py | 0 {case_gather => src/case_gather}/services.py | 0 .../case_gather}/test_data/case3details.txt | 0 .../case_gather}/test_data/casedetails.txt | 0 .../case_gather}/test_data/caselist.txt | 0 {case_gather => src/case_gather}/tests.py | 0 {case_gather => src/case_gather}/views.py | 0 {case_gather => src/case_gather}/xml_helper.py | 0 {case_gather => src/case_gather}/xml_parser.py | 0 {district => src/district}/__init__.py | 0 {district => src/district}/admin.py | 0 {district => src/district}/apps.py | 0 .../district}/migrations/0001_initial.py | 0 .../district}/migrations/__init__.py | 0 {district => src/district}/models.py | 0 {district => src/district}/serializers.py | 0 {district => src/district}/tests.py | 0 {district => src/district}/views.py | 0 {main => src/main}/__init__.py | 0 {main => src/main}/admin.py | 0 {main => src/main}/apps.py | 0 {main => src/main}/migrations/__init__.py | 0 {main => src/main}/models.py | 0 manage.py => src/manage.py | 0 {parliament => src/parliament}/__init__.py | 0 {parliament => src/parliament}/admin.py | 0 {parliament => src/parliament}/apps.py | 0 .../parliament}/migrations/0001_initial.py | 0 .../migrations/0002_parliamentmember.py | 0 .../parliament}/migrations/__init__.py | 0 {parliament => src/parliament}/models.py | 0 {parliament => src/parliament}/serializers.py | 0 {parliament => src/parliament}/tests.py | 0 {parliament => src/parliament}/views.py | 0 {party => src/party}/__init__.py | 0 {party => src/party}/admin.py | 0 {party => src/party}/apps.py | 0 {party => src/party}/migrations/0001_initial.py | 0 {party => src/party}/migrations/__init__.py | 0 {party => src/party}/models.py | 0 {party => src/party}/serializers.py | 0 {party => src/party}/tests.py | 0 {party => src/party}/views.py | 0 .../politech_backend}/__init__.py | 0 .../politech_backend}/settings.py | 4 ++-- .../politech_backend}/urls.py | 0 .../politech_backend}/wsgi.py | 0 {promises => src/promises}/__init__.py | 0 {promises => src/promises}/admin.py | 0 {promises => src/promises}/apps.py | 0 {promises => src/promises}/cronjobs.py | 0 .../promises}/migrations/0001_initial.py | 0 .../migrations/0002_auto_20170523_1933.py | 0 .../migrations/0003_auto_20170523_1944.py | 0 .../promises}/migrations/__init__.py | 0 {promises => src/promises}/models.py | 0 {promises => src/promises}/serializers.py | 0 {promises => src/promises}/services.py | 0 {promises => src/promises}/tests.py | 0 {promises => src/promises}/views.py | 0 {subjects => src/subjects}/__init__.py | 0 {subjects => src/subjects}/admin.py | 0 {subjects => src/subjects}/apps.py | 0 .../subjects}/migrations/0001_initial.py | 0 .../subjects}/migrations/__init__.py | 0 {subjects => src/subjects}/models.py | 0 {subjects => src/subjects}/serializers.py | 0 {subjects => src/subjects}/tests.py | 0 {subjects => src/subjects}/views.py | 0 80 files changed, 37 insertions(+), 11 deletions(-) rename {case_gather => src/case_gather}/__init__.py (100%) rename {case_gather => src/case_gather}/admin.py (100%) rename {case_gather => src/case_gather}/apps.py (100%) rename {case_gather => src/case_gather}/cron_jobs.py (100%) rename {case_gather => src/case_gather}/migrations/0001_initial.py (100%) rename {case_gather => src/case_gather}/migrations/0002_auto_20170428_1922.py (100%) rename {case_gather => src/case_gather}/migrations/__init__.py (100%) rename {case_gather => src/case_gather}/models.py (100%) rename {case_gather => src/case_gather}/serializers.py (100%) rename {case_gather => src/case_gather}/services.py (100%) rename {case_gather => src/case_gather}/test_data/case3details.txt (100%) rename {case_gather => src/case_gather}/test_data/casedetails.txt (100%) rename {case_gather => src/case_gather}/test_data/caselist.txt (100%) rename {case_gather => src/case_gather}/tests.py (100%) rename {case_gather => src/case_gather}/views.py (100%) rename {case_gather => src/case_gather}/xml_helper.py (100%) rename {case_gather => src/case_gather}/xml_parser.py (100%) rename {district => src/district}/__init__.py (100%) rename {district => src/district}/admin.py (100%) rename {district => src/district}/apps.py (100%) rename {district => src/district}/migrations/0001_initial.py (100%) rename {district => src/district}/migrations/__init__.py (100%) rename {district => src/district}/models.py (100%) rename {district => src/district}/serializers.py (100%) rename {district => src/district}/tests.py (100%) rename {district => src/district}/views.py (100%) rename {main => src/main}/__init__.py (100%) rename {main => src/main}/admin.py (100%) rename {main => src/main}/apps.py (100%) rename {main => src/main}/migrations/__init__.py (100%) rename {main => src/main}/models.py (100%) rename manage.py => src/manage.py (100%) rename {parliament => src/parliament}/__init__.py (100%) rename {parliament => src/parliament}/admin.py (100%) rename {parliament => src/parliament}/apps.py (100%) rename {parliament => src/parliament}/migrations/0001_initial.py (100%) rename {parliament => src/parliament}/migrations/0002_parliamentmember.py (100%) rename {parliament => src/parliament}/migrations/__init__.py (100%) rename {parliament => src/parliament}/models.py (100%) rename {parliament => src/parliament}/serializers.py (100%) rename {parliament => src/parliament}/tests.py (100%) rename {parliament => src/parliament}/views.py (100%) rename {party => src/party}/__init__.py (100%) rename {party => src/party}/admin.py (100%) rename {party => src/party}/apps.py (100%) rename {party => src/party}/migrations/0001_initial.py (100%) rename {party => src/party}/migrations/__init__.py (100%) rename {party => src/party}/models.py (100%) rename {party => src/party}/serializers.py (100%) rename {party => src/party}/tests.py (100%) rename {party => src/party}/views.py (100%) rename {politech_backend => src/politech_backend}/__init__.py (100%) rename {politech_backend => src/politech_backend}/settings.py (99%) rename {politech_backend => src/politech_backend}/urls.py (100%) rename {politech_backend => src/politech_backend}/wsgi.py (100%) rename {promises => src/promises}/__init__.py (100%) rename {promises => src/promises}/admin.py (100%) rename {promises => src/promises}/apps.py (100%) rename {promises => src/promises}/cronjobs.py (100%) rename {promises => src/promises}/migrations/0001_initial.py (100%) rename {promises => src/promises}/migrations/0002_auto_20170523_1933.py (100%) rename {promises => src/promises}/migrations/0003_auto_20170523_1944.py (100%) rename {promises => src/promises}/migrations/__init__.py (100%) rename {promises => src/promises}/models.py (100%) rename {promises => src/promises}/serializers.py (100%) rename {promises => src/promises}/services.py (100%) rename {promises => src/promises}/tests.py (100%) rename {promises => src/promises}/views.py (100%) rename {subjects => src/subjects}/__init__.py (100%) rename {subjects => src/subjects}/admin.py (100%) rename {subjects => src/subjects}/apps.py (100%) rename {subjects => src/subjects}/migrations/0001_initial.py (100%) rename {subjects => src/subjects}/migrations/__init__.py (100%) rename {subjects => src/subjects}/models.py (100%) rename {subjects => src/subjects}/serializers.py (100%) rename {subjects => src/subjects}/tests.py (100%) rename {subjects => src/subjects}/views.py (100%) diff --git a/Dockerfile b/Dockerfile index 171fa65..4cba6a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,18 @@ FROM python:3 ENV PYTHONUNBUFFERED 1 # Creates src folder in container -RUN mkdir /src +RUN mkdir /code + +# Copy contents of the /src directory into the /code directory of the container +ADD /src /code/ +# Add requirements.txt to code directory +ADD requirements.txt /code/ + # Makes src dir the working directory -WORKDIR /src +WORKDIR /code # Install requirements -ADD requirements.txt /src/ -RUN pip install -r requirements.txt +RUN pip install -r /code/requirements.txt -ADD . /src/ \ No newline at end of file +CMD ["python", "src/manage.py", "migrate"] +CMD ["python", "src/manage.py", "runserver"] \ No newline at end of file diff --git a/README.md b/README.md index e18d230..a8867df 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,16 @@ After adding a new model or making a change in the model you should 2. Add cronscript. For Ari on Ubuntu this worked: `SHELL=/bin/bash */5 * * * * cd home/path/to/project/directory source env/bin/activate && python manage.py runcrons 3. Write correct path + +# Docker +Recommended to read about Dockerfiles and docker-compose. Its required to install docker-compose. + +To build backend +```bash +$ docker-compose build +``` + +To run backend +```bash +$ docker-compose run backend +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 44a6615..9ad8cf4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,21 @@ version: '3' services: + nginx: + image: nginx:latest + db: - image: postgres + image: postgres:latest + backend: build: . - command: python3 manage.py runserver 0.0.0.0:8000 + environment: + - DB_USER=postgres + - DB_PASS=pass volumes: - - .:/src + - .:/code ports: - "8000:8000" depends_on: - - db \ No newline at end of file + - db + - nginx \ No newline at end of file diff --git a/case_gather/__init__.py b/src/case_gather/__init__.py similarity index 100% rename from case_gather/__init__.py rename to src/case_gather/__init__.py diff --git a/case_gather/admin.py b/src/case_gather/admin.py similarity index 100% rename from case_gather/admin.py rename to src/case_gather/admin.py diff --git a/case_gather/apps.py b/src/case_gather/apps.py similarity index 100% rename from case_gather/apps.py rename to src/case_gather/apps.py diff --git a/case_gather/cron_jobs.py b/src/case_gather/cron_jobs.py similarity index 100% rename from case_gather/cron_jobs.py rename to src/case_gather/cron_jobs.py diff --git a/case_gather/migrations/0001_initial.py b/src/case_gather/migrations/0001_initial.py similarity index 100% rename from case_gather/migrations/0001_initial.py rename to src/case_gather/migrations/0001_initial.py diff --git a/case_gather/migrations/0002_auto_20170428_1922.py b/src/case_gather/migrations/0002_auto_20170428_1922.py similarity index 100% rename from case_gather/migrations/0002_auto_20170428_1922.py rename to src/case_gather/migrations/0002_auto_20170428_1922.py diff --git a/case_gather/migrations/__init__.py b/src/case_gather/migrations/__init__.py similarity index 100% rename from case_gather/migrations/__init__.py rename to src/case_gather/migrations/__init__.py diff --git a/case_gather/models.py b/src/case_gather/models.py similarity index 100% rename from case_gather/models.py rename to src/case_gather/models.py diff --git a/case_gather/serializers.py b/src/case_gather/serializers.py similarity index 100% rename from case_gather/serializers.py rename to src/case_gather/serializers.py diff --git a/case_gather/services.py b/src/case_gather/services.py similarity index 100% rename from case_gather/services.py rename to src/case_gather/services.py diff --git a/case_gather/test_data/case3details.txt b/src/case_gather/test_data/case3details.txt similarity index 100% rename from case_gather/test_data/case3details.txt rename to src/case_gather/test_data/case3details.txt diff --git a/case_gather/test_data/casedetails.txt b/src/case_gather/test_data/casedetails.txt similarity index 100% rename from case_gather/test_data/casedetails.txt rename to src/case_gather/test_data/casedetails.txt diff --git a/case_gather/test_data/caselist.txt b/src/case_gather/test_data/caselist.txt similarity index 100% rename from case_gather/test_data/caselist.txt rename to src/case_gather/test_data/caselist.txt diff --git a/case_gather/tests.py b/src/case_gather/tests.py similarity index 100% rename from case_gather/tests.py rename to src/case_gather/tests.py diff --git a/case_gather/views.py b/src/case_gather/views.py similarity index 100% rename from case_gather/views.py rename to src/case_gather/views.py diff --git a/case_gather/xml_helper.py b/src/case_gather/xml_helper.py similarity index 100% rename from case_gather/xml_helper.py rename to src/case_gather/xml_helper.py diff --git a/case_gather/xml_parser.py b/src/case_gather/xml_parser.py similarity index 100% rename from case_gather/xml_parser.py rename to src/case_gather/xml_parser.py diff --git a/district/__init__.py b/src/district/__init__.py similarity index 100% rename from district/__init__.py rename to src/district/__init__.py diff --git a/district/admin.py b/src/district/admin.py similarity index 100% rename from district/admin.py rename to src/district/admin.py diff --git a/district/apps.py b/src/district/apps.py similarity index 100% rename from district/apps.py rename to src/district/apps.py diff --git a/district/migrations/0001_initial.py b/src/district/migrations/0001_initial.py similarity index 100% rename from district/migrations/0001_initial.py rename to src/district/migrations/0001_initial.py diff --git a/district/migrations/__init__.py b/src/district/migrations/__init__.py similarity index 100% rename from district/migrations/__init__.py rename to src/district/migrations/__init__.py diff --git a/district/models.py b/src/district/models.py similarity index 100% rename from district/models.py rename to src/district/models.py diff --git a/district/serializers.py b/src/district/serializers.py similarity index 100% rename from district/serializers.py rename to src/district/serializers.py diff --git a/district/tests.py b/src/district/tests.py similarity index 100% rename from district/tests.py rename to src/district/tests.py diff --git a/district/views.py b/src/district/views.py similarity index 100% rename from district/views.py rename to src/district/views.py diff --git a/main/__init__.py b/src/main/__init__.py similarity index 100% rename from main/__init__.py rename to src/main/__init__.py diff --git a/main/admin.py b/src/main/admin.py similarity index 100% rename from main/admin.py rename to src/main/admin.py diff --git a/main/apps.py b/src/main/apps.py similarity index 100% rename from main/apps.py rename to src/main/apps.py diff --git a/main/migrations/__init__.py b/src/main/migrations/__init__.py similarity index 100% rename from main/migrations/__init__.py rename to src/main/migrations/__init__.py diff --git a/main/models.py b/src/main/models.py similarity index 100% rename from main/models.py rename to src/main/models.py diff --git a/manage.py b/src/manage.py similarity index 100% rename from manage.py rename to src/manage.py diff --git a/parliament/__init__.py b/src/parliament/__init__.py similarity index 100% rename from parliament/__init__.py rename to src/parliament/__init__.py diff --git a/parliament/admin.py b/src/parliament/admin.py similarity index 100% rename from parliament/admin.py rename to src/parliament/admin.py diff --git a/parliament/apps.py b/src/parliament/apps.py similarity index 100% rename from parliament/apps.py rename to src/parliament/apps.py diff --git a/parliament/migrations/0001_initial.py b/src/parliament/migrations/0001_initial.py similarity index 100% rename from parliament/migrations/0001_initial.py rename to src/parliament/migrations/0001_initial.py diff --git a/parliament/migrations/0002_parliamentmember.py b/src/parliament/migrations/0002_parliamentmember.py similarity index 100% rename from parliament/migrations/0002_parliamentmember.py rename to src/parliament/migrations/0002_parliamentmember.py diff --git a/parliament/migrations/__init__.py b/src/parliament/migrations/__init__.py similarity index 100% rename from parliament/migrations/__init__.py rename to src/parliament/migrations/__init__.py diff --git a/parliament/models.py b/src/parliament/models.py similarity index 100% rename from parliament/models.py rename to src/parliament/models.py diff --git a/parliament/serializers.py b/src/parliament/serializers.py similarity index 100% rename from parliament/serializers.py rename to src/parliament/serializers.py diff --git a/parliament/tests.py b/src/parliament/tests.py similarity index 100% rename from parliament/tests.py rename to src/parliament/tests.py diff --git a/parliament/views.py b/src/parliament/views.py similarity index 100% rename from parliament/views.py rename to src/parliament/views.py diff --git a/party/__init__.py b/src/party/__init__.py similarity index 100% rename from party/__init__.py rename to src/party/__init__.py diff --git a/party/admin.py b/src/party/admin.py similarity index 100% rename from party/admin.py rename to src/party/admin.py diff --git a/party/apps.py b/src/party/apps.py similarity index 100% rename from party/apps.py rename to src/party/apps.py diff --git a/party/migrations/0001_initial.py b/src/party/migrations/0001_initial.py similarity index 100% rename from party/migrations/0001_initial.py rename to src/party/migrations/0001_initial.py diff --git a/party/migrations/__init__.py b/src/party/migrations/__init__.py similarity index 100% rename from party/migrations/__init__.py rename to src/party/migrations/__init__.py diff --git a/party/models.py b/src/party/models.py similarity index 100% rename from party/models.py rename to src/party/models.py diff --git a/party/serializers.py b/src/party/serializers.py similarity index 100% rename from party/serializers.py rename to src/party/serializers.py diff --git a/party/tests.py b/src/party/tests.py similarity index 100% rename from party/tests.py rename to src/party/tests.py diff --git a/party/views.py b/src/party/views.py similarity index 100% rename from party/views.py rename to src/party/views.py diff --git a/politech_backend/__init__.py b/src/politech_backend/__init__.py similarity index 100% rename from politech_backend/__init__.py rename to src/politech_backend/__init__.py diff --git a/politech_backend/settings.py b/src/politech_backend/settings.py similarity index 99% rename from politech_backend/settings.py rename to src/politech_backend/settings.py index a3068bf..b492e53 100644 --- a/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -121,10 +121,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'politech', + 'NAME': 'postgres', 'USER': os.environ["DB_USER"], 'PASSWORD': os.environ["DB_PASS"], - 'HOST': '127.0.0.1', + 'HOST': 'db', #'127.0.0.1', 'PORT': '5432', 'ATOMIC_REQUESTS': True } diff --git a/politech_backend/urls.py b/src/politech_backend/urls.py similarity index 100% rename from politech_backend/urls.py rename to src/politech_backend/urls.py diff --git a/politech_backend/wsgi.py b/src/politech_backend/wsgi.py similarity index 100% rename from politech_backend/wsgi.py rename to src/politech_backend/wsgi.py diff --git a/promises/__init__.py b/src/promises/__init__.py similarity index 100% rename from promises/__init__.py rename to src/promises/__init__.py diff --git a/promises/admin.py b/src/promises/admin.py similarity index 100% rename from promises/admin.py rename to src/promises/admin.py diff --git a/promises/apps.py b/src/promises/apps.py similarity index 100% rename from promises/apps.py rename to src/promises/apps.py diff --git a/promises/cronjobs.py b/src/promises/cronjobs.py similarity index 100% rename from promises/cronjobs.py rename to src/promises/cronjobs.py diff --git a/promises/migrations/0001_initial.py b/src/promises/migrations/0001_initial.py similarity index 100% rename from promises/migrations/0001_initial.py rename to src/promises/migrations/0001_initial.py diff --git a/promises/migrations/0002_auto_20170523_1933.py b/src/promises/migrations/0002_auto_20170523_1933.py similarity index 100% rename from promises/migrations/0002_auto_20170523_1933.py rename to src/promises/migrations/0002_auto_20170523_1933.py diff --git a/promises/migrations/0003_auto_20170523_1944.py b/src/promises/migrations/0003_auto_20170523_1944.py similarity index 100% rename from promises/migrations/0003_auto_20170523_1944.py rename to src/promises/migrations/0003_auto_20170523_1944.py diff --git a/promises/migrations/__init__.py b/src/promises/migrations/__init__.py similarity index 100% rename from promises/migrations/__init__.py rename to src/promises/migrations/__init__.py diff --git a/promises/models.py b/src/promises/models.py similarity index 100% rename from promises/models.py rename to src/promises/models.py diff --git a/promises/serializers.py b/src/promises/serializers.py similarity index 100% rename from promises/serializers.py rename to src/promises/serializers.py diff --git a/promises/services.py b/src/promises/services.py similarity index 100% rename from promises/services.py rename to src/promises/services.py diff --git a/promises/tests.py b/src/promises/tests.py similarity index 100% rename from promises/tests.py rename to src/promises/tests.py diff --git a/promises/views.py b/src/promises/views.py similarity index 100% rename from promises/views.py rename to src/promises/views.py diff --git a/subjects/__init__.py b/src/subjects/__init__.py similarity index 100% rename from subjects/__init__.py rename to src/subjects/__init__.py diff --git a/subjects/admin.py b/src/subjects/admin.py similarity index 100% rename from subjects/admin.py rename to src/subjects/admin.py diff --git a/subjects/apps.py b/src/subjects/apps.py similarity index 100% rename from subjects/apps.py rename to src/subjects/apps.py diff --git a/subjects/migrations/0001_initial.py b/src/subjects/migrations/0001_initial.py similarity index 100% rename from subjects/migrations/0001_initial.py rename to src/subjects/migrations/0001_initial.py diff --git a/subjects/migrations/__init__.py b/src/subjects/migrations/__init__.py similarity index 100% rename from subjects/migrations/__init__.py rename to src/subjects/migrations/__init__.py diff --git a/subjects/models.py b/src/subjects/models.py similarity index 100% rename from subjects/models.py rename to src/subjects/models.py diff --git a/subjects/serializers.py b/src/subjects/serializers.py similarity index 100% rename from subjects/serializers.py rename to src/subjects/serializers.py diff --git a/subjects/tests.py b/src/subjects/tests.py similarity index 100% rename from subjects/tests.py rename to src/subjects/tests.py diff --git a/subjects/views.py b/src/subjects/views.py similarity index 100% rename from subjects/views.py rename to src/subjects/views.py From 6ca962588737caa364559d8de63bfd16de6f393c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Mon, 19 Jun 2017 22:47:32 +0200 Subject: [PATCH 03/46] Adding initial data. Removing nginx for now --- Dockerfile | 5 +++-- docker-compose.yml | 6 +----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4cba6a5..a71cb0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,6 @@ WORKDIR /code # Install requirements RUN pip install -r /code/requirements.txt -CMD ["python", "src/manage.py", "migrate"] -CMD ["python", "src/manage.py", "runserver"] \ No newline at end of file +CMD ["python3", "src/manage.py", "migrate"] +CMD ["python3", "src/manage.py", "loaddata", "init_data.json"] +CMD ["python3", "src/manage.py", "runserver"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9ad8cf4..2393b55 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,6 @@ version: '3' services: - nginx: - image: nginx:latest - db: image: postgres:latest @@ -17,5 +14,4 @@ services: ports: - "8000:8000" depends_on: - - db - - nginx \ No newline at end of file + - db \ No newline at end of file From 8550e7e679e209acbf2e60159f5d662130fb3487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Mon, 19 Jun 2017 23:03:51 +0200 Subject: [PATCH 04/46] Update docs with docker info --- Dockerfile | 1 - README.md | 14 ++++++-------- docker-compose.yml | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index a71cb0c..3929061 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,3 @@ RUN pip install -r /code/requirements.txt CMD ["python3", "src/manage.py", "migrate"] CMD ["python3", "src/manage.py", "loaddata", "init_data.json"] -CMD ["python3", "src/manage.py", "runserver"] \ No newline at end of file diff --git a/README.md b/README.md index a8867df..e0a6f27 100644 --- a/README.md +++ b/README.md @@ -82,15 +82,13 @@ After adding a new model or making a change in the model you should `SHELL=/bin/bash */5 * * * * cd home/path/to/project/directory source env/bin/activate && python manage.py runcrons 3. Write correct path -# Docker -Recommended to read about Dockerfiles and docker-compose. Its required to install docker-compose. +# Docker and docker-compose +Its required to install docker-compose first (here)[https://docs.docker.com/compose/install/] -To build backend +To start up backend and database ```bash -$ docker-compose build +$ docker-compose up ``` -To run backend -```bash -$ docker-compose run backend -``` \ No newline at end of file +After that visit localhost:8000 in a browser and see that Django is running + diff --git a/docker-compose.yml b/docker-compose.yml index 2393b55..96a6423 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: environment: - DB_USER=postgres - DB_PASS=pass + command: python3 src/manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: From 2bee9889de58de20a388d8abadf8adaf9a2f68ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 11:11:53 +0200 Subject: [PATCH 05/46] Backend is now just an docker image. Compose should be in another repo. Added a little bit of documentation for docker in readme --- Dockerfile | 12 ++++++------ README.md | 18 ++++++++++++++++++ docker-compose.yml | 18 ------------------ src/politech_backend/settings.py | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 3929061..a80364d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,16 +5,16 @@ ENV PYTHONUNBUFFERED 1 # Creates src folder in container RUN mkdir /code -# Copy contents of the /src directory into the /code directory of the container -ADD /src /code/ -# Add requirements.txt to code directory -ADD requirements.txt /code/ +# Copy everything into the /code directory of the container +ADD . /code/ # Makes src dir the working directory WORKDIR /code # Install requirements RUN pip install -r /code/requirements.txt +#RUN python3 src/manage.py migrate -CMD ["python3", "src/manage.py", "migrate"] -CMD ["python3", "src/manage.py", "loaddata", "init_data.json"] +#CMD ["python3", "src/manage.py", "migrate"] +#CMD ["python3", "src/manage.py", "loaddata", "init_data.json"] +#CMD ["python3", "src/manage.py", "runserver"] diff --git a/README.md b/README.md index e0a6f27..e293eb1 100644 --- a/README.md +++ b/README.md @@ -92,3 +92,21 @@ $ docker-compose up After that visit localhost:8000 in a browser and see that Django is running +## Docker commands +### Build image +``` +docker build -t arihrannar/veritus-backend . +``` +###Login to docker cloud +``` +docker login +``` + +###Push image to docker cloud +``` +docker push : +``` +Example: +``` +docker push arihrannar/veritus-backend:latest +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 96a6423..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: '3' - -services: - db: - image: postgres:latest - - backend: - build: . - environment: - - DB_USER=postgres - - DB_PASS=pass - command: python3 src/manage.py runserver 0.0.0.0:8000 - volumes: - - .:/code - ports: - - "8000:8000" - depends_on: - - db \ No newline at end of file diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index b492e53..1aa0acf 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # Application definition From 10c48a90bf2358198256622c00aebc9fcb47c617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 11:57:42 +0200 Subject: [PATCH 06/46] improved readme --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e293eb1..38eea25 100644 --- a/README.md +++ b/README.md @@ -82,15 +82,8 @@ After adding a new model or making a change in the model you should `SHELL=/bin/bash */5 * * * * cd home/path/to/project/directory source env/bin/activate && python manage.py runcrons 3. Write correct path -# Docker and docker-compose -Its required to install docker-compose first (here)[https://docs.docker.com/compose/install/] - -To start up backend and database -```bash -$ docker-compose up -``` - -After that visit localhost:8000 in a browser and see that Django is running +# Docker +The docker image here is NOT suppose to be run alone. As the backend requires a database, there is no use running it alone. See the docker-compose repository for how to run the backend and the whole stack. ## Docker commands ### Build image From 72003131a56209404b646382d51f06a31cf0c0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 14:17:39 +0200 Subject: [PATCH 07/46] image now runs linter. Added docker compose for running tests --- Dockerfile | 21 ++++++++++++--------- README.md | 1 + docker-compose.test.yml | 23 +++++++++++++++++++++++ .pylintrc => pylintrc | 8 +------- run-tests.sh | 3 +++ src/manage.py | 1 + src/politech_backend/settings.py | 2 +- 7 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 docker-compose.test.yml rename .pylintrc => pylintrc (63%) create mode 100644 run-tests.sh diff --git a/Dockerfile b/Dockerfile index a80364d..be70a1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,23 @@ -# Start with a python 3 image -FROM python:3 -ENV PYTHONUNBUFFERED 1 +# Start with a python 3.6 image +FROM python:3.6 +ENV PYTHONUNBUFFERED 1 +ENV DB_USER postgres +ENV DB_PASS pass # Creates src folder in container RUN mkdir /code # Copy everything into the /code directory of the container ADD . /code/ -# Makes src dir the working directory +# Makes code dir the working directory +# and we change directory into it WORKDIR /code # Install requirements -RUN pip install -r /code/requirements.txt -#RUN python3 src/manage.py migrate +RUN pip install -r requirements.txt + +# Run linter +RUN pylint **/*.py + -#CMD ["python3", "src/manage.py", "migrate"] -#CMD ["python3", "src/manage.py", "loaddata", "init_data.json"] -#CMD ["python3", "src/manage.py", "runserver"] diff --git a/README.md b/README.md index 38eea25..d00a908 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ docker build -t arihrannar/veritus-backend . ``` docker login ``` +Input credentials. ###Push image to docker cloud ``` diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..481b767 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,23 @@ +sut: + build: . + command: run_tests.sh + depends_on: + - postgres + - backend + +services: + postgres: + image: postgres:9.6.3 + environment: + - POSTGRES_PASSWORD=${DB_PASS} + + backend: + image: arihrannar/veritus-backend:latest + environment: + - DB_USER=${DB_USER} + - DB_PASS=${DB_PASS} + command: python3 src/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - postgres diff --git a/.pylintrc b/pylintrc similarity index 63% rename from .pylintrc rename to pylintrc index 1544dde..06596a3 100644 --- a/.pylintrc +++ b/pylintrc @@ -1,5 +1,5 @@ [MASTER] -ignore=apps.py, admin, migrations, bin, lib, man +ignore=manage.py, apps.py, admin.py, migrations, env load-plugins=pylint_django [MESSAGES CONTROL] @@ -7,9 +7,3 @@ disable=missing-docstring, broad-except, bare-except, no-self-use, invalid-name, [TYPECHECK] ignored-classes=WSGIRequest, Exception, Client - - -[pre-commit-hook] -command=custom_pylint -params=--rcfile=/path/to/another/pylint.rc -limit=8.0 diff --git a/run-tests.sh b/run-tests.sh new file mode 100644 index 0000000..27e58bc --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,3 @@ +#!bin/bash + +python3 src/manage.py test \ No newline at end of file diff --git a/src/manage.py b/src/manage.py index 996e025..f1d23aa 100755 --- a/src/manage.py +++ b/src/manage.py @@ -13,6 +13,7 @@ # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: + # pylint: disable=unused-import import django except ImportError: raise ImportError( diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index 1aa0acf..921a9de 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -124,7 +124,7 @@ 'NAME': 'postgres', 'USER': os.environ["DB_USER"], 'PASSWORD': os.environ["DB_PASS"], - 'HOST': 'db', #'127.0.0.1', + 'HOST': 'postgres', #'127.0.0.1', 'PORT': '5432', 'ATOMIC_REQUESTS': True } From 2edc0de24530b2d736ea0526c56553d2877d1790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 14:36:19 +0200 Subject: [PATCH 08/46] only have postgres service in docker compose test --- docker-compose.test.yml | 24 ++++++------------------ run-tests.sh | 3 --- 2 files changed, 6 insertions(+), 21 deletions(-) delete mode 100644 run-tests.sh diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 481b767..86229e1 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,23 +1,11 @@ sut: build: . - command: run_tests.sh + command: python3 src/manage.py test depends_on: - postgres - - backend -services: - postgres: - image: postgres:9.6.3 - environment: - - POSTGRES_PASSWORD=${DB_PASS} - - backend: - image: arihrannar/veritus-backend:latest - environment: - - DB_USER=${DB_USER} - - DB_PASS=${DB_PASS} - command: python3 src/manage.py runserver 0.0.0.0:8000 - ports: - - "8000:8000" - depends_on: - - postgres +postgres: + image: postgres:9.6.3 + environment: + - POSTGRES_PASSWORD=pass + diff --git a/run-tests.sh b/run-tests.sh deleted file mode 100644 index 27e58bc..0000000 --- a/run-tests.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!bin/bash - -python3 src/manage.py test \ No newline at end of file From d751c30cb24e06a6dfd3e41982f2f5e570582033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 15:07:04 +0200 Subject: [PATCH 09/46] adding db host env variable. Adding services to docker-compose test file --- Dockerfile | 3 +-- docker-compose.test.yml | 24 +++++++++++++++++++----- src/politech_backend/settings.py | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index be70a1a..00fa358 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,7 @@ FROM python:3.6 ENV PYTHONUNBUFFERED 1 -ENV DB_USER postgres -ENV DB_PASS pass + # Creates src folder in container RUN mkdir /code diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 86229e1..435d414 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,11 +1,25 @@ +version: '3' + sut: build: . command: python3 src/manage.py test depends_on: - postgres + - backend -postgres: - image: postgres:9.6.3 - environment: - - POSTGRES_PASSWORD=pass - +services: + postgres: + image: postgres:9.6.3 + environment: + - POSTGRES_PASSWORD=pass + + backend: + image: arihrannar/veritus-backend:latest + environment: + - DB_USER=postgres + - DB_PASS=pass + - DB_HOST=postgres + ports: + - "8000:8000" + depends_on: + - postgres diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index 921a9de..12b7768 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -124,7 +124,7 @@ 'NAME': 'postgres', 'USER': os.environ["DB_USER"], 'PASSWORD': os.environ["DB_PASS"], - 'HOST': 'postgres', #'127.0.0.1', + 'HOST': os.environ["DB_HOST"], #f.x. 'postgres' OR '127.0.0.1', 'PORT': '5432', 'ATOMIC_REQUESTS': True } From 5edba51434455dcf7dfebd41556c4786c0a8b337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 15:13:17 +0200 Subject: [PATCH 10/46] trying docker-compose-test without sut --- docker-compose.test.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 435d414..511c08d 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,12 +1,5 @@ version: '3' -sut: - build: . - command: python3 src/manage.py test - depends_on: - - postgres - - backend - services: postgres: image: postgres:9.6.3 @@ -14,7 +7,8 @@ services: - POSTGRES_PASSWORD=pass backend: - image: arihrannar/veritus-backend:latest + build: . + command: python3 src/manage.py test environment: - DB_USER=postgres - DB_PASS=pass From 7dd7cf3a54cb240760452f9a1c7dc4beae7b6c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 15:22:13 +0200 Subject: [PATCH 11/46] adding sut instead of backend in docker-compose-test --- docker-compose.test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 511c08d..0bd0fc6 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -6,14 +6,14 @@ services: environment: - POSTGRES_PASSWORD=pass - backend: + sut: build: . command: python3 src/manage.py test environment: - DB_USER=postgres - DB_PASS=pass - DB_HOST=postgres - ports: - - "8000:8000" + #ports: + # - "8000:8000" depends_on: - postgres From 36731e3e7bf0b543a11cc632b7f657ab41f25834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 15:35:49 +0200 Subject: [PATCH 12/46] renaming database to db instead of postgres as that is what its called in the postgres image --- docker-compose.test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 0bd0fc6..e1a7aaa 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,7 +1,7 @@ version: '3' services: - postgres: + db: image: postgres:9.6.3 environment: - POSTGRES_PASSWORD=pass @@ -12,8 +12,8 @@ services: environment: - DB_USER=postgres - DB_PASS=pass - - DB_HOST=postgres + - DB_HOST=db #ports: # - "8000:8000" depends_on: - - postgres + - db From 3901d64777f27d679072fdbd0995f3f6a4570cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 15:51:24 +0200 Subject: [PATCH 13/46] Adding env variables to docker cloud and removing them from repo --- README.md | 4 ++-- src/politech_backend/settings.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d00a908..737bc2c 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ The docker image here is NOT suppose to be run alone. As the backend requires a ## Docker commands ### Build image ``` -docker build -t arihrannar/veritus-backend . +docker build -t veritus/backend . ``` ###Login to docker cloud ``` @@ -102,5 +102,5 @@ docker push : ``` Example: ``` -docker push arihrannar/veritus-backend:latest +docker push veritus/backend:latest ``` \ No newline at end of file diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index 12b7768..bffede4 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -122,9 +122,9 @@ 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', - 'USER': os.environ["DB_USER"], - 'PASSWORD': os.environ["DB_PASS"], - 'HOST': os.environ["DB_HOST"], #f.x. 'postgres' OR '127.0.0.1', + 'USER': os.environ["POSTGRES_USER"], + 'PASSWORD': os.environ["POSTGRES_PASSWORD"], + 'HOST': os.environ["DB_HOST"], #f.x. 'db' OR '127.0.0.1', 'PORT': '5432', 'ATOMIC_REQUESTS': True } From 7872c6c967aad7f80e01c003141d7a8587cbd6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 16:04:56 +0200 Subject: [PATCH 14/46] Adding env variables to docker-compose.test --- docker-compose.test.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index e1a7aaa..fdd6342 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,16 +4,14 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_PASSWORD=pass + - POSTGRES_PASSWORD={$POSTGRES_PASSWORD} sut: build: . command: python3 src/manage.py test environment: - - DB_USER=postgres - - DB_PASS=pass - - DB_HOST=db - #ports: - # - "8000:8000" + - POSTGRES_USER={$POSTGRES_USER} + - POSTGRES_PASSWORD={$POSTGRES_PASSWORD} + - DB_HOST={$DB_HOST} depends_on: - db From 68247f62c55e5c7a934d9af56d015f21495611b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 16:16:17 +0200 Subject: [PATCH 15/46] removing curley brackets in env variables --- docker-compose.test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index fdd6342..50b2551 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,14 +4,14 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_PASSWORD={$POSTGRES_PASSWORD} + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD sut: build: . command: python3 src/manage.py test environment: - - POSTGRES_USER={$POSTGRES_USER} - - POSTGRES_PASSWORD={$POSTGRES_PASSWORD} - - DB_HOST={$DB_HOST} + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - DB_HOST=$DB_HOST depends_on: - db From 69bad91e31b47a5797545b7a4c04114ebb644eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 16:31:47 +0200 Subject: [PATCH 16/46] db host doesnt need to be a environment variable in docker. It should always be the name of the service --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 50b2551..82da18d 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -12,6 +12,6 @@ services: environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - - DB_HOST=$DB_HOST + - DB_HOST=db depends_on: - db From c06483361331efd002be6740d8b27b1414c1da57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 16:40:51 +0200 Subject: [PATCH 17/46] try host postgres --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 82da18d..cae3ccb 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -12,6 +12,6 @@ services: environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - - DB_HOST=db + - DB_HOST=postgres depends_on: - db From 3de7d9b22fa3dd08afc7e94cae55782262256d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 16:54:49 +0200 Subject: [PATCH 18/46] trying to add port to db service as it does not seem to be found --- docker-compose.test.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index cae3ccb..6f3876a 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,14 +4,16 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + ports: + - "5432:5432" + sut: build: . command: python3 src/manage.py test environment: - - POSTGRES_USER=$POSTGRES_USER - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - - DB_HOST=postgres + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - DB_HOST=db depends_on: - db From c4b0080da357a7848891c89b9c6c7b61ab417ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 17:11:51 +0200 Subject: [PATCH 19/46] trying a script to wait for postgres to be ready before running tests --- docker-compose.test.yml | 4 +++- wait-for-postgres.sh | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 wait-for-postgres.sh diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 6f3876a..27d57f1 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -10,10 +10,12 @@ services: sut: build: . - command: python3 src/manage.py test + command: ["./wait-for-postgres.sh", "db", "python3", "src/manage.py", "test"] environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - DB_HOST=db depends_on: - db + links: + - db diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh new file mode 100644 index 0000000..20dae81 --- /dev/null +++ b/wait-for-postgres.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# wait-for-postgres.sh + +set -e + +host="$1" +shift +cmd="$@" + +until psql -h "$host" -U "postgres" -c '\l'; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 1 +done + +>&2 echo "Postgres is up - executing command" +exec $cmd \ No newline at end of file From 879388d56572df7e289ca8ba48b92c8599e27437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 17:19:19 +0200 Subject: [PATCH 20/46] chmod on wait-for-postgres so it can be run in the CI --- wait-for-postgres.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 wait-for-postgres.sh diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh old mode 100644 new mode 100755 From 77b5bdabfacd3108f23007707441ec6f7bdcd7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 19:07:59 +0200 Subject: [PATCH 21/46] deleting wait for postgres as taht did not help. --- docker-compose.test.yml | 13 +++++-------- wait-for-postgres.sh | 16 ---------------- 2 files changed, 5 insertions(+), 24 deletions(-) delete mode 100755 wait-for-postgres.sh diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 27d57f1..dccd751 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,18 +4,15 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - ports: - - "5432:5432" + - POSTGRES_USER=postgres #$POSTGRES_USER + - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD sut: build: . - command: ["./wait-for-postgres.sh", "db", "python3", "src/manage.py", "test"] + command: python3 src/manage.py test environment: - - POSTGRES_USER=$POSTGRES_USER - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - POSTGRES_USER=postgres #$POSTGRES_USER + - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD - DB_HOST=db depends_on: - db - links: - - db diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh deleted file mode 100755 index 20dae81..0000000 --- a/wait-for-postgres.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# wait-for-postgres.sh - -set -e - -host="$1" -shift -cmd="$@" - -until psql -h "$host" -U "postgres" -c '\l'; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 -done - ->&2 echo "Postgres is up - executing command" -exec $cmd \ No newline at end of file From f0069f97cd7a3981f9cfa3f1bbbcb312487fb557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 19:29:56 +0200 Subject: [PATCH 22/46] Adding links to docker-compose.test.yml --- docker-compose.test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index dccd751..c13e4f2 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -16,3 +16,5 @@ services: - DB_HOST=db depends_on: - db + links: + - db From 48fdadcba0ffd450f3678dc21022413b7a013847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 19:45:18 +0200 Subject: [PATCH 23/46] lets try version 3.2 --- docker-compose.test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c13e4f2..1099d8a 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,4 +1,4 @@ -version: '3' +version: '3.2' services: db: @@ -16,5 +16,3 @@ services: - DB_HOST=db depends_on: - db - links: - - db From a05f828a5490c8f4e83ff2052aa4cf0f67df28c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 20:33:05 +0200 Subject: [PATCH 24/46] introducing environment variables again --- docker-compose.test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 1099d8a..566412b 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,15 +4,15 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_USER=postgres #$POSTGRES_USER - - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD sut: build: . command: python3 src/manage.py test environment: - - POSTGRES_USER=postgres #$POSTGRES_USER - - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - DB_HOST=db depends_on: - db From 3ae3f09e714ae43a05afc5c5bb2c7373ce1c7f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 20:53:46 +0200 Subject: [PATCH 25/46] Adding healthcheck to postgres container for docker-compose.test --- docker-compose.test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 566412b..256284d 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -6,6 +6,11 @@ services: environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + healthcheck: + test: ["CMD-SHELL", "psql -h 'db' -U 'postgres' -c '\\l'"] + interval: 30s + timeout: 30s + retries: 3 sut: build: . @@ -16,3 +21,4 @@ services: - DB_HOST=db depends_on: - db + condition: service_healthy From 7d5ca40c03eefe60f4f9390d1a61a860547367a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 20:56:08 +0200 Subject: [PATCH 26/46] removing condition in depends on as it doesnt fit with docker-compose version --- docker-compose.test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 256284d..223f1a5 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -21,4 +21,3 @@ services: - DB_HOST=db depends_on: - db - condition: service_healthy From 2a87c47fc833e3eb791b4a1971195b9ed007059a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 21:14:37 +0200 Subject: [PATCH 27/46] lets try wait for it again --- docker-compose.test.yml | 7 +------ wait-for-postgres.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100755 wait-for-postgres.sh diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 223f1a5..fb25b44 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -6,15 +6,10 @@ services: environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - healthcheck: - test: ["CMD-SHELL", "psql -h 'db' -U 'postgres' -c '\\l'"] - interval: 30s - timeout: 30s - retries: 3 sut: build: . - command: python3 src/manage.py test + command: command: ["./wait-for-postgres.sh", "db:5432", "python3", "src/manage.py", "test"] environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh new file mode 100755 index 0000000..e5342bd --- /dev/null +++ b/wait-for-postgres.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# wait-for-postgres.sh + +set -e + +host="$1" +shift +cmd="$@" + +until psql -h "$host" -U "postgres" -c '\l'; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 10 +done + +>&2 echo "Postgres is up - executing command" +exec $cmd \ No newline at end of file From ffe80ce22d660128f63f658bce9fcc1fa1983aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sat, 24 Jun 2017 21:26:06 +0200 Subject: [PATCH 28/46] removing access command --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index fb25b44..dbd61b6 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -9,7 +9,7 @@ services: sut: build: . - command: command: ["./wait-for-postgres.sh", "db:5432", "python3", "src/manage.py", "test"] + command: ["./wait-for-postgres.sh", "db:5432", "python3", "src/manage.py", "test"] environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD From 76632b397c962b779506f010397425c1b5f90e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 11:21:55 +0200 Subject: [PATCH 29/46] lets try python instead of python3 --- Dockerfile | 2 +- docker-compose.test.yml | 10 +++++----- src/politech_backend/settings.py | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00fa358..77fa8b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,4 +19,4 @@ RUN pip install -r requirements.txt # Run linter RUN pylint **/*.py - +# RUN python3 src/manage.py test diff --git a/docker-compose.test.yml b/docker-compose.test.yml index dbd61b6..397e33b 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,15 +4,15 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_USER=$POSTGRES_USER - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - POSTGRES_USER=postgres #$POSTGRES_USER + - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD sut: build: . - command: ["./wait-for-postgres.sh", "db:5432", "python3", "src/manage.py", "test"] + command: python src/manage.py test environment: - - POSTGRES_USER=$POSTGRES_USER - - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - POSTGRES_USER=postgres #$POSTGRES_USER + - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD - DB_HOST=db depends_on: - db diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index bffede4..c5c7dd7 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -126,7 +126,10 @@ 'PASSWORD': os.environ["POSTGRES_PASSWORD"], 'HOST': os.environ["DB_HOST"], #f.x. 'db' OR '127.0.0.1', 'PORT': '5432', - 'ATOMIC_REQUESTS': True + 'ATOMIC_REQUESTS': True, + 'OPTIONS': { + 'client_encoding': 'UTF8', + } } } From 768eca15ad65687dd9444310efe6254cff710f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 12:15:42 +0200 Subject: [PATCH 30/46] moving text execution into script --- Dockerfile | 3 +++ docker-compose.test.yml | 2 +- wait-for-postgres.sh | 14 +------------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77fa8b7..a7feccc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,9 @@ FROM python:3.6 ENV PYTHONUNBUFFERED 1 +ENV POSTGRES_USER postgres +ENV POSTGRES_PASSWORD pass +ENV DB_HOST db # Creates src folder in container RUN mkdir /code diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 397e33b..b4dc2f2 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -9,7 +9,7 @@ services: sut: build: . - command: python src/manage.py test + command: ./wait-for-postgres.sh environment: - POSTGRES_USER=postgres #$POSTGRES_USER - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh index e5342bd..1439f0e 100755 --- a/wait-for-postgres.sh +++ b/wait-for-postgres.sh @@ -1,16 +1,4 @@ #!/bin/bash # wait-for-postgres.sh -set -e - -host="$1" -shift -cmd="$@" - -until psql -h "$host" -U "postgres" -c '\l'; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 10 -done - ->&2 echo "Postgres is up - executing command" -exec $cmd \ No newline at end of file +exec python src/manage.py test \ No newline at end of file From 61997a9af8a9bfa5cc8a66a30069a7f62317c99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 13:45:38 +0200 Subject: [PATCH 31/46] debug more in script --- Dockerfile | 2 +- wait-for-postgres.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a7feccc..debf359 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,4 +22,4 @@ RUN pip install -r requirements.txt # Run linter RUN pylint **/*.py -# RUN python3 src/manage.py test +#RUN python3 src/manage.py test diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh index 1439f0e..a6d373a 100755 --- a/wait-for-postgres.sh +++ b/wait-for-postgres.sh @@ -1,4 +1,6 @@ #!/bin/bash # wait-for-postgres.sh +(echo >/dev/tcp/db/5432) &>/dev/null && echo "DB Open" || echo "DB Close" + exec python src/manage.py test \ No newline at end of file From 5ee4422408e966d524d4f5b5a1562b1011931999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 15:50:30 +0200 Subject: [PATCH 32/46] lets try version 2.1 with healthheck! --- Dockerfile | 2 +- docker-compose.test.yml | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index debf359..a7feccc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,4 +22,4 @@ RUN pip install -r requirements.txt # Run linter RUN pylint **/*.py -#RUN python3 src/manage.py test +# RUN python3 src/manage.py test diff --git a/docker-compose.test.yml b/docker-compose.test.yml index b4dc2f2..c6c419b 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,4 +1,4 @@ -version: '3.2' +version: '2.1' services: db: @@ -6,6 +6,11 @@ services: environment: - POSTGRES_USER=postgres #$POSTGRES_USER - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD + healthcheck: + test: ["CMD-SHELL", "psql -h 'localhost' -U 'postgres' -c '\\l'"] + interval: 30s + timeout: 30s + retries: 3 sut: build: . @@ -15,4 +20,6 @@ services: - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD - DB_HOST=db depends_on: - - db + db: + condition: service_healthy + From 094e1b2366eda76b38268732151905864de34dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 15:59:54 +0200 Subject: [PATCH 33/46] Introducing env variables again for username and password for db --- docker-compose.test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c6c419b..92ef168 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -4,8 +4,8 @@ services: db: image: postgres:9.6.3 environment: - - POSTGRES_USER=postgres #$POSTGRES_USER - - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD healthcheck: test: ["CMD-SHELL", "psql -h 'localhost' -U 'postgres' -c '\\l'"] interval: 30s @@ -16,8 +16,8 @@ services: build: . command: ./wait-for-postgres.sh environment: - - POSTGRES_USER=postgres #$POSTGRES_USER - - POSTGRES_PASSWORD=pass #$POSTGRES_PASSWORD + - POSTGRES_USER=$POSTGRES_USER + - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - DB_HOST=db depends_on: db: From 1ba075c59520fe6861ba32679aea4ec8ea0731db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 16:08:01 +0200 Subject: [PATCH 34/46] Removing unneeded env variales in dockerfile. Replacing script with just command in docker-compose --- Dockerfile | 5 ----- docker-compose.test.yml | 2 +- wait-for-postgres.sh | 6 ------ 3 files changed, 1 insertion(+), 12 deletions(-) delete mode 100755 wait-for-postgres.sh diff --git a/Dockerfile b/Dockerfile index a7feccc..41697c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,6 @@ FROM python:3.6 ENV PYTHONUNBUFFERED 1 -ENV POSTGRES_USER postgres -ENV POSTGRES_PASSWORD pass -ENV DB_HOST db # Creates src folder in container RUN mkdir /code @@ -21,5 +18,3 @@ RUN pip install -r requirements.txt # Run linter RUN pylint **/*.py - -# RUN python3 src/manage.py test diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 92ef168..4c8dfba 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -14,7 +14,7 @@ services: sut: build: . - command: ./wait-for-postgres.sh + command: python src/manage.py test environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD diff --git a/wait-for-postgres.sh b/wait-for-postgres.sh deleted file mode 100755 index a6d373a..0000000 --- a/wait-for-postgres.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# wait-for-postgres.sh - -(echo >/dev/tcp/db/5432) &>/dev/null && echo "DB Open" || echo "DB Close" - -exec python src/manage.py test \ No newline at end of file From b2ec4ada8b538b0a2bcd1d3c90c3b78eee70a602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 16:12:00 +0200 Subject: [PATCH 35/46] Adding some comments to explain things better --- Dockerfile | 1 - docker-compose.test.yml | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 41697c5..f569ee1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ # Start with a python 3.6 image FROM python:3.6 - ENV PYTHONUNBUFFERED 1 # Creates src folder in container diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 4c8dfba..01fe4f4 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,3 +1,5 @@ +# Docker-compose file for spinning up a database service and building the backend +# This allows the CI to run our unit tests against the database version: '2.1' services: From 3d955bbc7549e19d0912f1eef3954f78a65bd4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 16:15:22 +0200 Subject: [PATCH 36/46] use python3 instead of pythong --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 01fe4f4..6efed91 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -16,7 +16,7 @@ services: sut: build: . - command: python src/manage.py test + command: python3 src/manage.py test environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD From a7478cc0e8a97a0013bf933a55d1356d718ebf7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 16:22:33 +0200 Subject: [PATCH 37/46] removing travis as docker cloud CI has us covered --- .travis.yml | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 01d9548..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: python -python: - - "3.6" - -services: postgresql - -env: - - DJANGO=1.10.3 - -before_install: - - export DJANGO_SETTINGS_MODULE=politech_backend.settings - - export PYTHONPATH=$HOME/builds/AriHrannar/politech_backend - - export PIP_USE_MIRRORS=true - - export DB_USER=postgres - - export DB_PASS= - - -install: - - pip install -r requirements.txt - - pip install django==$DJANGO --quiet - - pip install psycopg2 --quiet - -before_script: - - psql -c "CREATE DATABASE politech;" -U postgres - -script: - - pylint */*.py - - python manage.py check - - pytest promises/tests.py - - python manage.py test - -notifications: - slack: polidevelopers:b2ilF8FkLWBCps2rGq0gOqjr - -after_success: - coveralls From b9317a83b6d3f9f01bdc92d12620e1d5d7331548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 16:33:57 +0200 Subject: [PATCH 38/46] Making the secret key into a env variable --- src/politech_backend/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index c5c7dd7..37c1741 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -20,7 +20,7 @@ # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 't8&(jop7)*h!v5eug$iufd8l1(l2dpfjxj=(+2xt5knv+7v-!=' +SECRET_KEY = os.environ["SECRET_KEY"] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True From d53396e9f5fb1d5333daf07bbaee6088925ac2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Sun, 25 Jun 2017 19:59:31 +0200 Subject: [PATCH 39/46] adding secret key as env variabl in build --- docker-compose.test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 6efed91..82e22f8 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -20,6 +20,7 @@ services: environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD + - SECRET_KEY=$SECRET_KEY - DB_HOST=db depends_on: db: From 6fe434d4cb59dc796ddcf456b1876387770ce810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Tue, 11 Jul 2017 20:10:04 +0200 Subject: [PATCH 40/46] adding migrate and loaddata to docker-compose test --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 82e22f8..8eb21bc 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -16,7 +16,7 @@ services: sut: build: . - command: python3 src/manage.py test + command: "bash -c 'python3 src/manage.py migrate && python3 src/manage.py loaddata init_data.json && python3 src/manage.py runserver 0.0.0.0:8000'" environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD From 9e967c8ec3083fa11ed364f05b9dba03ce6e6b95 Mon Sep 17 00:00:00 2001 From: ragnar Date: Tue, 11 Jul 2017 20:23:31 +0200 Subject: [PATCH 41/46] Removing migrations --- .../migrations/0002_auto_20170709_1708.py | 21 ------ .../migrations/0003_auto_20170709_1712.py | 21 ------ src/case_gather/migrations/0001_initial.py | 66 ------------------ .../migrations/0002_auto_20170428_1922.py | 44 ------------ src/district/migrations/0001_initial.py | 29 -------- src/parliament/migrations/0001_initial.py | 56 --------------- .../migrations/0002_parliamentmember.py | 34 ---------- src/party/migrations/0001_initial.py | 29 -------- src/politicians/migrations/0001_initial.py | 35 ---------- src/promises/migrations/0001_initial.py | 68 ------------------- .../migrations/0002_auto_20170523_1933.py | 28 -------- .../migrations/0003_auto_20170523_1944.py | 20 ------ src/subjects/migrations/0001_initial.py | 49 ------------- 13 files changed, 500 deletions(-) delete mode 100644 politicians/migrations/0002_auto_20170709_1708.py delete mode 100644 politicians/migrations/0003_auto_20170709_1712.py delete mode 100644 src/case_gather/migrations/0001_initial.py delete mode 100644 src/case_gather/migrations/0002_auto_20170428_1922.py delete mode 100644 src/district/migrations/0001_initial.py delete mode 100644 src/parliament/migrations/0001_initial.py delete mode 100644 src/parliament/migrations/0002_parliamentmember.py delete mode 100644 src/party/migrations/0001_initial.py delete mode 100644 src/politicians/migrations/0001_initial.py delete mode 100644 src/promises/migrations/0001_initial.py delete mode 100644 src/promises/migrations/0002_auto_20170523_1933.py delete mode 100644 src/promises/migrations/0003_auto_20170523_1944.py delete mode 100644 src/subjects/migrations/0001_initial.py diff --git a/politicians/migrations/0002_auto_20170709_1708.py b/politicians/migrations/0002_auto_20170709_1708.py deleted file mode 100644 index c164f6a..0000000 --- a/politicians/migrations/0002_auto_20170709_1708.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-07-09 17:08 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('politicians', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='politician', - name='district', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='district', to='district.District'), - ), - ] diff --git a/politicians/migrations/0003_auto_20170709_1712.py b/politicians/migrations/0003_auto_20170709_1712.py deleted file mode 100644 index 2b00df9..0000000 --- a/politicians/migrations/0003_auto_20170709_1712.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-07-09 17:12 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('politicians', '0002_auto_20170709_1708'), - ] - - operations = [ - migrations.AlterField( - model_name='politician', - name='district', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='politicians', to='district.District'), - ), - ] diff --git a/src/case_gather/migrations/0001_initial.py b/src/case_gather/migrations/0001_initial.py deleted file mode 100644 index 2663790..0000000 --- a/src/case_gather/migrations/0001_initial.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('parliament', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Bill', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('description_link', models.TextField()), - ('althingi_created', models.DateField()), - ('number', models.IntegerField()), - ('parliament_session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), - ], - options={ - 'abstract': False, - }, - ), - migrations.CreateModel( - name='Case', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('number', models.IntegerField()), - ('case_type', models.TextField()), - ('case_status', models.TextField()), - ('parliament_session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), - ], - options={ - 'abstract': False, - }, - ), - migrations.CreateModel( - name='Subject', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('number', models.IntegerField(blank=True, null=True)), - ('description', models.TextField(blank=True, null=True)), - ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), - ('parliament_session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/case_gather/migrations/0002_auto_20170428_1922.py b/src/case_gather/migrations/0002_auto_20170428_1922.py deleted file mode 100644 index 28e0cb1..0000000 --- a/src/case_gather/migrations/0002_auto_20170428_1922.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-04-28 19:22 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('case_gather', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='subject', - name='major_group_name', - ), - migrations.RemoveField( - model_name='subject', - name='major_group_number', - ), - migrations.AddField( - model_name='subject', - name='parent', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject'), - ), - migrations.AlterField( - model_name='subject', - name='description', - field=models.TextField(blank=True, null=True), - ), - migrations.AlterField( - model_name='subject', - name='number', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='subject', - name='parliament_session', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession'), - ), - ] diff --git a/src/district/migrations/0001_initial.py b/src/district/migrations/0001_initial.py deleted file mode 100644 index 41e2dff..0000000 --- a/src/district/migrations/0001_initial.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='District', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('abbreviation', models.TextField()), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/parliament/migrations/0001_initial.py b/src/parliament/migrations/0001_initial.py deleted file mode 100644 index d635545..0000000 --- a/src/parliament/migrations/0001_initial.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('politicians', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Parliament', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('start_date', models.DateField()), - ('end_date', models.DateField()), - ], - options={ - 'abstract': False, - }, - ), - migrations.CreateModel( - name='ParliamentMember', - fields=[ - ('politician_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='politicians.Politician')), - ], - options={ - 'abstract': False, - }, - bases=('politicians.politician',), - ), - migrations.CreateModel( - name='ParliamentSession', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('session_number', models.IntegerField()), - ('parliament', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.Parliament')), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/parliament/migrations/0002_parliamentmember.py b/src/parliament/migrations/0002_parliamentmember.py deleted file mode 100644 index 05cc65c..0000000 --- a/src/parliament/migrations/0002_parliamentmember.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-04-25 17:58 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('district', '0001_initial'), - ('party', '0001_initial'), - ('parliament', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='ParliamentMember', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('name', models.TextField()), - ('initials', models.TextField()), - ('districtNumber', models.IntegerField()), - ('district', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='district.District')), - ('party', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='party.Party')), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/party/migrations/0001_initial.py b/src/party/migrations/0001_initial.py deleted file mode 100644 index 06e3991..0000000 --- a/src/party/migrations/0001_initial.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Party', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('website', models.TextField()), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/politicians/migrations/0001_initial.py b/src/politicians/migrations/0001_initial.py deleted file mode 100644 index d2e675f..0000000 --- a/src/politicians/migrations/0001_initial.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('party', '0001_initial'), - ('district', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Politician', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('initials', models.TextField()), - ('districtNumber', models.IntegerField()), - ('district', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='district.District')), - ('party', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='party.Party')), - ], - options={ - 'abstract': False, - }, - ), - ] diff --git a/src/promises/migrations/0001_initial.py b/src/promises/migrations/0001_initial.py deleted file mode 100644 index 0d1b708..0000000 --- a/src/promises/migrations/0001_initial.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('parliament', '0001_initial'), - ('party', '0001_initial'), - ('case_gather', '0001_initial'), - ('politicians', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Promise', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('small_description', models.TextField()), - ('long_description', models.TextField()), - ('parliament', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.Parliament')), - ('party', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='party.Party')), - ('politician', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='promises', to='politicians.Politician')), - ], - options={ - 'abstract': False, - }, - ), - migrations.CreateModel( - name='PromiseCase', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), - ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), - ], - ), - migrations.CreateModel( - name='SuggestedPromiseCase', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), - ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), - ], - ), - migrations.AlterUniqueTogether( - name='suggestedpromisecase', - unique_together=set([('promise', 'case')]), - ), - migrations.AlterUniqueTogether( - name='promisecase', - unique_together=set([('promise', 'case')]), - ), - ] diff --git a/src/promises/migrations/0002_auto_20170523_1933.py b/src/promises/migrations/0002_auto_20170523_1933.py deleted file mode 100644 index 8636115..0000000 --- a/src/promises/migrations/0002_auto_20170523_1933.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-05-23 19:33 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('parliament', '0002_parliamentmember'), - ('party', '0001_initial'), - ('promises', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='promise', - name='parliamentMember', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentMember'), - ), - migrations.AddField( - model_name='promise', - name='party', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='party.Party'), - ), - ] diff --git a/src/promises/migrations/0003_auto_20170523_1944.py b/src/promises/migrations/0003_auto_20170523_1944.py deleted file mode 100644 index 1a6704b..0000000 --- a/src/promises/migrations/0003_auto_20170523_1944.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-05-23 19:44 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('promises', '0002_auto_20170523_1933'), - ] - - operations = [ - migrations.RenameField( - model_name='promise', - old_name='parliamentMember', - new_name='parliament_member', - ), - ] diff --git a/src/subjects/migrations/0001_initial.py b/src/subjects/migrations/0001_initial.py deleted file mode 100644 index 6a2a285..0000000 --- a/src/subjects/migrations/0001_initial.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.3 on 2017-06-06 19:17 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('promises', '0001_initial'), - ('case_gather', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='CaseSubject', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), - ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), - ], - ), - migrations.CreateModel( - name='PromiseSubject', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.TextField()), - ('created', models.DateTimeField(auto_now_add=True)), - ('modified', models.DateTimeField(auto_now=True)), - ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), - ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), - ], - ), - migrations.AlterUniqueTogether( - name='promisesubject', - unique_together=set([('promise', 'subject')]), - ), - migrations.AlterUniqueTogether( - name='casesubject', - unique_together=set([('case', 'subject')]), - ), - ] From 833dd170995ce53a6ca4d2ece71e9ee8043acbb9 Mon Sep 17 00:00:00 2001 From: ragnar Date: Tue, 11 Jul 2017 20:29:59 +0200 Subject: [PATCH 42/46] Correct migrations --- src/case_gather/migrations/0001_initial.py | 66 +++++++++++++++++++++ src/district/migrations/0001_initial.py | 29 +++++++++ src/parliament/migrations/0001_initial.py | 56 ++++++++++++++++++ src/party/migrations/0001_initial.py | 29 +++++++++ src/politicians/migrations/0001_initial.py | 35 +++++++++++ src/promises/migrations/0001_initial.py | 69 ++++++++++++++++++++++ src/subjects/migrations/0001_initial.py | 49 +++++++++++++++ 7 files changed, 333 insertions(+) create mode 100644 src/case_gather/migrations/0001_initial.py create mode 100644 src/district/migrations/0001_initial.py create mode 100644 src/parliament/migrations/0001_initial.py create mode 100644 src/party/migrations/0001_initial.py create mode 100644 src/politicians/migrations/0001_initial.py create mode 100644 src/promises/migrations/0001_initial.py create mode 100644 src/subjects/migrations/0001_initial.py diff --git a/src/case_gather/migrations/0001_initial.py b/src/case_gather/migrations/0001_initial.py new file mode 100644 index 0000000..e396a39 --- /dev/null +++ b/src/case_gather/migrations/0001_initial.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('parliament', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Bill', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('description_link', models.TextField()), + ('althingi_created', models.DateField()), + ('number', models.IntegerField()), + ('parliament_session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Case', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('number', models.IntegerField()), + ('case_type', models.TextField()), + ('case_status', models.TextField()), + ('parliament_session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Subject', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('number', models.IntegerField(blank=True, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), + ('parliament_session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='parliament.ParliamentSession')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/district/migrations/0001_initial.py b/src/district/migrations/0001_initial.py new file mode 100644 index 0000000..c0a1421 --- /dev/null +++ b/src/district/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='District', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('abbreviation', models.TextField()), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/parliament/migrations/0001_initial.py b/src/parliament/migrations/0001_initial.py new file mode 100644 index 0000000..51b7a30 --- /dev/null +++ b/src/parliament/migrations/0001_initial.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('politicians', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Parliament', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('start_date', models.DateField()), + ('end_date', models.DateField()), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='ParliamentMember', + fields=[ + ('politician_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='politicians.Politician')), + ], + options={ + 'abstract': False, + }, + bases=('politicians.politician',), + ), + migrations.CreateModel( + name='ParliamentSession', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('session_number', models.IntegerField()), + ('parliament', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.Parliament')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/party/migrations/0001_initial.py b/src/party/migrations/0001_initial.py new file mode 100644 index 0000000..ddf22a4 --- /dev/null +++ b/src/party/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Party', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('website', models.TextField()), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/politicians/migrations/0001_initial.py b/src/politicians/migrations/0001_initial.py new file mode 100644 index 0000000..25acc6c --- /dev/null +++ b/src/politicians/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('district', '0001_initial'), + ('party', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Politician', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('initials', models.TextField()), + ('districtNumber', models.IntegerField()), + ('district', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='politicians', to='district.District')), + ('party', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='party.Party')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/promises/migrations/0001_initial.py b/src/promises/migrations/0001_initial.py new file mode 100644 index 0000000..29be2ca --- /dev/null +++ b/src/promises/migrations/0001_initial.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('parliament', '0001_initial'), + ('politicians', '0001_initial'), + ('case_gather', '0001_initial'), + ('party', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Promise', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('fulfilled', models.BooleanField(default=False)), + ('small_description', models.TextField()), + ('long_description', models.TextField()), + ('parliament', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='parliament.Parliament')), + ('party', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='party.Party')), + ('politician', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='promises', to='politicians.Politician')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='PromiseCase', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), + ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), + ], + ), + migrations.CreateModel( + name='SuggestedPromiseCase', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), + ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), + ], + ), + migrations.AlterUniqueTogether( + name='suggestedpromisecase', + unique_together=set([('promise', 'case')]), + ), + migrations.AlterUniqueTogether( + name='promisecase', + unique_together=set([('promise', 'case')]), + ), + ] diff --git a/src/subjects/migrations/0001_initial.py b/src/subjects/migrations/0001_initial.py new file mode 100644 index 0000000..dc999ac --- /dev/null +++ b/src/subjects/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2017-07-11 18:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('promises', '0001_initial'), + ('case_gather', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='CaseSubject', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Case')), + ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), + ], + ), + migrations.CreateModel( + name='PromiseSubject', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('created', models.DateTimeField(auto_now_add=True)), + ('modified', models.DateTimeField(auto_now=True)), + ('promise', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='promises.Promise')), + ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='case_gather.Subject')), + ], + ), + migrations.AlterUniqueTogether( + name='promisesubject', + unique_together=set([('promise', 'subject')]), + ), + migrations.AlterUniqueTogether( + name='casesubject', + unique_together=set([('case', 'subject')]), + ), + ] From f7c2a0b1710fc459f8d698cca3d49c3bf7743a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Tue, 11 Jul 2017 20:39:45 +0200 Subject: [PATCH 43/46] replace runserver with test in testing compose --- docker-compose.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 8eb21bc..d581c70 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -16,7 +16,7 @@ services: sut: build: . - command: "bash -c 'python3 src/manage.py migrate && python3 src/manage.py loaddata init_data.json && python3 src/manage.py runserver 0.0.0.0:8000'" + command: "bash -c 'python3 src/manage.py migrate && python3 src/manage.py loaddata init_data.json && python3 src/manage.py test'" environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD From a0820f099e9217a578641b07e0a69048429bbd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Tue, 11 Jul 2017 20:51:24 +0200 Subject: [PATCH 44/46] adding mac specific stuff to docker ignore --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 2bd7b91..a234995 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,5 @@ logs/ .pylintrc .travis.yml +#OSX +.DS_Store From c9f9a4dfc8a5e380db709f53f61cedd841851883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Tue, 11 Jul 2017 20:57:08 +0200 Subject: [PATCH 45/46] reinstating politech database name --- docker-compose.test.yml | 1 + src/politech_backend/settings.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index d581c70..27274a3 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -5,6 +5,7 @@ version: '2.1' services: db: image: postgres:9.6.3 + command: psql -c "CREATE DATABASE politech;" -U postgres environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index 8ccb372..c685c54 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -121,7 +121,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'postgres', + 'NAME': 'politech', 'USER': os.environ["POSTGRES_USER"], 'PASSWORD': os.environ["POSTGRES_PASSWORD"], 'HOST': os.environ["DB_HOST"], #f.x. 'db' OR '127.0.0.1', From f7f2e16be14598fc7c6ff2585113afa428802c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Hrannar=20Bj=C3=B6rnsson?= Date: Tue, 11 Jul 2017 21:09:19 +0200 Subject: [PATCH 46/46] renaming database name to postgres --- docker-compose.test.yml | 1 - src/politech_backend/settings.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 27274a3..d581c70 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -5,7 +5,6 @@ version: '2.1' services: db: image: postgres:9.6.3 - command: psql -c "CREATE DATABASE politech;" -U postgres environment: - POSTGRES_USER=$POSTGRES_USER - POSTGRES_PASSWORD=$POSTGRES_PASSWORD diff --git a/src/politech_backend/settings.py b/src/politech_backend/settings.py index c685c54..8ccb372 100644 --- a/src/politech_backend/settings.py +++ b/src/politech_backend/settings.py @@ -121,7 +121,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'politech', + 'NAME': 'postgres', 'USER': os.environ["POSTGRES_USER"], 'PASSWORD': os.environ["POSTGRES_PASSWORD"], 'HOST': os.environ["DB_HOST"], #f.x. 'db' OR '127.0.0.1',