Skip to content

Commit c5c9234

Browse files
authored
feat: upgrade to postgres 17 (#90)
* feat: upgrade to postgres 17 * fix: postgres version * fix: add env var to not seek ssl in gha * chore: upgrade builder to v4 * fix: add concurrency * fix: concurrency * fix: concurrency * chore: trying to see if it lets me upgrade * fix: permissions * fix: revert back to previous name * chore: update parameter group for aurora version upgrades * fix: add missing version upgrade flag * aurora specific changes
1 parent 0c85713 commit c5c9234

File tree

9 files changed

+78
-58
lines changed

9 files changed

+78
-58
lines changed

.github/workflows/.builds.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build Containers
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tags:
7+
description: 'Tags to apply to the built containers multiline, separated by newlines'
8+
required: true
9+
type: string
10+
permissions:
11+
id-token: write # This is required for requesting the JWT
12+
contents: write # This is required for actions/checkout
13+
packages: write
14+
pull-requests: write
15+
security-events: write
16+
attestations: write # This is required for uploading attestations to the Security tab
17+
jobs:
18+
# https://github.com/bcgov/action-builder-ghcr
19+
builds:
20+
name: Builds
21+
runs-on: ubuntu-24.04
22+
strategy:
23+
matrix:
24+
# Only building frontend containers to run PR based e2e tests
25+
package: [backend, migrations, frontend]
26+
timeout-minutes: 10
27+
steps:
28+
- uses: bcgov/[email protected]
29+
with:
30+
package: ${{ matrix.package }}
31+
tags: ${{ inputs.tags }}
32+
tag_fallback: test

.github/workflows/.tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
timeout-minutes: 5
1919
services:
2020
postgres:
21-
image: postgres
21+
image: postgis/postgis:17-3.5 # Updated to PostgreSQL 17 with PostGIS 3.5
2222
env:
2323
POSTGRES_PASSWORD: default
2424
options: >-
@@ -29,9 +29,10 @@ jobs:
2929
ports:
3030
- 5432:5432
3131
steps:
32-
- uses: bcgov-nr/action-test-and-analyse@e2ba34132662c1638dbde806064eb7004b3761c3 # v1.3.0
32+
- uses: bcgov-nr/[email protected]
3333
env:
3434
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
35+
NODE_ENV: unittest
3536
with:
3637
commands: |
3738
npm ci
@@ -54,7 +55,7 @@ jobs:
5455
runs-on: ubuntu-24.04
5556
timeout-minutes: 5
5657
steps:
57-
- uses: bcgov/action-test-and-analyse@e2ba34132662c1638dbde806064eb7004b3761c3 # v1.3.0
58+
- uses: bcgov/[email protected]
5859
env:
5960
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
6061
with:

.github/workflows/pr-open.yml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,33 @@ on:
55

66
workflow_dispatch:
77

8-
concurrency:
9-
# Cancel in progress for PR open and close
10-
group: ${{ github.event.number || 'latest' }}
11-
cancel-in-progress: false
128
permissions:
139
id-token: write # This is required for requesting the JWT
1410
contents: write # This is required for actions/checkout
1511
packages: write
1612
pull-requests: write
1713
security-events: write
14+
attestations: write # This is required for uploading attestations to the Security tab
1815
env:
1916
AWS_REGION: ca-central-1
2017
jobs:
2118
# https://github.com/bcgov-nr/action-builder-ghcr
2219
builds:
23-
name: Builds
24-
runs-on: ubuntu-24.04
25-
strategy:
26-
matrix:
27-
package: [backend, migrations, frontend]
28-
timeout-minutes: 10
29-
steps:
30-
- uses: bcgov-nr/action-builder-ghcr@ec30e4ce1ac3c25c93ec26cf370ecba028dc478e # v3.0.1
31-
with:
32-
package: ${{ matrix.package }}
33-
tags: |
34-
${{ github.event.number || 'manual' }}
35-
latest
36-
pr-${{ github.event.number || 'manual' }}
37-
tag_fallback: latest
38-
triggers: ('${{ matrix.package }}/')
39-
20+
concurrency:
21+
# Cancel in progress for PR open and close
22+
group: builds-${{ github.event.number || 'latest' }}
23+
cancel-in-progress: true
24+
uses: ./.github/workflows/.builds.yml
25+
with:
26+
tags: |
27+
${{ github.event.number || 'manual' }}
28+
latest
29+
4030
plan-stack:
4131
name: Plan Stack
32+
concurrency:
33+
group: plan-stack-${{ github.event.number || 'latest' }}
34+
cancel-in-progress: false
4235
uses: ./.github/workflows/.deploy_stack.yml
4336
with:
4437
environment_name: dev
@@ -50,18 +43,28 @@ jobs:
5043
tests:
5144
name: Tests
5245
needs: builds
46+
concurrency:
47+
# Cancel in progress for PR open and close
48+
group: tests-${{ github.event.number || 'latest' }}
49+
cancel-in-progress: true
5350
uses: ./.github/workflows/.tests.yml
5451
with:
5552
tag: ${{ github.event.number || 'latest' }}
5653
resume-resources-dev:
5754
name: Resume Resources Dev
5855
if: (github.event_name == 'workflow_dispatch')
56+
concurrency:
57+
group: rrd-${{ github.event.number || 'latest' }}
58+
cancel-in-progress: false
5959
needs: [builds]
6060
uses: ./.github/workflows/resume-resources.yml
6161
secrets: inherit
6262
deploy-to-dev:
6363
name: Deploy to Dev
6464
if: (github.event_name == 'workflow_dispatch')
65+
concurrency:
66+
group: deploy-dev-${{ github.event.number || 'latest' }}
67+
cancel-in-progress: false
6568
needs: [resume-resources-dev]
6669
uses: ./.github/workflows/.deploy_stack.yml
6770
with:
@@ -72,6 +75,9 @@ jobs:
7275
secrets: inherit
7376
results:
7477
name: PR Results
78+
concurrency:
79+
group: pr-results-${{ github.event.number || 'latest' }}
80+
cancel-in-progress: true
7581
needs: [builds, plan-stack, tests]
7682
if: always()
7783
runs-on: ubuntu-24.04

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Prerequisites:
128128

129129
1. Install JDK 17 and above.
130130
2. Install Node.js 22 and above.
131-
3. Install Postgres 16.4 with Postgis extension.
131+
3. Install Postgres 17.4 with Postgis extension.
132132
4. Download flyway.jar file
133133
Once all the softwares are installed follow below steps.
134134

backend/src/prisma.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const DB_PWD = encodeURIComponent(process.env.POSTGRES_PASSWORD || "default"); /
77
const DB_PORT = process.env.POSTGRES_PORT || 5432;
88
const DB_NAME = process.env.POSTGRES_DATABASE || "postgres";
99
const DB_SCHEMA = process.env.POSTGRES_SCHEMA || "app";
10-
const dataSourceURL = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5`;
10+
// SSL settings for PostgreSQL 17+ which requires SSL by default
11+
const SSL_MODE = (process.env.NODE_ENV === 'local' || 'unittest') ? 'prefer' : 'require'; // 'require' for aws deployments, 'prefer' for local development or ut in gha
12+
const dataSourceURL = `postgresql://${DB_USER}:${DB_PWD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?schema=${DB_SCHEMA}&connection_limit=5&sslmode=${SSL_MODE}`;
1113

1214
@Injectable({ scope: Scope.DEFAULT})
1315
class PrismaService extends PrismaClient<Prisma.PrismaClientOptions, 'query'> implements OnModuleInit, OnModuleDestroy {

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ x-postgres-vars: &postgres-vars
1616

1717
services:
1818
database:
19-
image: postgis/postgis:16-3.4 # if using crunchy , make sure to align with crunchy version, currently it is at 16 and postgis 3.3
19+
image: postgis/postgis:17-3.5 # Updated to PostgreSQL 17 with PostGIS 3.4
2020
container_name: database
2121
environment:
2222
<<: *postgres-vars
@@ -38,7 +38,6 @@ services:
3838
depends_on:
3939
database:
4040
condition: service_healthy
41-
4241
schemaspy:
4342
image: schemaspy/schemaspy:6.2.4
4443
profiles: ["schemaspy"]

infrastructure/api/ecs.tf

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ resource "aws_ecs_task_definition" "flyway_task" {
4848
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
4949
task_role_arn = aws_iam_role.app_container_role.arn
5050
container_definitions = jsonencode([
51-
{
51+
{
5252
name = "${var.app_name}-flyway"
5353
image = "${var.flyway_image}"
54-
essential = true
54+
essential = true
5555
environment = [
5656
{
5757
name = "FLYWAY_URL"
58-
value = "jdbc:postgresql://${data.aws_rds_cluster.rds_cluster.endpoint}/${var.db_name}"
58+
value = "jdbc:postgresql://${data.aws_rds_cluster.rds_cluster.endpoint}/${var.db_name}?sslmode=require"
5959
},
6060
{
6161
name = "FLYWAY_USER"
@@ -196,12 +196,11 @@ resource "aws_ecs_task_definition" "node_api_task" {
196196
name = "POSTGRES_DATABASE"
197197
value = var.db_name
198198
},
199-
{
199+
{
200200
name = "POSTGRES_SCHEMA"
201201
value = "${var.db_schema}"
202-
}
203-
,
204-
{
202+
},
203+
{
205204
name = "PORT"
206205
value = "3000"
207206
}

infrastructure/database/aurora-v2.tf

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,7 @@ resource "aws_db_subnet_group" "db_subnet_group" {
2525

2626
data "aws_rds_engine_version" "postgresql" {
2727
engine = "aurora-postgresql"
28-
version = "16.8"
29-
}
30-
31-
resource "aws_db_parameter_group" "db_postgresql" {
32-
name = "${var.db_cluster_name}-parameter-group"
33-
family = "aurora-postgresql16"
34-
description = "${var.db_cluster_name}-parameter-group"
35-
tags = {
36-
managed-by = "terraform"
37-
}
38-
}
39-
40-
resource "aws_rds_cluster_parameter_group" "db_postgresql" {
41-
name = "${var.db_cluster_name}-cluster-parameter-group"
42-
family = "aurora-postgresql16"
43-
description = "${var.db_cluster_name}-cluster-parameter-group"
44-
tags = {
45-
managed-by = "terraform"
46-
}
28+
version = "17.4"
4729
}
4830

4931

@@ -67,14 +49,14 @@ EOF
6749
module "aurora_postgresql_v2" {
6850
source = "terraform-aws-modules/rds-aurora/aws"
6951
version = "9.14.0"
70-
52+
allow_major_version_upgrade = true
7153
name = var.db_cluster_name
7254
engine = data.aws_rds_engine_version.postgresql.engine
7355
engine_mode = "provisioned"
7456
engine_version = data.aws_rds_engine_version.postgresql.version
7557
storage_encrypted = true
7658
database_name = var.db_database_name
77-
59+
7860
vpc_id = data.aws_vpc.main.id
7961
vpc_security_group_ids = [data.aws_security_group.data.id]
8062
db_subnet_group_name = aws_db_subnet_group.db_subnet_group.name
@@ -92,8 +74,6 @@ module "aurora_postgresql_v2" {
9274
skip_final_snapshot = true
9375
auto_minor_version_upgrade = false
9476

95-
db_parameter_group_name = aws_db_parameter_group.db_postgresql.id
96-
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.db_postgresql.id
9777
deletion_protection = contains(["prod"], var.app_env) ? true : false
9878
serverlessv2_scaling_configuration = {
9979
min_capacity = var.min_capacity

infrastructure/frontend/outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ output "cloudfront" {
33
value = {
44
domain_name = aws_cloudfront_distribution.s3_distribution.domain_name
55
distribution_id = aws_cloudfront_distribution.s3_distribution.id
6+
url= "https://${aws_cloudfront_distribution.s3_distribution.domain_name}"
67
}
78
}
89

0 commit comments

Comments
 (0)