Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paas-migration #487

Open
wants to merge 94 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
4975f12
TSS-2214-trs-dbt-migration-setup-environment-variables-to-be-compatib…
osimuka Nov 14, 2024
95b1f1c
Import error
chris-pettinga Nov 18, 2024
42e1f38
TSS-2213 - TRS DBT Migration - Upgrade backing services (#485)
chris-pettinga Nov 18, 2024
92f307f
fix-local-docker-deploy (#488)
osimuka Dec 4, 2024
191f373
poetry update
osimuka Dec 8, 2024
c251130
making sure that local dev runs (#490)
osimuka Dec 17, 2024
2cc4508
Merge branch 'master' into paas-migration
osimuka Jan 27, 2025
df2ce9f
fixing merge conflicts
osimuka Jan 27, 2025
1c8dd83
trigger deployment
ajuddin Feb 10, 2025
ce853b6
Added copilot config to the codebase
ajuddin Feb 10, 2025
37e6d4b
Testing deploy pipeline
NickFitz Feb 10, 2025
63ea106
Merge remote-tracking branch 'origin/paas-migration' into paas-migration
NickFitz Feb 10, 2025
04d8f42
Update entry.sh
ajuddin Feb 11, 2025
6b6fe60
testing api build
ajuddin Feb 11, 2025
ce5eb90
added debug command to the entrypoint
ajuddin Feb 11, 2025
1d6b9ad
Trigger deploy
emileswarts Feb 10, 2025
809d90b
Trigger deploy
emileswarts Feb 11, 2025
bd477d7
Don't restrict hosts on DBT Platform
emileswarts Feb 11, 2025
15d5149
Install 'packs' buildpack
emileswarts Feb 11, 2025
ec1ab59
test
irenegrandeh Feb 11, 2025
059a618
Remove unused buildpack
irenegrandeh Feb 11, 2025
e956166
Run collectstatic at build time
irenegrandeh Feb 11, 2025
900500c
Change manage.py path
irenegrandeh Feb 11, 2025
51c5ed9
Populate environment variables required to build static assets
irenegrandeh Feb 11, 2025
fc54f45
Provide `DATABASE_URL` value during build stage.
NickFitz Feb 12, 2025
e19e573
Testing `DATABASE_URL` value during build stage.
NickFitz Feb 12, 2025
9493cbe
Try `localhost` in `DATABASE_URL` value during build stage.
NickFitz Feb 12, 2025
684fd68
Try to find DB usage during build stage.
NickFitz Feb 12, 2025
0d84463
Log stuff from building.
NickFitz Feb 12, 2025
bf68e6b
Log stuff from building.
NickFitz Feb 12, 2025
4183512
Log stuff from building again.
NickFitz Feb 12, 2025
93b7cd6
Logging not working…
NickFitz Feb 12, 2025
0ae105e
Stack trace suggests running `manage.py` is at root of error…
NickFitz Feb 12, 2025
5f5efcf
Temporarily force healthcheck to always be happy so the checks can be…
NickFitz Feb 13, 2025
2a9d6e7
Temporarily add healthcheck path at `pingdom/ping.xml`.
NickFitz Feb 13, 2025
ea8c24b
Add SSL requirement to Celery Broker URL.
NickFitz Feb 13, 2025
bd0889e
Ensure `OPENSEARCH_URI` is populated in non-VCAP environments.
NickFitz Feb 13, 2025
66bc41c
Set default Opensearch port.
NickFitz Feb 13, 2025
bcdb9d3
Add Opensearch port to URI.
NickFitz Feb 13, 2025
053c1ee
Re-enable healthcheck for those parts that work.
NickFitz Feb 13, 2025
f71b473
Remove temporary Pingdom healthcheck URL.
NickFitz Feb 13, 2025
308869f
Reinstate OpenSearch healthcheck
emileswarts Feb 14, 2025
fd0f419
Don't do health checks on Celery
emileswarts Feb 14, 2025
7d1f6d7
Bump timeout on Opensearch healthcheck
emileswarts Feb 14, 2025
e439324
Add debugging for health checks
emileswarts Feb 14, 2025
8b7395c
Disable opensearch health check
emileswarts Feb 14, 2025
9793f7d
Add debugging for opensearch health check
emileswarts Feb 18, 2025
0095d90
Re-enable opensearch check
emileswarts Feb 18, 2025
77bb614
Trigger deploy
emileswarts Feb 18, 2025
9e53026
Trigger deploy
emileswarts Feb 18, 2025
12808b0
Increase timeout for OpenSearch healthcheck and add debugging
emileswarts Feb 18, 2025
907a6c5
Add more debugging
emileswarts Feb 18, 2025
5a5a2f5
Don't resque error from opensearch check
emileswarts Feb 18, 2025
79e639f
Add debugging
emileswarts Feb 18, 2025
b6589d5
Try to format the error info a bit more.
NickFitz Feb 18, 2025
c468184
Comment out rsomethign triggering recursion in `ping_opensearch`.
NickFitz Feb 18, 2025
2555253
See when we're pinging OS.
NickFitz Feb 18, 2025
a48b5d9
Return fake response from `ping_opensearch`.
NickFitz Feb 18, 2025
f39ebb7
Add debug logging
emileswarts Feb 19, 2025
a5d609f
Return only elapsed seconds for debugging
emileswarts Feb 19, 2025
777b523
Reset to original health check and don't resque errors
emileswarts Feb 19, 2025
4b5ed6a
Bump timeout on Opensearch check
emileswarts Feb 19, 2025
a23abc3
Run just opensearch check
emileswarts Feb 19, 2025
ebe9e7d
Print stacktrace when pinging opensearch
emileswarts Feb 19, 2025
d66df0c
Debug requests error on ssl
emileswarts Feb 19, 2025
eeb23c7
Print error when requesting https
emileswarts Feb 19, 2025
747a51b
Print traceback
emileswarts Feb 19, 2025
88292b2
Update stacktrace printing
emileswarts Feb 19, 2025
1b7daec
Don't monkeypatch workers
emileswarts Feb 19, 2025
2bcc6e4
Monkeypatch gevent before importing requests
emileswarts Feb 19, 2025
d5c2f71
Restore post_fork function
emileswarts Feb 19, 2025
797580a
Remove psycogreen monkeypatching.
NickFitz Feb 20, 2025
65d8ebf
Patch psycopg2 at gunicorn config load rather than in `post_fork()`.
NickFitz Feb 20, 2025
2533918
Patch psycopg2 in `post_fork()`.
NickFitz Feb 20, 2025
1c4e1c8
Remove attempted monkeypatching of gevent.
NickFitz Feb 20, 2025
baa5e61
It's a miracle! Maybe…
NickFitz Feb 20, 2025
5bb32c1
Fix copilot repo name.
NickFitz Feb 20, 2025
1e572dd
Restore temporarily disabled healthcheck functions.
NickFitz Feb 20, 2025
47eb30e
Trigger deploy
emileswarts Feb 21, 2025
dae9046
Trigger build
emileswarts Feb 24, 2025
c1f3aca
Trigger deploy
emileswarts Feb 24, 2025
bf84299
Trigger deploy
emileswarts Feb 24, 2025
3b42cc9
Trigger deploy
emileswarts Feb 24, 2025
fc7d73a
Setup health check for Celery
emileswarts Feb 24, 2025
1f28b43
update dbt copilot version
james-francis-MT Feb 24, 2025
8190686
Configure location of `celerybeat-schedule`.
NickFitz Feb 25, 2025
6e24484
Update repository name
emileswarts Feb 25, 2025
2139e38
Trigger deploy
emileswarts Feb 25, 2025
461f0f2
Trigger deploy
emileswarts Feb 25, 2025
d840be3
Trigger deploy
emileswarts Feb 25, 2025
8b2b9db
comentig out opensearch healthcheck to allow debug
ajuddin Feb 26, 2025
f41e43d
re-enable opensearch health check
james-francis-MT Feb 26, 2025
7ae21fc
Merge remote-tracking branch 'origin/master' into paas-migration
james-francis-MT Feb 26, 2025
ac78dec
Test deployment
NickFitz Feb 27, 2025
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
13 changes: 8 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ commands:
command: |
python3 -m venv venv
echo ". venv/bin/activate" >> $BASH_ENV
. venv/bin/activate #
. venv/bin/activate
pip install --upgrade pip
pip install poetry==1.6.1
poetry export --dev --without-hashes -f requirements.txt -o requirements-dev.txt
poetry export --with dev --without-hashes -f requirements.txt -o requirements-dev.txt
pip install -r requirements-dev.txt

restore_dependency_cache:
description: "Restore dependency cache."
steps:
- restore_cache:
key: deps2-{{ .Branch }}-{{ checksum "requirements-dev.txt" }}
keys:
- deps2-{{ .Branch }}-{{ checksum "requirements-dev.txt" }}
- deps2-{{ .Branch }}-
- deps2-

save_dependency_cache:
description: "Save dependency cache."
Expand All @@ -32,7 +35,7 @@ commands:
jobs:
code_quality:
docker:
- image: cimg/python:3.9.5
- image: cimg/python:3.9.20
steps:
- checkout
- restore_dependency_cache
Expand All @@ -48,7 +51,7 @@ jobs:
pflake8 trade_remedies_api --config pyproject.toml
test_and_fitness_functions:
docker:
- image: cimg/python:3.9.5
- image: cimg/python:3.9.20
environment:
DATABASE_URL: psql://ubuntu@localhost:5432/trade_remedies
DJANGO_SETTINGS_MODULE: config.settings.test
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: api
builder:
name: paketobuildpacks/builder-jammy-base
version: 0.4.240
10 changes: 10 additions & 0 deletions .copilot/image_build_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

export CASE_WORKER_ENVIRONMENT_KEY="example"
export DJANGO_SECRET_KEY="example"
export PUBLIC_ENVIRONMENT_KEY="example"
export DATABASE_URL=psql://postgres:postgres@localhost:5432/trade_remedies

#python ./trade_remedies_api/manage.py collectstatic --noinput
6 changes: 6 additions & 0 deletions .copilot/phases/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Exit early if something goes wrong
set -e

# Add commands below to run as part of the build phase
6 changes: 6 additions & 0 deletions .copilot/phases/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Exit early if something goes wrong
set -e

# Add commands below to run as part of the install phase
6 changes: 6 additions & 0 deletions .copilot/phases/post_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Exit early if something goes wrong
set -e

# Add commands below to run as part of the post_build phase
23 changes: 23 additions & 0 deletions .copilot/phases/pre_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Exit early if something goes wrong
set -e

if [ -f "./.gitmodules" ]; then
echo ".gitmodules file exists. Modifying URLs..."
account_id=$(echo $CODESTAR_CONNECTION_ARN | cut -d':' -f5)
connection_id=$(echo $CODESTAR_CONNECTION_ARN | cut -d'/' -f2)
git_clone_base_url="https://codestar-connections.eu-west-2.amazonaws.com/git-http/$account_id/eu-west-2/$connection_id/uktrade"

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

sed -i "s|url = [email protected]:uktrade/\(.*\).git|url = $git_clone_base_url/\1.git|g" ./.gitmodules

git submodule update --init --remote --recursive

else
echo ".gitmodules file does not exist. No URLs to update."
fi

# Add commands below to run as part of the pre_build phase
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9.15
FROM python:3.9.20

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
Expand All @@ -11,3 +11,5 @@ RUN pip install -r requirements-dev.txt

ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
ADD . /app
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ help:
@echo -e "$(COLOUR_YELLOW)make prod-requirements$(COLOUR_NONE) : Generate prod requirements (requires local pip-compile)"

all-requirements:
poetry lock
poetry export --without-hashes -f requirements.txt -o requirements.txt
poetry export --with dev --without-hashes -f requirements.txt -o requirements-dev.txt
pip install -r requirements-dev.txt
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: scripts/entry.sh
celery_worker: cd trade_remedies_api && celery -A config worker -l $CELERY_LOGLEVEL
celery_beat: cd trade_remedies_api && celery -A config beat -l $CELERY_LOGLEVEL
celery_beat: cd trade_remedies_api && celery -A config beat -l $CELERY_LOGLEVEL -s /tmp/celerybeat-schedule
45 changes: 25 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@ version: "3"
services:
api:
build:
context: .
context: .
ports:
- "8000:8000"
volumes:
- ./trade_remedies_api:/app/
- ./requirements.in:/app/requirements.in/
- ./requirements:/app/requirements/
- ./requirements-dev.txt:/app/requirements-dev.txt
env_file:
- local.env
command: python manage.py runserver 0.0.0.0:8000
command: >
/bin/sh -c "
python manage.py migrate &&
python manage.py load_sysparams &&
python manage.py notify_env &&
python manage.py collectstatic --noinput &&
python manage.py runserver 0.0.0.0:8000
"
environment:
- DJANGO_SETTINGS_MODULE=config.settings.local
depends_on:
- postgres
celery:
build:
context: .
Expand All @@ -25,21 +33,10 @@ services:
environment:
- DJANGO_SETTINGS_MODULE=config.settings.local
- DATABASE_URL=psql://postgres:postgres@postgres:5432/trade_remedies
apitest:
build:
context: .
ports:
- "8003:8000"
volumes:
- ./trade_remedies_api:/app/
env_file:
- local.env
command: python manage.py runserver 0.0.0.0:8000
environment:
- DJANGO_SETTINGS_MODULE=config.settings.bdd
- DATABASE_URL=psql://postgres:postgres@postgres:5432/trade_remedies_api_test
depends_on:
- api
postgres:
image: postgres:12
image: postgres:17
ports:
- "5432:5432"
volumes:
Expand All @@ -48,10 +45,18 @@ services:
environment:
POSTGRES_DB: trade_remedies
POSTGRES_PASSWORD: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 2s
timeout: 2s
retries: 5

redis:
image: redis:alpine
image: redis:7.4.1
command: ["redis-server", "--save", ""] # Disable RDB snapshot saving
ports:
- "6379:6379"

opensearch:
image: opensearchproject/opensearch:2.13.0
restart: unless-stopped
Expand All @@ -61,4 +66,4 @@ services:
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=odR$YG8t$fcLe5X3
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=coRrecth0rseba++ery9.23.2007staple$
Binary file modified fitness/fitness_metrics.db
Binary file not shown.
5 changes: 5 additions & 0 deletions pii-ner-exclude.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
linux
ENV PYTHONDONTWRITEBYTECODE 1
update -y && apt
PUB
ref
" Returns the mime type for this file
Expand Down Expand Up @@ -2192,3 +2195,5 @@ django-db-geventpool==4.0.0
Holborn
the third party
terminated_at
GUNICORN_ACCESS_LOG_FORMAT
GUNICORN_ENABLE_ASYNC_PSYCOPG2
Loading