-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Docker image building, testing and pushing to Travis #920
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doe this grab the first six characters of the git commit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly. This doesn't actually get copied anywhere beyond the Travis instance as far as I know, so it's not too important, but the 6-character git commit hash seemed good to use. |
||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move
pytest-django
into therequirements.txt
file. That way people can run these tests locally with ease.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already in
requirements_dev.txt
, which gets installed by thepython_env_build.sh
script which is run by end-users. So I think it actually makes sense the current way, right? It probably shouldn't be in the image that gets deployed to e.g. Heroku.