Skip to content

Commit 2ef54c4

Browse files
committed
Add Docker image building and pushing to Travis
1 parent c70447a commit 2ef54c4

File tree

4 files changed

+84
-29
lines changed

4 files changed

+84
-29
lines changed

.travis.yml

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,60 @@
1-
language: python
2-
3-
python:
4-
- "3.6"
5-
6-
install:
7-
# Install conda
8-
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
9-
- bash miniconda.sh -b -p $HOME/miniconda
10-
- export PATH="$HOME/miniconda/bin:$PATH"
11-
- 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);'
12-
- conda clean --all -y
13-
- ./python_env_build.sh
14-
- source activate pb_env
15-
- python manage.py collectstatic --no-input
16-
17-
addons:
18-
postgresql: "9.4"
19-
20-
before_script:
21-
- psql -c 'create database test_db;' -U postgres
22-
23-
script:
24-
- py.test webapp/apps/
1+
matrix:
2+
include:
3+
- language: ruby # Cannot be 'minimal' in order to have PostgreSQL
4+
5+
sudo: required
6+
7+
services: docker
8+
9+
env: TAG=${TRAVIS_COMMIT::6}
10+
11+
# Need NEW_RELIC_TOKEN to be defined in Travis settings
12+
install:
13+
- make NEW_RELIC_TOKEN=$NEW_RELIC_TOKEN webapp-build
14+
- pip install --user git-lint pylint pycodestyle
15+
- export PATH=$PATH:/$HOME/.local/bin
16+
17+
addons:
18+
postgresql: "9.4"
19+
20+
before_script: psql -c 'create database mypb;' -U postgres
21+
22+
script:
23+
- >
24+
docker run --net host -e PORT=80 -e DJANGO_SETTINGS_MODULE=webapp.settings
25+
-e DROPQ_WORKERS=127.0.0.1:5050
26+
-e DATABASE_URL=postgresql://postgres@localhost/mypb
27+
-it opensourcepolicycenter/web:$TAG
28+
/bin/bash -c "pip install -q pytest-django && py.test webapp/apps"
29+
- if git reset --soft ${TRAVIS_COMMIT_RANGE%...*}; then git lint; fi
30+
31+
before_deploy:
32+
# Need HEROKU_TOKEN to be defined in Travis settings
33+
- curl https://cli-assets.heroku.com/install.sh | sh
34+
- echo "machine api.heroku.com password $HEROKU_TOKEN" > ~/.netrc
35+
- docker login --username=_ --password=$HEROKU_TOKEN registry.heroku.com
36+
37+
deploy:
38+
provider: script
39+
script: make MODE=test webapp-release
40+
on:
41+
branch: travis
42+
43+
- language: minimal
44+
45+
sudo: required
46+
47+
services: docker
48+
49+
# Also need OSPC_ANACONDA_TOKEN, AWS_ACCOUNT_ID, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be defined in settings
50+
env: TAG=${TRAVIS_COMMIT::6}
51+
52+
install: make OSPC_ANACONDA_TOKEN=$OSPC_ANACONDA_TOKEN dist-build
53+
54+
script: make dist-test
55+
56+
deploy:
57+
provider: script
58+
script: bash distributed/deploy.sh staging
59+
on:
60+
branch: travis

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ webapp-build:
2323
docker build --build-arg NEW_RELIC_TOKEN=$(NEW_RELIC_TOKEN) -t opensourcepolicycenter/web:$(TAG) ./
2424

2525
webapp-push:
26-
docker tag opensourcepolicycenter/web:$(TAG) registry.heroku.com/ospc-$(VERSION)/web
27-
docker push registry.heroku.com/ospc-$(VERSION)/web
2826
docker push opensourcepolicycenter/web:$(TAG)
2927

3028
webapp-release:
31-
heroku container:release web -a ospc-$(VERSION)
29+
docker tag opensourcepolicycenter/web:$(TAG) registry.heroku.com/ospc-$(MODE)/web
30+
docker push registry.heroku.com/ospc-$(MODE)/web
31+
heroku container:release web -a ospc-$(MODE)

distributed/deploy.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
mode=$1
2+
region=us-east-2
3+
4+
pip install --user awscli
5+
eval $(aws ecr get-login --region $region --no-include-email)
6+
7+
function tagpush() {
8+
docker tag opensourcepolicycenter/$1:$TAG $AWS_ACCOUNT_ID.dkr.ecr.$region.amazonaws.com/$mode-celeryflask:$1
9+
docker push $AWS_ACCOUNT_ID.dkr.ecr.$region.amazonaws.com/$mode-celeryflask:$1
10+
}
11+
12+
tagpush flask
13+
tagpush celery
14+
15+
function redeploy() {
16+
aws ecs update-service --cluster $mode-ecs-cluster --service $mode-$1 --region $region --force-new-deployment >/dev/null 2>&1
17+
echo "$1 deploy exit code: $?"
18+
}
19+
20+
redeploy flask
21+
redeploy celery

webapp/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109

110110
# if os.environ.get('DATABASE_URL', None):
111111
# Parse database configuration from $DATABASE_URL
112-
import dj_database_url
113112
TEST_DATABASE = {
114113
'TEST': {
115114
'ENGINE': 'django.db.backends.postgresql_psycopg2',
@@ -120,7 +119,6 @@
120119
}
121120
if os.environ.get('DATABASE_URL', None): # DATABASE_URL var is set
122121
DATABASES = {'default': dj_database_url.config()}
123-
DATABASES.update(TEST_DATABASE)
124122
else: # DATABASE_URL is not set--try default
125123
DATABASES = {
126124
'default': {

0 commit comments

Comments
 (0)