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

feat: use cnpg in dev/preprod #3034

Merged
merged 21 commits into from
Dec 20, 2023
1 change: 1 addition & 0 deletions .env.dev.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DOMIFA_ENV_ID=dev
POSTGRES_USERNAME=domifa_user
POSTGRES_PASSWORD=xxxxxxxxxxxxxxxxxxx
POSTGRES_DATABASE=domifa_dev
POSTGRES_SSL=false
2 changes: 2 additions & 0 deletions .kontinuous/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ projectName: domifa
dependencies:
fabrique:
import: socialgouv/kontinuous/plugins/fabrique
extends:
- name: buildkit-service
dependencies:
contrib:
preDeploy:
Expand Down
1 change: 1 addition & 0 deletions .kontinuous/env/dev/templates/backend.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data:
DOMIFA_EMAILS_ENABLE: "true"
DOMIFA_SMS_ENABLED: "false"
POSTGRES_LOGGING: "schema,migration"
POSTGRES_SSL: "true"
DOMIFA_FRONTEND_META_ROBOTS: noindex,nofollow
DOMIFA_SENTRY_ENABLED: "true"
DOMIFA_LOG_HTTP_REQUESTS: "true"
Expand Down
27 changes: 13 additions & 14 deletions .kontinuous/env/dev/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
global:
pgSecretName: pg-app

pg:
# this force ce PG cluster to be destroyed on redeploys
~preDeploy.cleaner:
match:
kind: Cluster
value: true

jobs:
runs:
build-backend:
Expand All @@ -7,25 +17,14 @@ jobs:
DOMIFA_PORTAIL_ADMINS_URL: https://admin-{{ .Values.global.host }}/
DOMIFA_PORTAIL_USAGERS_URL: https://mon-{{ .Values.global.host }}/
DOMIFA_FRONTEND_URL: https://{{ .Values.global.host }}/

drop-db:
use: drop-db
with:
pgAdminUserSecretRefName: azure-pg-admin-user-devflex
create-db:
~needs: [drop-db]
use: create-db
with:
pgAdminUserSecretRefName: azure-pg-admin-user-devflex
useAzureFlex: "true"
seed:
~needs: [backend]
~needs: [backend] # need backend to run migrations
use: seed-db
with:
seedPath: _scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql

backend:
~needs: [create-db, build-backend]
~needs: [build-backend, pg]
volumes:
- name: files
emptyDir: {}
Expand All @@ -34,4 +33,4 @@ backend:
name: files

backend-cron:
~needs: [create-db, build-backend]
~needs: [backend]
1 change: 1 addition & 0 deletions .kontinuous/env/preprod/templates/backend.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data:
# emails redirigés vers l'adresse configurée pour DOMIFA_EMAIL_ADDRESS_REDIRECT_ALL_TO
DOMIFA_EMAILS_ENABLE: "true"
DOMIFA_SMS_ENABLED: "true"
POSTGRES_SSL: "true"
# 50 connexions en tout à partager entre la preprod + les environnements de dev :
# https://docs.microsoft.com/fr-fr/azure/postgresql/concepts-limits
POSTGRES_POOL_MAX_CONNEXIONS: "50"
Expand Down
16 changes: 13 additions & 3 deletions .kontinuous/env/preprod/values.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
global:
pgSecretName: pg-app
revolunet marked this conversation as resolved.
Show resolved Hide resolved

pg-metabase:
~chart: pg

backend:
host: "api-{{ .Values.global.host }}"
~needs: [build-backend, pg]
addVolumes:
- files
envFrom:
- secretRef:
name: pg-user-devflex
name: pg-app
- secretRef:
name: backend-sealed-secret
- configMapRef:
Expand All @@ -15,9 +22,10 @@ backend:
name: domifa-encryption-key

backend-cron:
~needs: [backend]
envFrom:
- secretRef:
name: pg-user-devflex
name: pg-app
- secretRef:
name: backend-sealed-secret
- configMapRef:
Expand All @@ -34,11 +42,13 @@ portail-usagers:

