Trying to set up travis and docker auto-deploy
This commit is contained in:
parent
4e97a5f26a
commit
7978a2aa7e
|
@ -0,0 +1,47 @@
|
|||
language: python
|
||||
|
||||
python:
|
||||
- "3.7"
|
||||
|
||||
services:
|
||||
- postgresql
|
||||
- docker
|
||||
|
||||
addons:
|
||||
chrome: stable
|
||||
sonarcloud:
|
||||
organization: "sartography"
|
||||
|
||||
before_install:
|
||||
- psql -c 'create database communicator-test;' -U postgres
|
||||
|
||||
install:
|
||||
- pipenv install --dev
|
||||
|
||||
env:
|
||||
global:
|
||||
- TESTING=true
|
||||
- PB_ENABLED=false
|
||||
- SQLALCHEMY_DATABASE_URI="postgresql://postgres:@localhost:5432/communicator_test"
|
||||
|
||||
script:
|
||||
- pipenv run coverage run -m pytest
|
||||
- pipenv run coverage xml -i
|
||||
|
||||
after_success:
|
||||
- sonar-scanner
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
script: bash deploy.sh sartography/testing-communicator
|
||||
skip_cleanup: true
|
||||
on:
|
||||
all_branches: true
|
||||
condition: $TRAVIS_BRANCH =~ ^(dev|testing|demo|training|staging|master|rrt\/.*)$
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
recipients:
|
||||
- dan@sartography.com
|
10
Dockerfile
10
Dockerfile
|
@ -1,10 +1,16 @@
|
|||
FROM sartography/cr-connect-python-base
|
||||
FROM python:3.8-slim
|
||||
|
||||
WORKDIR /app
|
||||
COPY Pipfile Pipfile.lock /app/
|
||||
|
||||
RUN set -xe \
|
||||
&& pipenv install --dev \
|
||||
&& pip install pipenv \
|
||||
&& apt-get update -q \
|
||||
&& apt-get install -y -q \
|
||||
gcc python3-dev libssl-dev \
|
||||
curl postgresql-client git-core \
|
||||
gunicorn3 postgresql-client \
|
||||
&& pipenv install --dev
|
||||
&& apt-get remove -y gcc python3-dev libssl-dev \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
|
|
|
@ -28,6 +28,7 @@ SQLALCHEMY_DATABASE_URI = environ.get(
|
|||
'SQLALCHEMY_DATABASE_URI',
|
||||
default="postgresql://%s:%s@%s:%s/%s" % (DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
|
||||
)
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS=False
|
||||
TOKEN_AUTH_TTL_HOURS = float(environ.get('TOKEN_AUTH_TTL_HOURS', default=24))
|
||||
SECRET_KEY = environ.get('SECRET_KEY', default="Shhhh!!! This is secret! And better darn well not show up in prod.")
|
||||
SWAGGER_AUTH_KEY = environ.get('SWAGGER_AUTH_KEY', default="SWAGGER")
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
#########################################################################
|
||||
# Builds the Docker image for the current git branch on Travis CI and
|
||||
# publishes it to Docker Hub.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: Docker Hub repository to publish to
|
||||
#
|
||||
# Required environment variables (place in Settings menu on Travis CI):
|
||||
# $DOCKER_USERNAME: Docker Hub username
|
||||
# $DOCKER_TOKEN: Docker Hub access token
|
||||
#########################################################################
|
||||
|
||||
echo 'Building Docker image...'
|
||||
DOCKER_REPO="$1"
|
||||
|
||||
function branch_to_tag () {
|
||||
if [ "$1" == "master" ]; then echo "latest"; else echo "$1" ; fi
|
||||
}
|
||||
|
||||
function branch_to_deploy_group() {
|
||||
echo "covid";
|
||||
# if [[ $1 =~ ^(rrt\/.*)$ ]]; then echo "rrt"; else echo "crconnect" ; fi
|
||||
}
|
||||
|
||||
DOCKER_TAG=$(branch_to_tag "$TRAVIS_BRANCH")
|
||||
|
||||
DEPLOY_GROUP=$(branch_to_deploy_group "$TRAVIS_BRANCH")
|
||||
|
||||
echo "DOCKER_REPO = $DOCKER_REPO"
|
||||
echo "DOCKER_TAG = $DOCKER_TAG"
|
||||
|
||||
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin || exit 1
|
||||
docker build -f Dockerfile -t "$DOCKER_REPO:$DOCKER_TAG" . || exit 1
|
||||
|
||||
|
||||
# Push Docker image to Docker Hub
|
||||
echo "Publishing to Docker Hub..."
|
||||
docker push "$DOCKER_REPO" || exit 1
|
||||
echo "Done."
|
|
@ -12,9 +12,9 @@ class IvyServiceTest(BaseTest):
|
|||
|
||||
def test_read_file_and_build_records(self):
|
||||
records = IvyService.samples_from_ivy_file(self.ivy_file)
|
||||
self.assertEquals("987654321", records[0].student_id)
|
||||
self.assertEquals("testpositive@virginia.edu", records[1].email)
|
||||
self.assertEquals("1142270225", records[2].result_code)
|
||||
self.assertEqual("987654321", records[0].student_id)
|
||||
self.assertEqual("testpositive@virginia.edu", records[1].email)
|
||||
self.assertEqual("1142270225", records[2].result_code)
|
||||
|
||||
def test_invalid_file(self):
|
||||
with self.assertRaises(CommError):
|
||||
|
|
|
@ -34,38 +34,38 @@ class IvyServiceTest(BaseTest):
|
|||
# Load firebase records
|
||||
service = SampleService()
|
||||
fb_samples = self.get_firebase_records()
|
||||
self.assertEquals(0, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(0, len(db.session.query(Sample).all()))
|
||||
|
||||
service.add_or_update_records(fb_samples)
|
||||
|
||||
self.assertEquals(4, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(4, len(db.session.query(Sample).all()))
|
||||
|
||||
ivy_samples = IvyService.samples_from_ivy_file(self.ivy_file)
|
||||
service.add_or_update_records(ivy_samples)
|
||||
|
||||
# There are 6 records in ivy, but three records that should match up, giving seven total
|
||||
self.assertEquals(6, len(db.session.query(Sample).filter(Sample.in_ivy == True).all()))
|
||||
self.assertEquals(4, len(db.session.query(Sample).filter(Sample.in_firebase == True).all()))
|
||||
self.assertEquals(3, len(db.session.query(Sample).filter(Sample.in_firebase == True)
|
||||
self.assertEqual(6, len(db.session.query(Sample).filter(Sample.in_ivy == True).all()))
|
||||
self.assertEqual(4, len(db.session.query(Sample).filter(Sample.in_firebase == True).all()))
|
||||
self.assertEqual(3, len(db.session.query(Sample).filter(Sample.in_firebase == True)
|
||||
.filter(Sample.in_ivy == True).all()))
|
||||
self.assertEquals(7, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(7, len(db.session.query(Sample).all()))
|
||||
|
||||
|
||||
def test_correlate_samples_ivy_first(self):
|
||||
service = SampleService()
|
||||
|
||||
self.assertEquals(0, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(0, len(db.session.query(Sample).all()))
|
||||
|
||||
ivy_samples = IvyService.samples_from_ivy_file(self.ivy_file)
|
||||
service.add_or_update_records(ivy_samples)
|
||||
self.assertEquals(6, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(6, len(db.session.query(Sample).all()))
|
||||
|
||||
fb_samples = self.get_firebase_records()
|
||||
service.add_or_update_records(fb_samples)
|
||||
|
||||
self.assertEquals(6, len(db.session.query(Sample).filter(Sample.in_ivy == True).all()))
|
||||
self.assertEquals(4, len(db.session.query(Sample).filter(Sample.in_firebase == True).all()))
|
||||
self.assertEquals(3, len(db.session.query(Sample).filter(Sample.in_firebase == True)
|
||||
self.assertEqual(6, len(db.session.query(Sample).filter(Sample.in_ivy == True).all()))
|
||||
self.assertEqual(4, len(db.session.query(Sample).filter(Sample.in_firebase == True).all()))
|
||||
self.assertEqual(3, len(db.session.query(Sample).filter(Sample.in_firebase == True)
|
||||
.filter(Sample.in_ivy == True).all()))
|
||||
self.assertEquals(7, len(db.session.query(Sample).all()))
|
||||
self.assertEqual(7, len(db.session.query(Sample).all()))
|
||||
|
||||
|
|
Loading…
Reference in New Issue