diff --git a/.travis.yml b/.travis.yml index 6abd3e82..86adcb27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,60 @@ -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: + # Need HEROKU_TOKEN to be defined in Travis settings + - curl https://cli-assets.heroku.com/install.sh | sh + - echo "machine api.heroku.com password $HEROKU_TOKEN" > ~/.netrc + - docker login --username=_ --password=$HEROKU_TOKEN registry.heroku.com + + deploy: + provider: script + script: 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 diff --git a/Makefile b/Makefile index e531808a..36354f86 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/distributed/deploy.sh b/distributed/deploy.sh new file mode 100644 index 00000000..8d2307e2 --- /dev/null +++ b/distributed/deploy.sh @@ -0,0 +1,21 @@ +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 + echo "$1 deploy exit code: $?" +} + +redeploy flask +redeploy celery diff --git a/webapp/settings.py b/webapp/settings.py index cc6582fd..1692f66d 100644 --- a/webapp/settings.py +++ b/webapp/settings.py @@ -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', @@ -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': {