From 2911de0b93b750877d29a37d7f888ab8ffdea0ac Mon Sep 17 00:00:00 2001 From: Emile Swarts Date: Mon, 1 Jul 2024 14:12:35 +0100 Subject: [PATCH] add changes required for dbt platform Fix repository name Downgrade paketobuildpacks/builder-jammy-full trigger build add prebuild script to get submodules Downgrade Paketo buildpack to get older version of Python Bump buildpack Bump buildpack Add runtime.txt file with Python version Remove runtime.txt chore: specify required python version in pyroject.toml chore: specify required python version in pyroject.toml in single quotes chore: specify version of python in runtime.txt chore: add pipenv install --deploy to pre_build phase chore: remove pipenv install deploy from pre build phase update python version in runtime bump builder version revert back to python 3.8 update python version to 3.9 update pipfile.lock remove typed-ast package Remove comment as this is seen as a deployable process Add debugging for failed build Improve debugging Print what's in /layers for debugging Debug pack Debug in image_build_run.sh Test full version of Python configuration Remove debugging revert debug changes update pipfile.lock disable health checks that aren't working Add required Redis flags re-enable health check for storage remove redit config from settings file disable storage healthcheck test: remove all healthchecks other than the main one renable celery health checks Debug plugins remove plugins log line add additional debug lines disable celery plugins remove debug logging and commented out code run linter re-add redis config Try serving assets relative from the project root Enable Sentry APM Remove unused runtime.txt Revert "Remove unused runtime.txt" This reverts commit 0e7e48904f2c9486e141b594f9d1675372fc2d56. Revert health checks and static asset path Remove typed-ast update pipfile.lock remove comments from phases revert pipfile re-add health checks when not in dbt platform --- .copilot/config.yml | 4 ++++ .copilot/image_build_run.sh | 6 ++++++ .copilot/phases/build.sh | 4 ++++ .copilot/phases/install.sh | 4 ++++ .copilot/phases/post_build.sh | 4 ++++ .copilot/phases/pre_build.sh | 18 ++++++++++++++++++ Procfile | 1 - conf/settings.py | 31 +++++++++++++++++++++---------- runtime.txt | 1 + 9 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 .copilot/config.yml create mode 100755 .copilot/image_build_run.sh create mode 100644 .copilot/phases/build.sh create mode 100644 .copilot/phases/install.sh create mode 100644 .copilot/phases/post_build.sh create mode 100644 .copilot/phases/pre_build.sh create mode 100644 runtime.txt diff --git a/.copilot/config.yml b/.copilot/config.yml new file mode 100644 index 00000000..5570cb64 --- /dev/null +++ b/.copilot/config.yml @@ -0,0 +1,4 @@ +repository: lite/lite-hmrc +builder: + name: paketobuildpacks/builder-jammy-full + version: 0.3.339 diff --git a/.copilot/image_build_run.sh b/.copilot/image_build_run.sh new file mode 100755 index 00000000..233cc20b --- /dev/null +++ b/.copilot/image_build_run.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Exit early if something goes wrong +set -x + +# Add commands below to run inside the container after all the other buildpacks have been applied \ No newline at end of file diff --git a/.copilot/phases/build.sh b/.copilot/phases/build.sh new file mode 100644 index 00000000..7e96b6b0 --- /dev/null +++ b/.copilot/phases/build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +set -e + diff --git a/.copilot/phases/install.sh b/.copilot/phases/install.sh new file mode 100644 index 00000000..7e96b6b0 --- /dev/null +++ b/.copilot/phases/install.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +set -e + diff --git a/.copilot/phases/post_build.sh b/.copilot/phases/post_build.sh new file mode 100644 index 00000000..7e96b6b0 --- /dev/null +++ b/.copilot/phases/post_build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +set -e + diff --git a/.copilot/phases/pre_build.sh b/.copilot/phases/pre_build.sh new file mode 100644 index 00000000..fed34d03 --- /dev/null +++ b/.copilot/phases/pre_build.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e + +git_clone_base_url="https://codestar-connections.eu-west-2.amazonaws.com/git-http/730335529260/eu-west-2/192881c6-e3f2-41a9-9dcb-fcc87d8b90be/uktrade" + +git config --global credential.helper '!aws codecommit credential-helper $@' +git config --global credential.UseHttpPath true + +cat < ./.gitmodules +[submodule "django_db_anonymiser"] + path = django_db_anonymiser + url = $git_clone_base_url/django-db-anonymiser.git +EOF + +git submodule update --init --remote --recursive + +echo "done" diff --git a/Procfile b/Procfile index dc030945..0a7bb140 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,3 @@ -# See gunicorn.conf.py for more configuration. web: python manage.py migrate && gunicorn conf.wsgi:application celeryworker: celery -A conf worker -l info celerybeat: celery -A conf beat -l info diff --git a/conf/settings.py b/conf/settings.py index b555bf84..b7134e6f 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -49,18 +49,21 @@ "django.contrib.messages", "django.contrib.staticfiles", "mail", - # healthcheck app is for custom healthchecks in this app, health_check is django-health-check - "healthcheck", "health_check", - "health_check.db", - "health_check.cache", - "health_check.storage", - "health_check.contrib.migrations", - "health_check.contrib.celery", - "health_check.contrib.celery_ping", "django_db_anonymiser.db_anonymiser", ] +if not IS_ENV_DBT_PLATFORM: + INSTALLED_APPS += [ + "healthcheck", + "health_check.db", + "health_check.cache", + "health_check.storage", + "health_check.contrib.migrations", + "health_check.contrib.celery", + "health_check.contrib.celery_ping", + ] + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", @@ -230,6 +233,7 @@ environment=env.str("SENTRY_ENVIRONMENT"), integrations=[DjangoIntegration()], send_default_pii=True, + traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", 1.0), ) SENTRY_ENABLED = True else: @@ -322,8 +326,15 @@ def _build_redis_url(base_url, db_number, **query_args): } REDIS_BASE_URL = env("REDIS_BASE_URL", default=None) - CELERY_BROKER_URL = env("CELERY_BROKER_URL", default=None) - CELERY_RESULT_BACKEND = CELERY_BROKER_URL + REDIS_CELERY_DB = env("REDIS_CELERY_DB", default=0) + + if REDIS_BASE_URL: + is_redis_ssl = REDIS_BASE_URL.startswith("rediss://") + url_args = {"ssl_cert_reqs": "CERT_REQUIRED"} if is_redis_ssl else {} + + CELERY_BROKER_URL = _build_redis_url(REDIS_BASE_URL, REDIS_CELERY_DB, **url_args) + CELERY_RESULT_BACKEND = CELERY_BROKER_URL + CACHES = { "default": { "BACKEND": "django.core.cache.backends.redis.RedisCache", diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 00000000..8fdd9071 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.9