From 177515de8f7089267cb9ac175b62e296119e4002 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 21 Oct 2016 16:16:10 +0100 Subject: [PATCH 1/7] Use python wheels to speed up AS deployment: * Create wheels from python dependencies on building codedeploy artifact * Update script to install wheels and default to pypi if not found --- Makefile | 1 + scripts/aws_install_dependencies.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6884c678b..62dfbc931 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ build: dependencies generate-version-file ## Build project .PHONY: build-codedeploy-artifact build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy + pip3 wheel --wheel-dir=wheelhouse -r requirements.txt mkdir -p target zip -r -x@deploy-exclude.lst target/notifications-api.zip * diff --git a/scripts/aws_install_dependencies.sh b/scripts/aws_install_dependencies.sh index b82881d45..03daadb21 100755 --- a/scripts/aws_install_dependencies.sh +++ b/scripts/aws_install_dependencies.sh @@ -5,4 +5,4 @@ set -eo pipefail echo "Install dependencies" cd /home/notify-app/notifications-api; -pip3 install -r /home/notify-app/notifications-api/requirements.txt +pip3 install --find-links=wheelhouse -r /home/notify-app/notifications-api/requirements.txt From 72993311b35e4b4a701a167375c9d3ab554b97bf Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Mon, 24 Oct 2016 16:23:18 +0100 Subject: [PATCH 2/7] Install wheel when building artifact --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 62dfbc931..3c258990f 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ build: dependencies generate-version-file ## Build project .PHONY: build-codedeploy-artifact build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy + pip3 install wheel pip3 wheel --wheel-dir=wheelhouse -r requirements.txt mkdir -p target zip -r -x@deploy-exclude.lst target/notifications-api.zip * From a45c62d41d3c9c6bea6d3f00ba64ae062e7c5dd1 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 25 Oct 2016 17:49:49 +0100 Subject: [PATCH 3/7] add can_send_letters flag to services defaults to false --- app/models.py | 1 + migrations/versions/0058_add_letters_flag.py | 24 ++++++++++++++++++++ tests/app/service/test_rest.py | 12 ++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/0058_add_letters_flag.py diff --git a/app/models.py b/app/models.py index 445977251..3fa042d98 100644 --- a/app/models.py +++ b/app/models.py @@ -123,6 +123,7 @@ class Service(db.Model, Versioned): backref=db.backref('user_to_service', lazy='dynamic')) restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False) research_mode = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=False) + can_send_letters = db.Column(db.Boolean, nullable=False, default=False) email_from = db.Column(db.Text, index=False, unique=True, nullable=False) created_by = db.relationship('User') created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False) diff --git a/migrations/versions/0058_add_letters_flag.py b/migrations/versions/0058_add_letters_flag.py new file mode 100644 index 000000000..3e7e5fcac --- /dev/null +++ b/migrations/versions/0058_add_letters_flag.py @@ -0,0 +1,24 @@ +"""empty message + +Revision ID: 0058_add_letters_flag +Revises: 0057_change_email_template +Create Date: 2016-10-25 17:37:27.660723 + +""" + +# revision identifiers, used by Alembic. +revision = '0058_add_letters_flag' +down_revision = '0057_change_email_template' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('services', sa.Column('can_send_letters', sa.Boolean(), nullable=False, server_default=sa.false())) + op.add_column('services_history', sa.Column('can_send_letters', sa.Boolean(), nullable=False, server_default=sa.false())) + + +def downgrade(): + op.drop_column('services_history', 'can_send_letters') + op.drop_column('services', 'can_send_letters') diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 69e382c4e..3959e401d 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -193,6 +193,7 @@ def test_create_service(notify_api, sample_user): json_resp = json.loads(resp.get_data(as_text=True)) assert json_resp['data']['name'] == 'created service' assert not json_resp['data']['research_mode'] + assert not json_resp['data']['can_send_letters'] def test_should_not_create_service_with_missing_user_id_field(notify_api, fake_uuid): @@ -376,7 +377,7 @@ def test_update_service(notify_api, notify_db, sample_service): assert result['data']['organisation'] == str(org.id) -def test_update_service_research_mode(notify_api, sample_service): +def test_update_service_flags(notify_api, sample_service): with notify_api.test_request_context(): with notify_api.test_client() as client: auth_header = create_authorization_header() @@ -387,10 +388,12 @@ def test_update_service_research_mode(notify_api, sample_service): json_resp = json.loads(resp.get_data(as_text=True)) assert resp.status_code == 200 assert json_resp['data']['name'] == sample_service.name - assert not json_resp['data']['research_mode'] + assert json_resp['data']['research_mode'] is False + assert json_resp['data']['can_send_letters'] is False data = { - 'research_mode': True + 'research_mode': True, + 'can_send_letters': True } auth_header = create_authorization_header() @@ -402,7 +405,8 @@ def test_update_service_research_mode(notify_api, sample_service): ) result = json.loads(resp.get_data(as_text=True)) assert resp.status_code == 200 - assert result['data']['research_mode'] + assert result['data']['research_mode'] is True + assert result['data']['can_send_letters'] is True def test_update_service_research_mode_throws_validation_error(notify_api, sample_service): From 497f56bc81608ad3c81c5642b49f0623c833a228 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 28 Oct 2016 17:27:37 +0100 Subject: [PATCH 4/7] Move wheel dependency installation to docker build --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3c258990f..d083adc97 100644 --- a/Makefile +++ b/Makefile @@ -57,6 +57,8 @@ production: ## Set environment to production dependencies: venv ## Install build dependencies mkdir -p ${PIP_ACCEL_CACHE} PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} ./venv/bin/pip-accel install -r requirements_for_test.txt + pip3 install wheel + pip3 wheel --wheel-dir=wheelhouse -r requirements.txt .PHONY: generate-version-file generate-version-file: ## Generates the app version file @@ -67,8 +69,6 @@ build: dependencies generate-version-file ## Build project .PHONY: build-codedeploy-artifact build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy - pip3 install wheel - pip3 wheel --wheel-dir=wheelhouse -r requirements.txt mkdir -p target zip -r -x@deploy-exclude.lst target/notifications-api.zip * From c8be8db7422da0074efc69af1d7b8a0de2432498 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 28 Oct 2016 17:43:27 +0100 Subject: [PATCH 5/7] Use venv for installation --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d083adc97..d1f06a9f7 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,8 @@ production: ## Set environment to production dependencies: venv ## Install build dependencies mkdir -p ${PIP_ACCEL_CACHE} PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} ./venv/bin/pip-accel install -r requirements_for_test.txt - pip3 install wheel - pip3 wheel --wheel-dir=wheelhouse -r requirements.txt + ./venv/bin/pip-accel install wheel + ./venv/bin/pip-accel wheel --wheel-dir=wheelhouse -r requirements.txt .PHONY: generate-version-file generate-version-file: ## Generates the app version file From ebe2ec434194f1817ec66894dbf023c382b5fe1b Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 28 Oct 2016 17:48:31 +0100 Subject: [PATCH 6/7] Install pip wheel in the dockerfile --- Makefile | 3 +-- docker/Dockerfile-build | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d1f06a9f7..58bfd9b3c 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,6 @@ production: ## Set environment to production dependencies: venv ## Install build dependencies mkdir -p ${PIP_ACCEL_CACHE} PIP_ACCEL_CACHE=${PIP_ACCEL_CACHE} ./venv/bin/pip-accel install -r requirements_for_test.txt - ./venv/bin/pip-accel install wheel - ./venv/bin/pip-accel wheel --wheel-dir=wheelhouse -r requirements.txt .PHONY: generate-version-file generate-version-file: ## Generates the app version file @@ -66,6 +64,7 @@ generate-version-file: ## Generates the app version file .PHONY: build build: dependencies generate-version-file ## Build project + ./venv/bin/pip-accel wheel --wheel-dir=wheelhouse -r requirements.txt .PHONY: build-codedeploy-artifact build-codedeploy-artifact: ## Build the deploy artifact for CodeDeploy diff --git a/docker/Dockerfile-build b/docker/Dockerfile-build index 4fa6afb2d..25b071293 100644 --- a/docker/Dockerfile-build +++ b/docker/Dockerfile-build @@ -20,6 +20,7 @@ RUN \ echo "Install global pip packages" \ && pip install \ virtualenv \ - awscli + awscli \ + wheel WORKDIR /var/project From 9192ff137f9f81f1b2560f22d0ae86dea46b6aff Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 31 Oct 2016 09:21:18 +0000 Subject: [PATCH 7/7] Bump utils Includes: - [ ] https://github.com/alphagov/notifications-utils/pull/75 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3ffdfb572..dba7c2cfc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,6 @@ statsd==3.2.1 git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0 -git+https://github.com/alphagov/notifications-utils.git@9.0.5#egg=notifications-utils==9.0.5 +git+https://github.com/alphagov/notifications-utils.git@9.1.1#egg=notifications-utils==9.1.1 git+https://github.com/alphagov/boto.git@2.42.0-patch2#egg=boto==2.42.0-patch2