Skip to content

Commit

Permalink
Merge branch 'master' into update-serenata-de-amor-config-ini
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed Mar 22, 2018
2 parents 505be49 + 5dbf659 commit 89c04fe
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 256 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# development environment
.coverage
.env
.env.prod
.floo
*.sqlite3
htmlcov/
Expand Down
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ services:
- postgresql

env:
- DATABASE_URL="postgres://postgres@localhost/jarbas"
global:
- AMAZON_BUCKET=serenata-de-amor-data
- AMAZON_REGION=sa-east-1
- DATABASE_URL=postgres://postgres@localhost/jarbas

install:
- cp contrib/.env.sample .env
- python -m pip install -U pip
- psql -U postgres -c 'create database "jarbas";'
- python -m pip install -r requirements-dev.txt coveralls
- ./rosie/setup
- python -m pip install -r rosie/requirements.txt

before_script:
- python manage.py migrate
- python manage.py collectstatic --no-input

script:
- coverage run manage.py test
- cd rosie && coverage run rosie.py test && python rosie.py run federal_senate
- cd rosie
- coverage run rosie.py test
- python rosie.py run federal_senate
- cd ..

after_success:
- coveralls
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM python:3.5.4-alpine
ENV PYTHONUNBUFFERED=1 \
GOSS_VERSION=${GOSS_VERSION:-v0.3.5}
FROM python:3.6.4-alpine3.7

ENV AMAZON_BUCKET=serenata-de-amor-data \
AMAZON_REGION=sa-east-1 \
GOSS_VERSION=${GOSS_VERSION:-v0.3.5} \
PYTHONUNBUFFERED=1 \
SECRET_KEY=${SECRET_KEY:-my-secret}

COPY ./requirements.txt /code/requirements.txt
COPY ./requirements-dev.txt /code/requirements-dev.txt
Expand All @@ -10,7 +14,6 @@ COPY goss.yaml /goss/goss.yaml

WORKDIR /code

# set timezone
RUN set -ex && \
apk add --no-cache --virtual=.goss-dependencies curl ca-certificates && \
curl -L https://github.com/aelsabbahy/goss/releases/download/"$GOSS_VERSION"/goss-linux-amd64 -o /usr/local/bin/goss && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN ./node_modules/.bin/elm-package install --yes

COPY ./jarbas /code/jarbas

CMD ["npm", "run", "watch"]
CMD ["npm", "run", "assets"]
2 changes: 1 addition & 1 deletion Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.13.3-alpine
FROM nginx:1.13.9-alpine

COPY contrib/nginx.conf /etc/nginx/conf.d/default.conf

Expand Down
23 changes: 3 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ Copy `contrib/.env.sample` as `.env` in the project's root folder and adjust you

##### Amazon S3 settings

* `AMAZON_S3_BUCKET` (_str_) Name of the Amazon S3 bucket to look for datasets (e.g. `serenata-de-amor-data`)
* `AMAZON_S3_REGION` (_str_) Region of the Amazon S3 (e.g. `s3-sa-east-1`)
* `AMAZON_BUCKET` (_str_) Name of the Amazon S3 bucket to look for datasets (e.g. `serenata-de-amor-data`)
* `AMAZON_REGION` (_str_) Region of the Amazon S3 (e.g. `s3-sa-east-1`)
* `AMAZON_S3_CEAPTRANSLATION_DATE` (_str_) File name prefix for dataset guide (e.g. `2016-08-08` for `2016-08-08-ceap-datasets.md`)