metabase:
enabled: true
~chart: metabase
~needs: [pg-metabase]
ingress:
enabled: false
envFrom:
- secretRef:
name: metabase
name: pg-metabase-app

oauth2-proxy:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions .kontinuous/env/prod/templates/backend.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data:
DOMIFA_PRINT_CONFIG: "false"
DOMIFA_EMAILS_ENABLE: "true"
DOMIFA_SMS_ENABLED: "true"
POSTGRES_SSL: "true"
# 50 connexions max : https://docs.microsoft.com/fr-fr/azure/postgresql/concepts-limits
POSTGRES_POOL_MAX_CONNEXIONS: "100"
DOMIFA_FRONTEND_META_ROBOTS: index,follow
Expand Down
6 changes: 6 additions & 0 deletions .kontinuous/env/prod/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
PRODUCTION: "true"
DOMIFA_FRONTEND_META_ROBOTS: index,follow

pg:
~chart: pg
cnpg-cluster:
persistence:
size: "50Gi"

backend-cron:
replicas: 1
addVolumes:
Expand Down
10 changes: 3 additions & 7 deletions .kontinuous/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pg:
~chart: pg

backend:
~chart: app
~needs: [build-backend]
Expand Down Expand Up @@ -221,10 +224,3 @@ jobs:
DOMIFA_BACKEND_URL: "https://api-{{ .Values.global.host }}/"
DOMIFA_SENTRY_DSN_PORTAIL: "https://[email protected]/58"
DOMIFA_FRONTEND_META_ROBOTS: noindex,nofollow

deactivate:
jobs-deactivate:
runs:
deactivate:
with:
db: true
revolunet marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
POSTGRES_DB: ${POSTGRES_DATABASE}
POSTGRES_USER: ${POSTGRES_USERNAME}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_SSL: "false"
env_file:
- ./.env
healthcheck:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
POSTGRES_DB: domifa_test
POSTGRES_USER: domifa_user
POSTGRES_PASSWORD: xxxxxxxxxxxxxxxxxxx
POSTGRES_SSL: "false"
env_file: ./.env.dev.example.env
healthcheck:
retries: 5
Expand Down
1 change: 1 addition & 0 deletions packages/backend/.env.backend.dev.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DOMIFA_ENV_PRESET=local-dev.preset.env
POSTGRES_USERNAME=domifa_user
POSTGRES_PASSWORD=xxxxxxxxxxxxxxxxxxx
POSTGRES_DATABASE=domifa_dev
POSTGRES_SSL=false

# POSTGRES_LOGGING=warn
# POSTGRES_LOGGING=query,schema,migration
Expand Down
1 change: 1 addition & 0 deletions packages/backend/.env.backend.test.local.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DOMIFA_ENV_PRESET=local-test.preset.env
POSTGRES_USERNAME=domifa_user
POSTGRES_PASSWORD=xxxxxxxxxxxxxxxxxxx
POSTGRES_DATABASE=domifa_test
POSTGRES_SSL=false

