Skip to content

Commit

Permalink
Merge branch 'bcgov:main' into fix/FORMS-1654-make-print-visible-to-p…
Browse files Browse the repository at this point in the history
…ublic
  • Loading branch information
bhuvan-aot authored Jan 7, 2025
2 parents 5333674 + 51fa134 commit e330974
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 3,706 deletions.
26 changes: 13 additions & 13 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ There are limitations running this devcontainer, such as all networking is withi

The `.devcontainer` folder contains the `devcontainer.json` file which defines this container. We are using a `Dockerfile` and `post-install.sh` to build and configure the container run image. The `Dockerfile` is simple but in place for simplifying image enhancements. The `post-install.sh` will install the required node libraries for CHEFS including the frontend and formio components.

In order to run CHEFS you require Keycloak (configured), Postgresql (seeded) and the CHEFS backend/API and frontend/UX. Previously, this was a series of downloads and configuration updates and numerous commands to run. See `.devcontainer/chefs_local` files.
In order to run CHEFS you require Postgresql (seeded) and the CHEFS backend/API and frontend/UX. Previously, this was a series of downloads and configuration updates and numerous commands to run. See `.devcontainer/chefs_local` files.

**NODE_CONFIG_DIR** to simplify loading a default configuration to the CHEFS infrastructure (Keycloak, Postgresql, etc), we set an environment variable [`NODE_CONFIG_DIR`](https://github.com/node-config/node-config/wiki/Environment-Variables#node_config_dir). This supercedes the files found under `app/config`. Running node apps and commands (ex. knex, launch configurations) will use this environment variable and load configuration from `.devcontainer/chefs_local`.
**NODE_CONFIG_DIR** to simplify loading a default configuration to the CHEFS infrastructure (Postgresql, etc), we set an environment variable [`NODE_CONFIG_DIR`](https://github.com/node-config/node-config/wiki/Environment-Variables#node_config_dir). This supercedes the files found under `app/config`. Running node apps and commands (ex. knex, launch configurations) will use this environment variable and load configuration from `.devcontainer/chefs_local`.

Also included are convenient launch tasks to run and debug CHEFS.

Expand All @@ -30,43 +30,38 @@ To open CHEFS in a devcontainer, we open the _root_ of this repository. We can o

## Running CHEFS locally

Keycloak and Postgresql will be launched using docker compose. These will run inside of the devcontainer (docker-in-docker) but the ports are forwarded to the host machine and are accessible on the local host.
Postgresql will be launched using docker compose. These will run inside of the devcontainer (docker-in-docker) but the ports are forwarded to the host machine and are accessible on the local host.

CHEFS API and Frontend are running as node applications on the devcontainer - again, ports are forwarded to the host.

### Configuring CHEFS locally

When the devcontainer is built, it copies `.devcontainer/chefs_local/local.json.sample` and `.devcontainer/chefs_local/realm-export.json.sample` to `.devcontainer/chefs_local/local.json` and `.devcontainer/chefs_local/realm-export.json` respectively. These copies are not checked in and allow the developer to make changes and tweaks without impacting other developers or accidentially committing passwords.
When the devcontainer is built, it copies `.devcontainer/chefs_local/local.sample.json` to `.devcontainer/chefs_local/local.json`. This copy is not checked in and allows the developer to make changes and tweaks without impacting other developers or accidentially committing passwords.

### Authorization Prerequisites

1. An IDIR account is required to access CHEFS.
2. Request an SSO Integration from the Common Hosted Single Sign-on (CSS) page in order to obtain a resource and secret that will be used for authentication when building CHEFS. View the [detailed documentation](https://bcdevex.atlassian.net/wiki/spaces/CCP/pages/961675282) about requesting the Pathfinder SSO integration.
3. Open realm-export.json located at build/docker/imports/keycloak and search for `XXXXXXXXXXXX`. This value must match the `clientSecret` value in `local.json` so that the CHEFS API can connect to your Keycloak instance. By default, these are set to be equal and don’t need to be altered.
4. Navigate to the CSS page, login with your IDIR, and download the ‘Development’ Installation JSON from your SSO Integration.
5. Back in the `realm-export.json` file, search for all instances of `YYYYYYYYYYYY` and replace it with the `resource` you obtained from the downloaded JSON file. Search for all instances of `ZZZZZZZZZZZZ` and replace it with the `secret`.

### Run/Debug

1. start Keycloak and Postgresql. Many ways to start...
1. start Postgresql. Many ways to start...
- right click on `.devcontainer/chefs_local/docker-compose.yml` and select `Compose up`
- or use command palette `Docker: Compose Up` then select `.devcontainer/chefs_local/docker-compose.yml`
- or `Terminal | Run Task...|chefs_local up`
2. start CHEFS
- Run and Debug, select 'CHEFS' which will start both the API and the frontend.
3. debug Frontend with Chrome
- Run and Debug, select 'CHEFS Frontend - chrome' which will start a Chrome browser against the frontend, will allow breakpoints in `/app/frontend/src`
4. stop Keycloak and Postgresql. Many ways to stop...
4. stop Postgresql. Many ways to stop...
- right click on `.devcontainer/chefs_local/docker-compose.yml` and select `Compose down`
- or use command palette `Docker: Compose Down` then select `.devcontainer/chefs_local/docker-compose.yml`
- or `Terminal | Run Task...|chefs_local down`

_Notes_

- `CHEFS Frontend` launch configuration is using the `chefs-frontend-local` client in Keycloak, not `chefs-frontend` client as we do in production.
- `CHEFS Frontend` launch configuration is using the `chefs-frontend-localhost-5300` client in Keycloak, not `chefs-frontend-xxxx` client as we do in production.
- `CHEFS API` will use the configuration found at `.devcontainer/chefs_local/local.json`
- `Postgres DB`: localhost:5432
- `Keycloak Admin console`: http://localhost:8082 - username/password = admin/admin
- `CHEFS Frontend`: http://localhost:5173/app
- `CHEFS API`: http://localhost:5173/app/api/v1

Expand All @@ -75,9 +70,11 @@ _Notes_
If you are developing the formio components, you should build and redeploy them before running your local debug instances of CHEFS. Use tasks `Components build` and `Components Deploy`.

## KNEX - Database tools

[knex](https://knexjs.org) is installed globally and should be run from the `/app` directory where the knex configuration is located. Use knex to stub out migrations or to rollback migrations as you are developing.

### create a migration file

This will create a stub file with a timestamp. You will populate the up and down methods to add/update/delete database objects.

```
Expand All @@ -87,16 +84,19 @@ knex migrate:make my_new_migration_script
```

### rollback previous migration
When developing your migrations, you may find it useful to run the migration and roll it back if it isn't exactly what you expect to happen.

When developing your migrations, you may find it useful to run the migration and roll it back if it isn't exactly what you expect to happen.

#### run the migration(s)

```
cd app
knex migrate:latest
> Batch 2 run: 1 migrations
```

#### rollback the migration(s)

```
cd app
knex migrate:rollback
Expand Down
26 changes: 0 additions & 26 deletions .devcontainer/chefs_local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,3 @@ services:
- POSTGRES_USER=app
- POSTGRES_PASSWORD=admin
- POSTGRES_DB=chefs
chefs-keycloak:
image: quay.io/keycloak/keycloak:17.0.1
volumes:
- type: bind
source: ./realm-export.json
target: /tmp/realm-export.json
read_only: true
ports:
- 8082:8082
environment:
- DB_VENDOR=POSTGRES
- DB_ADDR=postgres
- DB_USER=admin
- DB_PASSWORD=admin
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
depends_on:
- postgres
restart: unless-stopped
command:
- "start-dev"
- "--http-port=8082"
- "-Dkeycloak.migration.action=import"
- "-Dkeycloak.migration.provider=singleFile"
- "-Dkeycloak.migration.file=/tmp/realm-export.json"
- "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING"
112 changes: 0 additions & 112 deletions .devcontainer/chefs_local/local.json.sample

This file was deleted.

111 changes: 111 additions & 0 deletions .devcontainer/chefs_local/local.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"db": {
"database": "chefs",
"host": "localhost",
"port": "5432",
"username": "app",
"password": "admin"
},
"files": {
"uploads": {
"enabled": "true",
"fileCount": "1",
"fileKey": "files",
"fileMaxSize": "25MB",
"fileMinSize": "0KB",
"path": "files"
},
"permanent": "localStorage",
"localStorage": {
"path": "myfiles"
},
"objectStorage": {
"accessKeyId": "bcgov-citz-ccft",
"bucket": "chefs",
"endpoint": "https://commonservices.objectstore.gov.bc.ca",
"key": "chefs/dev/",
"secretAccessKey": "anything"
}
},
"frontend": {
"apiPath": "api/v1",
"basePath": "/app",
"oidc": {
"clientId": "chefs-frontend-localhost-5300",
"realm": "standard",
"serverUrl": "https://dev.loginproxy.gov.bc.ca/auth",
"logoutUrl": "https://logon7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https%3A%2F%2Fdev.loginproxy.gov.bc.ca%2Fauth%2Frealms%2Fstandard%2Fprotocol%2Fopenid-connect%2Flogout"
}
},
"server": {
"apiPath": "/api/v1",
"basePath": "/app",
"bodyLimit": "30mb",
"oidc": {
"realm": "standard",
"serverUrl": "https://dev.loginproxy.gov.bc.ca/auth",
"jwksUri": "https://dev.loginproxy.gov.bc.ca/auth/realms/standard/protocol/openid-connect/certs",
"issuer": "https://dev.loginproxy.gov.bc.ca/auth/realms/standard",
"audience": "chefs-frontend-localhost-5300",
"maxTokenAge": "300"
},
"logLevel": "http",
"port": "8080",
"rateLimit": {
"public": {
"limitApiKey": "120",
"limitFrontend": "500",
"windowMs": "60000"
}
},
"encryption": {
"proxy": "352f7c24819086bf3df5a38c1a40586045f73e0007440c9d27d59ee8560e3fe7"
}
},
"eventStreamService": {
"servers": "localhost:4222,localhost:4223,localhost:4224",
"websockets": "false",
"streamName": "CHEFS",
"source": "chefs-local",
"domain": "forms",
"username": "chefs",
"password": "password",
"maxAge": "300000",
"maxBytes": "1048576",
"maxMsgs": "10",
"maxMsgSize": "51200",
"duplicateWindow": "60000",
"numReplicas": "3"
},
"serviceClient": {
"commonServices": {
"ches": {
"endpoint": "https://ches-dev.api.gov.bc.ca/api",
"tokenEndpoint": "https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token",
"clientId": "CHES_CLIENT_ID",
"clientSecret": "CHES_CLIENT_SECRET"
},
"cdogs": {
"endpoint": "https://cdogs-dev.api.gov.bc.ca/api",
"tokenEndpoint": "https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token",
"clientId": "CDOGS_CLIENT_ID",
"clientSecret": "CDOGS_CLIENT_SECRET"
}
}
},
"customBcAddressFormioComponent": {
"apikey": "xxxxxxxxxxxxxxx",
"bcAddressURL": "https://geocoder.api.gov.bc.ca/addresses.json",
"queryParameters": {
"echo": false,
"brief": true,
"minScore": 55,
"onlyCivic": true,
"maxResults": 15,
"autocomplete": true,
"matchAccuracy": 100,
"matchPrecision": "occupant, unit, site, civic_number, intersection, block, street, locality, province",
"precisionPoints": 100
}
}
}
Loading

0 comments on commit e330974

Please sign in to comment.