Skip to content

Commit

Permalink
Add Docker image building and pushing to Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassz committed Jul 12, 2018
1 parent c70447a commit 7668308
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
81 changes: 57 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,57 @@
language: python

python:
- "3.6"

install:
# Install conda
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
- conda clean --all -y
- ./python_env_build.sh
- source activate pb_env
- python manage.py collectstatic --no-input

addons:
postgresql: "9.4"

before_script:
- psql -c 'create database test_db;' -U postgres

script:
- py.test webapp/apps/
matrix:
include:
- language: ruby # Cannot be 'minimal' in order to have PostgreSQL

sudo: required

services: docker

env: TAG=${TRAVIS_COMMIT::6}

# Need NEW_RELIC_TOKEN to be defined in Travis settings
install:
- make NEW_RELIC_TOKEN=$NEW_RELIC_TOKEN webapp-build
- pip install --user git-lint pylint pycodestyle
- export PATH=$PATH:/$HOME/.local/bin

addons:
postgresql: "9.4"

before_script: psql -c 'create database mypb;' -U postgres

script:
- >
docker run --net host -e PORT=80 -e DJANGO_SETTINGS_MODULE=webapp.settings
-e DROPQ_WORKERS=127.0.0.1:5050
-e DATABASE_URL=postgresql://postgres@localhost/mypb
-it opensourcepolicycenter/web:$TAG
/bin/bash -c "pip install -q pytest-django && py.test webapp/apps"
- if git reset --soft ${TRAVIS_COMMIT_RANGE%...*}; then git lint; fi

before_deploy: curl https://cli-assets.heroku.com/install.sh | sh

deploy:
provider: script
# Need HEROKU_TOKEN to be defined in Travis settings
script: docker login --username=_ --password=$HEROKU_TOKEN registry.heroku.com && make MODE=test webapp-release
on:
branch: travis

- language: minimal

sudo: required

services: docker

# Also need OSPC_ANACONDA_TOKEN, AWS_ACCOUNT_ID, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be defined in settings
env: TAG=${TRAVIS_COMMIT::6}

install: make OSPC_ANACONDA_TOKEN=$OSPC_ANACONDA_TOKEN dist-build

script: make dist-test

deploy:
provider: script
script: bash distributed/deploy.sh staging
on:
branch: travis
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ webapp-build:
docker build --build-arg NEW_RELIC_TOKEN=$(NEW_RELIC_TOKEN) -t opensourcepolicycenter/web:$(TAG) ./

webapp-push:
docker tag opensourcepolicycenter/web:$(TAG) registry.heroku.com/ospc-$(VERSION)/web
docker push registry.heroku.com/ospc-$(VERSION)/web
docker push opensourcepolicycenter/web:$(TAG)

webapp-release:
heroku container:release web -a ospc-$(VERSION)
docker tag opensourcepolicycenter/web:$(TAG) registry.heroku.com/ospc-$(MODE)/web
docker push registry.heroku.com/ospc-$(MODE)/web
heroku container:release web -a ospc-$(MODE)
20 changes: 20 additions & 0 deletions distributed/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mode=$1
region=us-east-2

pip install --user awscli
eval $(aws ecr get-login --region $region --no-include-email)

function tagpush() {
docker tag opensourcepolicycenter/$1:$TAG $AWS_ACCOUNT_ID.dkr.ecr.$region.amazonaws.com/$mode-celeryflask:$1
docker push $AWS_ACCOUNT_ID.dkr.ecr.$region.amazonaws.com/$mode-celeryflask:$1
}

tagpush flask
tagpush celery

function redeploy() {
aws ecs update-service --cluster $mode-ecs-cluster --service $mode-$1 --region $region --force-new-deployment >/dev/null 2>&1
}

redeploy flask
redeploy celery
2 changes: 0 additions & 2 deletions webapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@

# if os.environ.get('DATABASE_URL', None):
# Parse database configuration from $DATABASE_URL
import dj_database_url
TEST_DATABASE = {
'TEST': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand All @@ -120,7 +119,6 @@
}
if os.environ.get('DATABASE_URL', None): # DATABASE_URL var is set
DATABASES = {'default': dj_database_url.config()}
DATABASES.update(TEST_DATABASE)
else: # DATABASE_URL is not set--try default
DATABASES = {
'default': {
Expand Down

0 comments on commit 7668308

Please sign in to comment.