# JWT SECRET:
DOMIFA_SECURITY_JWT_SECRET=9Ibl1P3XxNJOqaWTnvBpCVw8o1kFoSwiUwL8NETPfMMZY0f2BG0tgZNdTbYRwLfwRjfaqaHISvOqhQL7nGpmES73V0vgR3tUQeyvnI8gsKTFFJJPYqLIbBCLiXT8LKx5Q3tJirYI0zM4Joby2SkYv9QxqwaMKZGxYjJrU5WHTmUnk6c4GL6w1rk5sI
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/config/domifaConfig.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("loadConfig", () => {
POSTGRES_USERNAME: "value POSTGRES_USERNAME",
POSTGRES_PASSWORD: "value POSTGRES_PASSWORD",
POSTGRES_DATABASE: "value POSTGRES_DATABASE",
POSTGRES_SSL: false,
DOMIFA_SECURITY_JWT_SECRET: "******************",
};
const env = loadEnvWithPreset({ defaultEnv });
Expand All @@ -28,6 +29,7 @@ describe("loadConfig", () => {
expect(config.postgres.username).toEqual(env.POSTGRES_USERNAME);
expect(config.postgres.password).toEqual(env.POSTGRES_PASSWORD);
expect(config.postgres.database).toEqual(env.POSTGRES_DATABASE);
expect(config.postgres.ssl).toEqual(env.POSTGRES_SSL);

expect(config.upload.basePath).toBeDefined();

Expand All @@ -43,6 +45,7 @@ describe("loadConfig", () => {
POSTGRES_USERNAME: "value POSTGRES_USERNAME",
POSTGRES_PASSWORD: "value POSTGRES_PASSWORD",
POSTGRES_DATABASE: "value POSTGRES_DATABASE",
POSTGRES_SSL: false,
DOMIFA_SECURITY_JWT_SECRET: "******************",
};
const env = loadEnvWithPreset({ defaultEnv });
Expand All @@ -61,6 +64,7 @@ describe("loadConfig", () => {
expect(config.postgres.username).toEqual(env.POSTGRES_USERNAME);
expect(config.postgres.password).toEqual(env.POSTGRES_PASSWORD);
expect(config.postgres.database).toEqual(env.POSTGRES_DATABASE);
expect(config.postgres.ssl).toEqual(env.POSTGRES_SSL);

expect(config.upload.basePath).toBeDefined();

Expand All @@ -80,6 +84,7 @@ describe("loadConfig", () => {
POSTGRES_USERNAME: "value POSTGRES_USERNAME",
POSTGRES_PASSWORD: "value POSTGRES_PASSWORD",
POSTGRES_DATABASE: "value POSTGRES_DATABASE",
POSTGRES_SSL: false,
DOMIFA_SECURITY_JWT_SECRET: "******************",
DOMIFA_FRONTEND_URL: "https://domifa.xxx",
DOMIFA_PORTAIL_USAGERS_URL: "https://mon-domifa.xxx",
Expand Down Expand Up @@ -108,6 +113,7 @@ describe("loadConfig", () => {
expect(config.postgres.username).toEqual(env.POSTGRES_USERNAME);
expect(config.postgres.password).toEqual(env.POSTGRES_PASSWORD);
expect(config.postgres.database).toEqual(env.POSTGRES_DATABASE);
expect(config.postgres.ssl).toEqual(env.POSTGRES_SSL);

expect(config.upload.basePath).toBeDefined();

Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/config/domifaConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export function loadConfig(x: Partial<DomifaEnv>): DomifaConfig {
username: configParser.parseString(x, "POSTGRES_USERNAME"),
password: configParser.parseString(x, "POSTGRES_PASSWORD"),
database: configParser.parseString(x, "POSTGRES_DATABASE"),
ssl: configParser.parseBoolean(x, "POSTGRES_SSL", {
required: false,
defaultValue: false,
}),
logging: configTypeOrmLoggerParser.getTypeormLoggerOptions(
x,
"POSTGRES_LOGGING"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type DomifaConfigPostgres = {
username: string; // POSTGRES_USERNAME
password: string; // POSTGRES_PASSWORD
database: string; // POSTGRES_DATABASE
ssl: boolean; // POSTGRES_SSL
logging: LoggerOptions; // POSTGRES_LOGGING
poolMaxConnections: number; // POSTGRES_POOL_MAX_CONNEXIONS
};
1 change: 1 addition & 0 deletions packages/backend/src/config/model/DomifaEnv.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type DomifaEnv = {
POSTGRES_USERNAME: string;
POSTGRES_PASSWORD: string;
POSTGRES_DATABASE: string;
POSTGRES_SSL: boolean;
POSTGRES_LOGGING: string;
POSTGRES_POOL_MAX_CONNEXIONS: string;
DOMIFA_TYPEORM_RUN_ON_STARTUP: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const PG_CONNECT_OPTIONS: PostgresConnectionOptions = {
username: domifaConfig().postgres.username,
password: domifaConfig().postgres.password,
database: domifaConfig().postgres.database,
ssl: domifaConfig().postgres.ssl
? {
rejectUnauthorized: false,
}
: false,
logger: new CustomTypeOrmLogger(
domifaConfig().envId !== "test"
? domifaConfig().logger.logSqlRequests
Expand Down
Loading