From d08f2ce8378b380f5cb57a5b7a864dae0c942efb Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 11 Feb 2021 11:44:46 -0500 Subject: [PATCH 1/6] Moving to quay.io, no longer need to run the deploy section for travis, as this is handled within quay. --- .travis.yml | 8 -------- deploy.sh | 45 --------------------------------------------- 2 files changed, 53 deletions(-) delete mode 100755 deploy.sh diff --git a/.travis.yml b/.travis.yml index 6e6dbf6c..85640a9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,14 +31,6 @@ script: after_success: - sonar-scanner -deploy: - provider: script - script: bash deploy.sh sartography/cr-connect-workflow - skip_cleanup: true - on: - all_branches: true - condition: $TRAVIS_BRANCH =~ ^(dev|testing|demo|training|staging|master|rrt\/.*)$ - notifications: email: on_success: change diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 04e3e81c..00000000 --- a/deploy.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/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() { - 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") - -if [ "$DEPLOY_GROUP" == "rrt" ]; then - IFS='/' read -ra ARR <<< "$TRAVIS_BRANCH" # Split branch on '/' character - DOCKER_TAG=$(branch_to_tag "rrt_${ARR[1]}") -fi - -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." From 044b82cb25ff751762dc24111f953370fe7fe46a Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 11 Feb 2021 12:44:34 -0500 Subject: [PATCH 2/6] Maybe a faster, more dependeable dockerfile? --- Dockerfile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index bc602d09..ef931d08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,24 @@ -FROM sartography/cr-connect-python-base +FROM python:3.8 + +RUN pip install pipenv +RUN useradd _gunicorn --no-create-home --user-group + +RUN apt-get update && \ + apt-get install -y -q \ + gcc libssl-dev \ + curl postgresql-client git-core \ + gunicorn3 postgresql-client WORKDIR /app COPY Pipfile Pipfile.lock /app/ +RUN cd /app && pipenv lock --keep-outdated --requirements > requirements.txt +RUN pip install -r /app/requirements.txt RUN set -xe \ - && pipenv install --dev \ && apt-get remove -y gcc python3-dev libssl-dev \ && apt-get autoremove -y \ && apt-get clean -y \ - && rm -rf /var/lib/apt/lists/* \ - && useradd _gunicorn --no-create-home --user-group + && rm -rf /var/lib/apt/lists/* COPY . /app/ WORKDIR /app From d8bd20313932e5a20949747ba6de09c2203114e6 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Thu, 11 Feb 2021 15:36:12 -0500 Subject: [PATCH 3/6] The email script was failing validation because of missing parameters in scripts.email.do_task_validate_only. I added a test in tests.test_email_script to make sure we get the default email_address. I also found and fixed a bug in workflow_service.populate_form_with_random_data where we would overwrite default_values with random text because of a missing continue. (We don't want to continue if we have repeating fields though.) --- crc/scripts/email.py | 2 +- crc/services/workflow_service.py | 2 ++ tests/test_email_script.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crc/scripts/email.py b/crc/scripts/email.py index 3160dc22..dcef5e8e 100644 --- a/crc/scripts/email.py +++ b/crc/scripts/email.py @@ -26,7 +26,7 @@ Example: email ("My Subject", "dhf8r@virginia.edu", pi.email) """ - def do_task_validate_only(self, task, *args, **kwargs): + def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): self.get_subject(args) self.get_email_recipients(task, args) self.get_content(task) diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 74d070c0..894bac4f 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -166,6 +166,8 @@ class WorkflowService(object): # If we have a default_value or value_expression, try to set the default if field.has_property(Task.FIELD_PROP_VALUE_EXPRESSION) or (hasattr(field, 'default_value') and field.default_value): form_data[field.id] = WorkflowService.get_default_value(field, task) + if not field.has_property(Task.FIELD_PROP_REPEAT): + continue # If we are only populating required fields, and this isn't required. stop here. if required_only: diff --git a/tests/test_email_script.py b/tests/test_email_script.py index ee3d7219..d1520314 100644 --- a/tests/test_email_script.py +++ b/tests/test_email_script.py @@ -1,9 +1,19 @@ from tests.base_test import BaseTest from crc import mail +import json class TestEmailScript(BaseTest): + def test_email_script_validation(self): + # This validates scripts.email.do_task_validate_only + # It also tests that we don't overwrite the default email_address with random text during validation + # Otherwise json would have an error about parsing the email address + self.load_example_data() + spec_model = self.load_test_spec('email_script') + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % spec_model.id, headers=self.logged_in_headers()) + self.assertEqual([], rv.json) + def test_email_script(self): with mail.record_messages() as outbox: @@ -12,6 +22,7 @@ class TestEmailScript(BaseTest): first_task = self.get_workflow_api(workflow).next_task workflow = self.get_workflow_api(workflow) + self.assertEqual('dan@sartography.com', workflow.next_task.data['email_address']) self.complete_form(workflow, first_task, {'email_address': 'test@example.com'}) self.assertEqual(1, len(outbox)) From 7eeb491dfa195998bcff62af4d4d399f6ce480a3 Mon Sep 17 00:00:00 2001 From: Nile Walker Date: Fri, 12 Feb 2021 09:30:18 -0500 Subject: [PATCH 4/6] User str decode Removed --- crc/api/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crc/api/user.py b/crc/api/user.py index bbd51130..6c1e9abf 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -214,7 +214,7 @@ def _handle_login(user_info: LdapModel, redirect_url=None): g.user = user # Return the frontend auth callback URL, with auth token appended. - auth_token = user.encode_auth_token().decode() + auth_token = user.encode_auth_token()#.decode() g.token = auth_token if redirect_url is not None: From ab3453a70e74a30793ddb6aec668ec1c3c664400 Mon Sep 17 00:00:00 2001 From: Nile Walker Date: Fri, 12 Feb 2021 09:43:30 -0500 Subject: [PATCH 5/6] Update user.py --- crc/api/user.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crc/api/user.py b/crc/api/user.py index 6c1e9abf..6eedaa45 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -214,7 +214,12 @@ def _handle_login(user_info: LdapModel, redirect_url=None): g.user = user # Return the frontend auth callback URL, with auth token appended. - auth_token = user.encode_auth_token()#.decode() + auth_token = user.encode_auth_token() + if type(auth_token) != str: + try: + auth_token = auth_token.decode() + except: + raise(ValueError("ValueError Auth Token not understood")) g.token = auth_token if redirect_url is not None: From c44e784eb2da0adabc6eda8980808a04397b49cd Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 12 Feb 2021 09:48:41 -0500 Subject: [PATCH 6/6] Fixing a bug with the user model. --- crc/api/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crc/api/user.py b/crc/api/user.py index 6c1e9abf..bbd51130 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -214,7 +214,7 @@ def _handle_login(user_info: LdapModel, redirect_url=None): g.user = user # Return the frontend auth callback URL, with auth token appended. - auth_token = user.encode_auth_token()#.decode() + auth_token = user.encode_auth_token().decode() g.token = auth_token if redirect_url is not None: