Skip to content

Commit

Permalink
EAS-1576 Add config for local running (#330)
Browse files Browse the repository at this point in the history
* improve env var naming

* improve env nomenclature

* restore test config

* add config for local running

* remove used config classes

* improve variable name

* remove deprecated PR template

* default to local config
  • Loading branch information
jonathan-owens-gds authored Nov 30, 2023
1 parent a3bacc0 commit 36f412f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 40 deletions.
8 changes: 0 additions & 8 deletions .github/pull_request_template.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/on-pr-into-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Bootstrap Python app and run tests
run: |
export ENVIRONMENT='development'
export ENVIRONMENT='local'
set -eu
make bootstrap
make test
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_app():
)

from app.config import configs
environment = os.getenv('NOTIFY_ENVIRONMENT', 'development')
environment = os.getenv('HOST', 'local')
application.config.from_object(configs[environment])

from app.main import bp as main
Expand Down
28 changes: 5 additions & 23 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Config():
FASTLY_API_KEY = os.getenv("FASTLY_API_KEY")
FASTLY_SURROGATE_KEY = "notify-emergency-alerts"

NOTIFY_API_HOST_NAME = os.environ.get("NOTIFY_API_HOST_NAME")
NOTIFY_API_CLIENT_SECRET = os.environ.get("NOTIFY_API_CLIENT_SECRET")
NOTIFY_API_HOST_NAME = "http://localhost:6011"
NOTIFY_API_CLIENT_SECRET = "govuk-alerts-secret-key"
NOTIFY_API_CLIENT_ID = "govuk-alerts"

CELERY = {
Expand Down Expand Up @@ -49,7 +49,7 @@ class Config():
PLANNED_TESTS_YAML_FILE_NAME = "planned-tests.yaml"


class Decoupled(Config):
class Hosted(Config):
# Prefix to identify queues in SQS
NOTIFICATION_QUEUE_PREFIX = f"{os.getenv('ENVIRONMENT')}-"
SQS_QUEUE_BASE_URL = os.getenv("SQS_QUEUE_BASE_URL")
Expand Down Expand Up @@ -103,13 +103,6 @@ class Decoupled(Config):
PLANNED_TESTS_YAML_FILE_NAME = "planned-tests.yaml"


class Development(Config):
NOTIFY_API_CLIENT_SECRET = "govuk-alerts-secret-key"
NOTIFY_API_HOST_NAME = "http://localhost:6011"

PLANNED_TESTS_YAML_FILE_NAME = "planned-tests-dev.yaml"


class Test(Config):
DEBUG = True

Expand All @@ -122,19 +115,8 @@ class Test(Config):
GOVUK_ALERTS_S3_BUCKET_NAME = "test-bucket-name"


class Staging(Config):
PLANNED_TESTS_YAML_FILE_NAME = "planned-tests-staging.yaml"


class Preview(Config):
PLANNED_TESTS_YAML_FILE_NAME = "planned-tests-preview.yaml"


configs = {
"development": Development,
"decoupled": Decoupled,
"local": Config,
"hosted": Hosted,
"test": Test,
"staging": Staging,
"preview": Preview,
"production": Config,
}
2 changes: 1 addition & 1 deletion app/models/planned_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class PlannedTests(SerialisedModelCollection):
model = PlannedTest
planned_tests = defaultdict()
environment = os.getenv('NOTIFY_ENVIRONMENT', 'development')
environment = os.getenv('HOST', 'local')
yaml_filename = (configs[environment].PLANNED_TESTS_YAML_FILE_NAME)

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def is_in_uk(simple_polygons):


def upload_html_to_s3(rendered_pages):
notify_environment = os.environ.get('NOTIFY_ENVIRONMENT')
host_environment = os.environ.get('HOST')

if (notify_environment == "decoupled"):
if (host_environment == "hosted"):
session = boto3.Session()

else:
Expand Down Expand Up @@ -80,9 +80,9 @@ def upload_assets_to_s3():
if not Path(DIST).exists():
raise FileExistsError(f'Folder {DIST} not found.')

notify_environment = os.environ.get('NOTIFY_ENVIRONMENT')
host_environment = os.environ.get('HOST')

if (notify_environment == "decoupled"):
if (host_environment == "hosted"):
session = boto3.Session()

else:
Expand Down
2 changes: 1 addition & 1 deletion manifest.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ applications:
env:
# Logging and metrics
LOGGING_STDOUT_JSON: '1'
NOTIFY_ENVIRONMENT: '{{ environment }}'
HOST: '{{ environment }}'
NOTIFY_LOG_PATH: '/home/vcap/logs/app.log'
STATSD_HOST: "notify-statsd-exporter-{{ environment }}.apps.internal"

Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pytest]
testpaths = tests
env =
NOTIFY_ENVIRONMENT=test
HOST=test
xfail_strict = True
# suppress deprecation warnings from within dependencies (celery, flask and flask respeectively)
filterwarnings =
Expand Down

0 comments on commit 36f412f

Please sign in to comment.