Skip to content

Commit 3cf4f34

Browse files
AWS Paas Migration Changes (#1264)
* Configure application to run on DBT platform * clean-up of code prior to PR. Add is_copilot switch for instantiating s3 client * Update NodeJS buildpack workaround to only be present in Package.json --------- Co-authored-by: Emile Swarts <emile.swarts@digital.trade.gov.uk>
1 parent f5c0272 commit 3cf4f34

File tree

9 files changed

+39
-11
lines changed

9 files changed

+39
-11
lines changed

.copilot/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
repository: tariff-application/tamato
2+
builder:
3+
name: paketobuildpacks/builder-jammy-full
4+
version: 0.3.339

.copilot/image_build_run.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Add commands below to run inside the container after all the other buildpacks have been applied

.copilot/phases/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
set -e

.copilot/phases/install.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
set -e

.copilot/phases/post_build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
set -e

.copilot/phases/pre_build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
set -e

common/views.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import kombu.exceptions
1515
from botocore.exceptions import ClientError
1616
from botocore.exceptions import EndpointConnectionError
17+
from dbt_copilot_python.utility import is_copilot
1718
from django.conf import settings
1819
from django.contrib.auth.mixins import LoginRequiredMixin
1920
from django.contrib.auth.mixins import PermissionRequiredMixin
@@ -302,13 +303,20 @@ def check_celery_broker(self) -> Tuple[str, int]:
302303

303304
def check_s3(self) -> Tuple[str, int]:
304305
try:
305-
client = boto3.client(
306-
"s3",
307-
aws_access_key_id=settings.HMRC_PACKAGING_S3_ACCESS_KEY_ID,
308-
aws_secret_access_key=settings.HMRC_PACKAGING_S3_SECRET_ACCESS_KEY,
309-
endpoint_url=settings.S3_ENDPOINT_URL,
310-
region_name=settings.HMRC_PACKAGING_S3_REGION_NAME,
311-
)
306+
if is_copilot():
307+
client = boto3.client(
308+
"s3",
309+
endpoint_url=settings.S3_ENDPOINT_URL,
310+
region_name=settings.HMRC_PACKAGING_S3_REGION_NAME,
311+
)
312+
else:
313+
client = boto3.client(
314+
"s3",
315+
aws_access_key_id=settings.HMRC_PACKAGING_S3_ACCESS_KEY_ID,
316+
aws_secret_access_key=settings.HMRC_PACKAGING_S3_SECRET_ACCESS_KEY,
317+
endpoint_url=settings.S3_ENDPOINT_URL,
318+
region_name=settings.HMRC_PACKAGING_S3_REGION_NAME,
319+
)
312320
client.head_bucket(Bucket=settings.HMRC_PACKAGING_STORAGE_BUCKET_NAME)
313321
return "OK", 200
314322
except (ClientError, EndpointConnectionError):

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"clean": "rm -f ./run/static/webpack_bundles/*",
4545
"heroku-prebuild": "",
4646
"heroku-postbuild": "npm run build",
47+
"start": "bash scripts/web-worker-entrypoint.sh",
4748
"test": "jest",
4849
"lint:js": "npx eslint . --ext .jsx,.js",
4950
"lint:js:fix": "npx eslint . --ext .jsx,.js --fix",

settings/common.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,8 @@
324324

325325
# DBT PaaS
326326
elif is_copilot():
327-
DB_URL = dj_database_url.config(
328-
default=database_url_from_env("DATABASE_CREDENTIALS"),
329-
)
330-
DATABASES = {"default": DB_URL}
327+
DB_URL = database_url_from_env("DATABASE_CREDENTIALS")
328+
DATABASES = {"default": dj_database_url.parse(DB_URL)}
331329
# Govuk PaaS
332330
elif VCAP_SERVICES.get("postgres"):
333331
DB_URL = VCAP_SERVICES["postgres"][0]["credentials"]["uri"]

0 commit comments

Comments
 (0)