Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Introducing docker and docker-compose #48

Merged
merged 48 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bb63f19
creating Dockerfile, .dockerignore and docket-compose
AriHrannar Jun 19, 2017
789dc63
put everything in an src folder. Dockerfile can now migrate
AriHrannar Jun 19, 2017
6ca9625
Adding initial data. Removing nginx for now
AriHrannar Jun 19, 2017
8550e7e
Update docs with docker info
AriHrannar Jun 19, 2017
2bee988
Backend is now just an docker image. Compose should be in another rep…
AriHrannar Jun 24, 2017
10c48a9
improved readme
AriHrannar Jun 24, 2017
7200313
image now runs linter. Added docker compose for running tests
AriHrannar Jun 24, 2017
2edc0de
only have postgres service in docker compose test
AriHrannar Jun 24, 2017
d751c30
adding db host env variable. Adding services to docker-compose test file
AriHrannar Jun 24, 2017
5edba51
trying docker-compose-test without sut
AriHrannar Jun 24, 2017
7dd7cf3
adding sut instead of backend in docker-compose-test
AriHrannar Jun 24, 2017
36731e3
renaming database to db instead of postgres as that is what its calle…
AriHrannar Jun 24, 2017
3901d64
Adding env variables to docker cloud and removing them from repo
AriHrannar Jun 24, 2017
7872c6c
Adding env variables to docker-compose.test
AriHrannar Jun 24, 2017
68247f6
removing curley brackets in env variables
AriHrannar Jun 24, 2017
69bad91
db host doesnt need to be a environment variable in docker. It should…
AriHrannar Jun 24, 2017
c064833
try host postgres
AriHrannar Jun 24, 2017
3de7d9b
trying to add port to db service as it does not seem to be found
AriHrannar Jun 24, 2017
c4b0080
trying a script to wait for postgres to be ready before running tests
AriHrannar Jun 24, 2017
879388d
chmod on wait-for-postgres so it can be run in the CI
AriHrannar Jun 24, 2017
77b5bda
deleting wait for postgres as taht did not help.
AriHrannar Jun 24, 2017
f0069f9
Adding links to docker-compose.test.yml
AriHrannar Jun 24, 2017
48fdadc
lets try version 3.2
AriHrannar Jun 24, 2017
a05f828
introducing environment variables again
AriHrannar Jun 24, 2017
3ae3f09
Adding healthcheck to postgres container for docker-compose.test
AriHrannar Jun 24, 2017
7d5ca40
removing condition in depends on as it doesnt fit with docker-compose…
AriHrannar Jun 24, 2017
2a87c47
lets try wait for it again
AriHrannar Jun 24, 2017
ffe80ce
removing access command
AriHrannar Jun 24, 2017
76632b3
lets try python instead of python3
AriHrannar Jun 25, 2017
768eca1
moving text execution into script
AriHrannar Jun 25, 2017
61997a9
debug more in script
AriHrannar Jun 25, 2017
5ee4422
lets try version 2.1 with healthheck!
AriHrannar Jun 25, 2017
094e1b2
Introducing env variables again for username and password for db
AriHrannar Jun 25, 2017
1ba075c
Removing unneeded env variales in dockerfile. Replacing script with j…
AriHrannar Jun 25, 2017
b2ec4ad
Adding some comments to explain things better
AriHrannar Jun 25, 2017
3d955bb
use python3 instead of pythong
AriHrannar Jun 25, 2017
a7478cc
removing travis as docker cloud CI has us covered
AriHrannar Jun 25, 2017
b9317a8
Making the secret key into a env variable
AriHrannar Jun 25, 2017
d53396e
adding secret key as env variabl in build
AriHrannar Jun 25, 2017
d70f8a6
Merge branch 'master' into deployment/docker-startup
AriHrannar Jul 11, 2017
6fe434d
adding migrate and loaddata to docker-compose test
AriHrannar Jul 11, 2017
48138c4
Merge branch 'master' of github.com:veritus/veritus-backend into depl…
Ragnar-H Jul 11, 2017
9e967c8
Removing migrations
Ragnar-H Jul 11, 2017
833dd17
Correct migrations
Ragnar-H Jul 11, 2017
f7c2a0b
replace runserver with test in testing compose
AriHrannar Jul 11, 2017
a0820f0
adding mac specific stuff to docker ignore
AriHrannar Jul 11, 2017
c9f9a4d
reinstating politech database name
AriHrannar Jul 11, 2017
f7f2e16
renaming database name to postgres
AriHrannar Jul 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.github/
.vscode/
env/
logs/
.coverage
.coveragerc
.gitignore
.pylintrc
.travis.yml

