Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

DO NOT MERGE: Migration deploy #942

Merged
merged 38 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
504456c
update codeowners
cgsunkel Jul 10, 2024
42c5413
Add sample rate to sentry (#981)
cgsunkel Jul 10, 2024
46f79c6
Bump django from 4.2.13 to 4.2.14 (#982)
dependabot[bot] Jul 11, 2024
d5a3515
Add new fields to sentry config (#983)
cgsunkel Jul 11, 2024
72eb223
Remove migration actions (#984)
cgsunkel Jul 15, 2024
05ca172
Update Pingdom health check Database, Redis and Celery (#871)
marijnkampf Mar 28, 2024
5d757e8
DPM 202 asim formatter logging (#893)
marijnkampf Apr 23, 2024
7d1fb68
add build config file
acodeninja May 7, 2024
72c3f09
allow for running on gov.uk paas and dbt platform
acodeninja May 7, 2024
24a063f
allow any python 3.12 version
acodeninja May 7, 2024
2d63430
allow nodejs buildpack to be included
acodeninja May 7, 2024
6b27851
set nodejs version to 20.11
acodeninja May 7, 2024
2af3a60
add collect static command to build
acodeninja May 7, 2024
31ccaa0
do not use sentry when dsn unset
acodeninja May 7, 2024
e86c38d
add required variables for local build
acodeninja May 7, 2024
192093b
DPM 623 Update DB connection environment variable (#915)
marijnkampf May 8, 2024
20489a9
Update image_build for packaging.
markWarr May 14, 2024
c0872cb
Add extra env vars to image build.
markWarr May 14, 2024
d08d3f8
Adding Env vars
markWarr May 14, 2024
02008a2
Update env vars
markWarr May 14, 2024
7e13b30
Adding Env vars
markWarr May 14, 2024
9d71229
Added more env vars
markWarr May 14, 2024
ee3d400
More Env vars
markWarr May 14, 2024
6c726b7
More Env Vars
markWarr May 14, 2024
6cf6da3
Remove Duplicate Env Var
markWarr May 15, 2024
a021608
Added extra env var
markWarr May 15, 2024
117e1e5
fix: remove unnecessary start from package.json
markWarr May 21, 2024
d524a82
Update image_build_run.sh to include all env vars
markWarr May 22, 2024
f0594de
Add setuptools to requirements.txt
markWarr May 22, 2024
5fe0bb0
fix: try downgrade of python
markWarr May 23, 2024
d490be3
Reset migration for staging deploy
PippoRaimondiDIT Jun 3, 2024
e523328
Apply admin migration before enquiry (#933)
PippoRaimondiDIT Jun 3, 2024
e4cff24
Revert migration script changes (#941)
PippoRaimondiDIT Jun 4, 2024
7b4d3f3
Remove celery check from pingdom (#944)
PippoRaimondiDIT Jun 4, 2024
c81c2c3
fix: always call collectstatic
markWarr Jun 4, 2024
1787485
Add saas compilation to image build script
markWarr Jun 5, 2024
f489374
fix: update celery timezone
markWarr Jun 5, 2024
c135c2b
chore: update default timezone
markWarr Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
path: cypress/screenshots
docs-build:
docker:
- image: python:3.8
- image: python:3.12
steps:
- checkout
- dotenv/source:
Expand Down
4 changes: 4 additions & 0 deletions .copilot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
repository: emt
builder:
name: paketobuildpacks/builder-jammy-full
version: 0.3.339
103 changes: 103 additions & 0 deletions .copilot/image_build_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash

# Exit early if something goes wrong
set -e

# Add commands below to run inside the container after all the other buildpacks have been applied

export DEBUG="True"
export DJANGO_SECRET_KEY="supersecretkey"

# Database settings
export DATABASE_CREDENTIALS='{"username": "postgres", "password": "password", "engine": "postgres", "port": 5432, "dbname": "postgres", "host": "db", "dbInstanceIdentifier": "emt-db"}'

# Sentry
export DJANGO_SENTRY_DSN=""

export ENQUIRIES_PER_PAGE="10"
export ENQUIRY_RESPONSIVENESS_PERIOD_WEEKS="6"

# DataHub links
export DATA_HUB_FRONTEND="https://www.datahub.dev.uktrade.io"
export DATA_HUB_CREATE_COMPANY_PAGE_URL="https://www.datahub.dev.uktrade.io/companies/create"

# DataHub API variables when running Data Hub API locally on port 8000
export DATA_HUB_METADATA_URL="http://docker.for.mac.localhost:8000/v4/metadsuf"
export DATA_HUB_COMPANY_SEARCH_URL="http://docker.for.mac.localhost:8000/v4/search/company"
export DATA_HUB_CONTACT_SEARCH_URL="http://docker.for.mac.localhost:8000/v3/search/contact"
export DATA_HUB_CONTACT_CREATE_URL="http://docker.for.mac.localhost:8000/v3/contact"
export DATA_HUB_INVESTMENT_CREATE_URL="http://docker.for.mac.localhost:8000/v3/investment"
export DATA_HUB_ADVISER_SEARCH_URL="http://docker.for.mac.localhost:8000/adviser/"
export DATA_HUB_WHOAMI_URL="http://docker.for.mac.localhost:8000/whoami/"

# Hawk
export DATA_HUB_HAWK_ID="hawk-id"
export DATA_HUB_HAWK_KEY="hawk-key"

# Celery and Redis
export ENQUIRY_STATUS_UPDATE_INTERVAL_DAYS="1"
export ENQUIRY_STATUS_SHOULD_UPDATE="0"
export REDIS_BASE_URL="redis://redis:6379"
export CELERY_TIMEZONE="UTC"

# Staff SSO/OAuth2 settings
export FEATURE_ENFORCE_STAFF_SSO_ENABLED="1"

# Control Consent Service
export FEATURE_ENFORCE_CONSENT_SERVICE="1"

# The AUTHBROKER_URL needs to be accessible from the browser for the
# authorization redirect and also from the Docker container for the access token
# POST request, and the only way to do this is to use the
# docker.for.mac.localhost host provided by Docker.
export AUTHBROKER_URL="http://docker.for.mac.localhost:8080"
export AUTHBROKER_CLIENT_ID="contact-web-ops-for-details"
export AUTHBROKER_CLIENT_SECRET="contact-web-ops-for-details"
export AUTHBROKER_TOKEN_SESSION_KEY="_authbroker_token"
export AUTHBROKER_STAFF_SSO_SCOPE="dummy-scope"

export MOCK_SSO_TOKEN="dummy-token"
export MOCK_SSO_SCOPE="dummy-scope"
export MOCK_SSO_USERNAME="testuser"
export MOCK_SSO_EMAIL_USER_ID="testuser@example.com"
export COMPOSE_PROJECT_NAME="enquiry-mgmt-tool"

# Deny http for the OAuth flow
export OAUTHLIB_INSECURE_TRANSPORT="0"

# Activity Stream
export ACTIVITY_STREAM_ENQUIRY_POLL_INTERVAL_MINS="1"
export ACTIVITY_STREAM_KEY_ID="enquiry-mgmt-key-id"
export ACTIVITY_STREAM_KEY="enquiry-mgmt-secret-key"
export ACTIVITY_STREAM_SEARCH_URL="https://activity-stream/search"
export ACTIVITY_STREAM_SEARCH_TARGET_URL="/international/invest/contact/"
export ACTIVITY_STREAM_ENQUIRY_SEARCH_KEY1="enquiry-key-1"
export ACTIVITY_STREAM_ENQUIRY_SEARCH_VALUE1="enquiry-value-2"
export ACTIVITY_STREAM_ENQUIRY_SEARCH_KEY2="enquiry-key-2"
export ACTIVITY_STREAM_ENQUIRY_SEARCH_VALUE2="enquiry-value-2"
export ACTIVITY_STREAM_ENQUIRY_DATA_OBJ="enquiry-data-obj"

# Date from which enquiry data is to be fetched in AS
export ACTIVITY_STREAM_INITIAL_LOAD_DATE="01-January-2020"

# Settings for CSRF and Session cookies
export CSRF_COOKIE_SECURE="False"
export CSRF_COOKIE_HTTPONLY="False"
export SESSION_COOKIE_SECURE="False"
# SESSION_COOKIE_AGE=36000 # Optional, defaults to 32400 (9 hours)

# Set HSTS headers, only needs to be True in Production
export SET_HSTS_HEADERS="False"

export NON_RESPONSIVE_ENQUIRY_INITIAL_LOAD_DATE="01-April-2020"
export ACTIVITY_STREAM_SECOND_QUALIFICATION_SEARCH_NAME="enquiry-data-search-name"
export ACTIVITY_STREAM_SECOND_QUALIFICATION_SEARCH_VALUE="enquiry-data-search-value"

export ALLOW_TEST_FIXTURE_SETUP="allow"

echo "Running npm i"
npm i
echo "Running npm run sass"
npm run sass
echo "Running python manage.py collectstatic --noinput --traceback"
python manage.py collectstatic --noinput
34 changes: 0 additions & 34 deletions .github/workflows/update-migration-branch.yml

This file was deleted.

3 changes: 2 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* @uktrade/datahub
# * @uktrade/datahub
* @cgsunkel @marijnkampf @p3dr0migue1 @DeanElliott96 @bau123
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM python:3.12

RUN mkdir /usr/src/app
WORKDIR /usr/src/app
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: ./web.sh
web: bash web.sh
celery: celery -A app worker -l info
celerybeat: celery -A app beat -l info
Empty file.
26 changes: 0 additions & 26 deletions app/enquiries/ping.py

This file was deleted.

32 changes: 0 additions & 32 deletions app/enquiries/tests/test_ping_views.py

This file was deleted.

1 change: 1 addition & 0 deletions app/pingdom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Functionality for monitoring the uptime of the service."""
54 changes: 54 additions & 0 deletions app/pingdom/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.conf import settings
from django.db import DatabaseError
from redis import Redis

from app.enquiries.celery import app as celery_app
from app.enquiries.models import Enquiry


class CheckDatabase:
"""Check the database is up and running."""

name = "database"

def check(self):
"""Perform the check."""
try:
Enquiry.objects.exists()
return True, ""
except DatabaseError as exception:
return False, f"Pingdom check Database: {exception}"

Check warning on line 20 in app/pingdom/services.py

View check run for this annotation

Codecov / codecov/patch

app/pingdom/services.py#L16-L20

Added lines #L16 - L20 were not covered by tests


class CheckCelery:
name = "celery"

def check(self):
try:
insp = celery_app.control.inspect()
nodes = insp.stats()
if not nodes:
raise Exception("Celery is not running")
return True, ""
except Exception as exception:
return False, f"Pingdom check Celery: {exception}"

Check warning on line 34 in app/pingdom/services.py

View check run for this annotation

Codecov / codecov/patch

app/pingdom/services.py#L27-L34

Added lines #L27 - L34 were not covered by tests


class CheckRedis:
name = "redis"

def check(self):
try:
redis = Redis.from_url(settings.REDIS_BASE_URL)
if redis.ping():
return True, ""

Check warning on line 44 in app/pingdom/services.py

View check run for this annotation

Codecov / codecov/patch

app/pingdom/services.py#L41-L44

Added lines #L41 - L44 were not covered by tests
else:
return False, "Redis is not connected"
except Exception as exception:
return False, f"Pingdom check Redis: {exception}"

Check warning on line 48 in app/pingdom/services.py

View check run for this annotation

Codecov / codecov/patch

app/pingdom/services.py#L46-L48

Added lines #L46 - L48 were not covered by tests


services_to_check = (
CheckDatabase,
CheckRedis,
)
75 changes: 75 additions & 0 deletions app/pingdom/tests/test_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from unittest.mock import patch

from django.db import DatabaseError
from django.test import TestCase
from redis import RedisError

from app.pingdom.services import CheckCelery, CheckDatabase, CheckRedis


class PingdomServicesTestCase(TestCase):
def test_check_database_success(self):
check_database = CheckDatabase()
result = check_database.check()
assert check_database.name == "database"
assert result == (True, "")

def test_check_database_failure(self):
check_database = CheckDatabase()
with patch(
'app.enquiries.models.Enquiry.objects.exists',
side_effect=DatabaseError('No database'),
):
result = check_database.check()

assert result == (False, "Pingdom check Database: No database")

def test_check_celery_success(self):
check_celery = CheckCelery()
with patch(
'app.enquiries.celery.app.control.inspect.stats',
return_value=[{}]
):
result = check_celery.check()
assert check_celery.name == "celery"
assert result == (True, "")

def test_check_celery_failure(self):
check_celery = CheckCelery()
with patch(
'app.enquiries.celery.app.control.inspect.stats',
return_value=None
):
result = check_celery.check()

assert result == (False, "Pingdom check Celery: Celery is not running")

def test_check_redis_success(self):
check_redis = CheckRedis()
with patch(
'redis.Redis.ping',
return_value=True,
):
result = check_redis.check()
assert check_redis.name == "redis"
assert result == (True, "")

def test_check_redis_no_ping(self):
check_redis = CheckRedis()
with patch(
'redis.Redis.ping',
return_value=False,
):
result = check_redis.check()
assert check_redis.name == "redis"
assert result == (False, "Redis is not connected")

def test_check_redis_failure(self):
check_redis = CheckRedis()
with patch(
'redis.Redis.ping',
side_effect=RedisError("Redis error"),
):
result = check_redis.check()

assert result == (False, "Pingdom check Redis: Redis error")
Loading