##### Google settings
Expand All @@ -191,26 +191,9 @@ instructions](https://python-twitter.readthedocs.io/en/latest/getting_started.ht

### Using Docker

There are two combinations in terms of With [Docker](https://docs.docker.com/engine/installation/) and [Docker Compose](https://docs.docker.com/compose/install/)
You must first install [Docker](https://docs.docker.com/engine/installation/) and [Docker Compose](https://docs.docker.com/compose/install/)
environments.

* **Develoment**: simply running `docker-compose …` will trigger `docker-compose.yml` and `docker-compose.override.yml` with optimun configuration for developing such as:
* automatic serving static files through Django
* restarting the Django on Python files changes
* rebuilding JS from Elm files on save
* skipping server cache
* **Production**: passing a specific configurarion as `docker-compose -f docker-compose.yml -f docker-compose.prod.yml …` will launch a more robust environment with production in mind, among others:
* `nginx` in front of Django
* server-side cache with memcached
* manually generate JS after edits on Elm files
* manually run `collectstatic` command is static changes
* manually restarting server on change
* requires `VIRTUAL_HOST_WEB` envvar, e.g. `VIRTUAL_HOST_WEB=jarbas.serenata.ai docker-compose -f docker-compose.yml -f docker-compose.prod.yml …`

That said instructions here keep it simple and runs with the development set up. To swicth always add `-f docker-compose.yml -f docker-compose.prod.yml` after `docker-compose`.

When using tghe production settings remember to double check the [appropriate environment varables](#for-the-production-environment) and to create a `.env.prod` (separate from `.env`) to hold production only values.

#### Build and start services

```console
Expand Down
35 changes: 22 additions & 13 deletions contrib/.env.sample
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
DEBUG=False
SECRET_KEY=jaa-aaa-ar-bas
ALLOWED_HOSTS=*
DEBUG=True
HTTPS_METHOD=redirect
INBOX_PASSWORD=

DATABASE_URL=postgres://jarbas:mysecretpassword@localhost/jarbas
CELERY_BROKER_URL='amqp://guest:guest@localhost//'
LETSENCRYPT_EMAIL=contato@serenata.ai
POSTGRES_PASSWORD=mysecretpassword
POSTGRES_USER=jarbas
SECRET_KEY=my-secret
STATICFILES_STORAGE=
VIRTUAL_HOST=jarbas.serenata.ai
VIRTUAL_PROTO=http

DATABASE_URL=postgres://jarbas:mysecretpassword@postgres/jarbas
CELERY_BROKER_URL=amqp://guest:guest@queue/
LOGGING_URL=

AMAZON_S3_BUCKET=serenata-de-amor-data
AMAZON_S3_REGION=s3-sa-east-1
AMAZON_ACCESS_KEY=
AMAZON_BUCKET=serenata-de-amor-data
AMAZON_REGION=sa-east-1
AMAZON_S3_CEAPTRANSLATION_DATE=2016-08-08
AMAZON_SECRET_KEY=

GOOGLE_API_KEY=
GOOGLE_STREET_VIEW_API_KEY=my-google-places-api-key
GOOGLE_STREET_VIEW_API_KEY=

FOURSQUARE_CLIENT_ID=
FOURSQUARE_CLIENT_SECRET=
Expand All @@ -21,10 +30,10 @@ NEW_RELIC_DEVELOPER_MODE=true
NEW_RELIC_ENVIRONMENT=development
NEW_RELIC_LICENSE_KEY=

TWITTER_CONSUMER_KEY=my_twitter_consumer_key
TWITTER_CONSUMER_SECRET=my_twitter_consumer_secret
TWITTER_ACCESS_TOKEN=my_twitter_access_token
TWITTER_ACCESS_SECRET=my_twitter_access_secret
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_SECRET=

YELP_ACCESS_TOKEN=

Expand Down
37 changes: 0 additions & 37 deletions docker-compose.override.yml

This file was deleted.

108 changes: 0 additions & 108 deletions docker-compose.prod.yml

This file was deleted.

43 changes: 29 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,57 @@ services:
- /tmp/serenata-data:/tmp/serenata-data

django:
image: datasciencebr/jarbas-backend
environment:
- ALLOWED_HOSTS=localhost,127.0.0.1
- AMAZON_S3_BUCKET=serenata-de-amor-data
- AMAZON_S3_REGION=s3-sa-east-1
- AMAZON_S3_CEAPTRANSLATION_DATE=2016-08-08
- CELERY_BROKER_URL=amqp://guest:guest@queue/
- NEW_RELIC_APP_NAME=Jarbas (Django); Jarbas (Combined)
image: serenata/django
depends_on:
- elm
- postgres
- tasks
volumes:
- "./contrib/data:/mnt/data"
environment:
- NEW_RELIC_APP_NAME=Jarbas (Django); Jarbas (Combined)
hostname: django
ports:
- "8000:8000"
volumes:
- .:/code
- ./contrib/data:/mnt/data

tasks:
image: datasciencebr/jarbas-backend
image: serenata/django
environment:
- CELERY_BROKER_URL=amqp://guest:guest@queue/
- NEW_RELIC_APP_NAME=Jarbas (Celery); Jarbas (Combined)
depends_on:
- queue
command: ["newrelic-admin", "run-program", "celery", "worker", "--app", "jarbas"]
volumes:
- .:/code
hostname: tasks

elm:
image: datasciencebr/jarbas-frontend
command: ["npm", "run", "watch"]
image: serenata/elm
volumes:
- ./jarbas:/code/jarbas
hostname: elm

queue:
image: rabbitmq:3.6.11-alpine
image: rabbitmq:3.7.3-alpine
hostname: queue

postgres:
image: postgres:10.3-alpine
env_file:
- .env
volumes:
- ./db:/var/lib/postgresql
ports:
- "5432:5432"

research:
build:
context: research
args:
- AMAZON_BUCKET
- AMAZON_REGION
env_file:
- .env
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
origin = 'https://{}.amazonaws.com/{}/{}-ceap-datasets.md'.format(
settings.AMAZON_S3_REGION,
settings.AMAZON_S3_BUCKET,
settings.AMAZON_REGION,
settings.AMAZON_BUCKET,
settings.AMAZON_S3_CEAPTRANSLATION_DATE
)

Expand Down
Loading

0 comments on commit 89c04fe

Please sign in to comment.