#OSX
.DS_Store
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Start with a python 3.6 image
FROM python:3.6
ENV PYTHONUNBUFFERED 1

# Creates src folder in container
RUN mkdir /code

# Copy everything into the /code directory of the container
ADD . /code/

# Makes code dir the working directory
# and we change directory into it
WORKDIR /code

# Install requirements
RUN pip install -r requirements.txt

# Run linter
RUN pylint **/*.py
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,26 @@ 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
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
```
docker build -t veritus/backend .
```
###Login to docker cloud
```
docker login
```
Input credentials.

###Push image to docker cloud
```
docker push <IMAGE-NAME>:</TAG>
```
Example:
```
docker push veritus/backend:latest
```
28 changes: 28 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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:
db:
image: postgres:9.6.3
environment:
- POSTGRES_USER=$POSTGRES_USER
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
healthcheck:
test: ["CMD-SHELL", "psql -h 'localhost' -U 'postgres' -c '\\l'"]
interval: 30s
timeout: 30s
retries: 3

sut:
build: .
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
- SECRET_KEY=$SECRET_KEY
- DB_HOST=db
depends_on:
db:
condition: service_healthy

21 changes: 0 additions & 21 deletions politicians/migrations/0002_auto_20170709_1708.py

This file was deleted.

21 changes: 0 additions & 21 deletions politicians/migrations/0003_auto_20170709_1712.py

This file was deleted.

20 changes: 0 additions & 20 deletions promises/migrations/0002_promise_fulfilled.py

This file was deleted.

8 changes: 1 addition & 7 deletions .pylintrc → pylintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
[MASTER]
ignore=apps.py, admin, migrations, bin, lib, man
ignore=manage.py, apps.py, admin.py, migrations, env
load-plugins=pylint_django

[MESSAGES CONTROL]
disable=missing-docstring, broad-except, bare-except, no-self-use, invalid-name, not-callable, not-an-iterable, locally-disabled

[TYPECHECK]
ignored-classes=WSGIRequest, Exception, Client


[pre-commit-hook]
command=custom_pylint
params=--rcfile=/path/to/another/pylint.rc
limit=8.0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions manage.py → src/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 10 additions & 7 deletions politech_backend/settings.py → src/politech_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
# 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

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be fixed in a future PR



# Application definition
Expand Down Expand Up @@ -121,12 +121,15 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'politech',
'USER': os.environ["DB_USER"],
'PASSWORD': os.environ["DB_PASS"],
'HOST': '127.0.0.1',
'NAME': 'postgres',
Copy link
Collaborator

Choose a reason for hiding this comment

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

'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
'ATOMIC_REQUESTS': True,
'OPTIONS': {
'client_encoding': 'UTF8',
}
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand All @@ -11,8 +11,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('party', '0001_initial'),
('district', '0001_initial'),
('party', '0001_initial'),
]

operations = [
Expand All @@ -25,7 +25,7 @@ class Migration(migrations.Migration):
('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')),
('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={
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand All @@ -12,9 +12,9 @@ class Migration(migrations.Migration):

dependencies = [
('parliament', '0001_initial'),
('party', '0001_initial'),
('case_gather', '0001_initial'),
('politicians', '0001_initial'),
('case_gather', '0001_initial'),
('party', '0001_initial'),
]

operations = [
Expand All @@ -25,6 +25,7 @@ class Migration(migrations.Migration):
('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')),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-06-06 19:17
# Generated by Django 1.10.3 on 2017-07-11 18:29
from __future__ import unicode_literals

from django.db import migrations, models
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.