11# Deploying a new backend version
22
3- Once a release is built and deployed by CircleCI, deploy it to an environment using ArgoCD .
3+ The backend is deployed to AWS ECS (Elastic Container Service) with separate staging and production environments .
44
5- 1 . First, to connect to ArgoCD:
6- ```
7- kubectl -n argocd port-forward service/argocd-server 8443:443 &
8- open https://localhost:8443
5+ ## Building and Pushing Docker Images
6+
7+ Use the ` docker-build.sh ` script to build multi-architecture images and push to AWS ECR:
8+
9+ ``` bash
10+ # Build and push staging images
11+ ./docker-build.sh staging
12+
13+ # Build and push production images
14+ ./docker-build.sh prod
915```
10- 2 . login - credentials are in 1password, or ask someone for help
11- 3 . pick up the new version in staging.
12- - go to https://localhost:8443/applications/pyback-staging ,
13- - click the hamburger menu (3 dots, blue button), -> Details -> Parameters
14- - update the images field with the build ID as the tag, like: ` operationcode/back-end:staging-846 `
15- - as the new pods deploy, tail their logs to check for errors
16- - validate the staging environment (notes below)
17- 4 . repeat those steps for the production environment
16+
17+ This creates:
18+ - ` back-end:staging-amd64 ` and ` back-end:staging-arm64 ` images
19+ - A multi-arch manifest at ` back-end:staging `
20+
21+ ## Deploying to ECS
22+
23+ After images are pushed to ECR, deploy by updating the ECS service:
24+
25+ 1 . ** Update task definition** with new image tag
26+ 2 . ** Deploy to staging first** - Update ECS service to use new task definition
27+ 3 . ** Monitor logs** in CloudWatch or Sentry
28+ 4 . ** Validate staging** (see below)
29+ 5 . ** Deploy to production** - Repeat for production ECS service
30+
31+ ## Important: JWT Secret Key Migration
32+
33+ ** Before deploying these performance changes** , you must update the production ` JWT_SECRET_KEY ` environment variable:
34+
35+ 1 . Generate a new secret: ` openssl rand -base64 64 | tr -d '\n' `
36+ 2 . Set ` JWT_SECRET_KEY ` env var in ECS task definition to the generated string
37+ 3 . Remove ` JWT_PUBLIC_KEY ` env var (no longer needed with HS256)
38+
39+ ⚠️ ** This will log out all users** (one-time migration from RS256 to HS256)
1840
1941# Validating the staging environment
2042
@@ -25,33 +47,30 @@ When you run the front-end repo in localdev mode, it automatically connects to t
25472 . run the dev server: ` docker run -it -v ${PWD}:/src -w /src -p 127.0.0.1:3000:3000/tcp node:lts yarn dev --hostname 0.0.0.0 `
26483 . Connect to the dev server: ` open http://localhost:3000 `
2749
28- # Certificate management with certbot
50+ # Monitoring
2951
30- Certbot runs continously as a kube operator and refreshes certs for you. To ensure it is working,
31- check the logs of the ` cert-manager ` pod, like:
32- ```
33- kubectl -n cert-manager logs -f cert-manager-dcc48bf99-skhn7
34- ```
52+ ## Sentry Performance Monitoring
3553
36- Current version running is v0.10.1
54+ The application is instrumented with Sentry for error tracking and performance monitoring:
55+ - Error tracking with breadcrumbs and context
56+ - Transaction tracing for HTTP requests
57+ - Database query performance tracking
58+ - Python profiling for CPU-intensive operations
3759
38- if you need for some reason to upgrade:
39- 1 . read the release notes for all versions between current and desired, watch for breaking changes
40- 2 . ignore the instructions about helm and kubectly apply, one minor version at a time
41- ```
42- kubectl apply \
43- --validate=false \
44- -f https://github.com/jetstack/cert-manager/releases/download/v0.10.1/cert-manager.yaml
45- ```
60+ Configure via environment variables (see ` example.env ` ):
61+ - ` SENTRY_DSN ` - Sentry project DSN
62+ - ` SENTRY_TRACES_SAMPLE_RATE ` - Percentage of requests to trace (0.0-1.0)
63+ - ` SENTRY_PROFILES_SAMPLE_RATE ` - Percentage of transactions to profile (0.0-1.0)
4664
47- certificates installed:
48- ```
49- $ kubectl get Certificates --all-namespaces
50- NAMESPACE NAME READY SECRET AGE
51- monitoring grafana-tls True grafana-tls 299d
52- operationcode-staging back-end-tls True back-end-tls 264d
53- operationcode-staging resources-api-tls True resources-api-tls 299d
54- operationcode back-end-tls True back-end-tls 264d
55- operationcode resources-api-tls True resources-api-tls 299d
65+ ## CloudWatch Logs
66+
67+ Application logs are sent to CloudWatch Logs. Access via AWS Console or CLI:
68+
69+ ``` bash
70+ # View recent logs for staging
71+ aws logs tail /ecs/back-end-staging --follow
72+
73+ # View recent logs for production
74+ aws logs tail /ecs/back-end-production --follow
5675```
5776
0 commit comments