You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following guide will get you up and running and developing/debugging CHEFS as quickly as possible.
4
-
We provide a [`devcontainer`](https://containers.dev) and will use [`VS Code`](https://code.visualstudio.com) to illustrate.
3
+
Please refer to the online [CHEFS Techdocs](https://developer.gov.bc.ca/docs/default/component/chefs-techdocs/):
5
4
6
-
By no means is CHEFS development limited to these tools; they are merely examples.
7
-
8
-
## Caveats
9
-
10
-
The primary use case for this `devcontainer` is for developing, debugging and unit testing CHEFS source code.
11
-
12
-
There are limitations running this devcontainer, such as all networking is within this container. This container has [docker-in-docker](https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/docker-in-docker.md) which allows running demos, building docker images, running `docker compose` all within this container.
13
-
14
-
## Files
15
-
16
-
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.
17
-
18
-
In order to run CHEFS you require Postgresql (seeded) and the CHEFS backend/API and frontend/UX - optionally you will use a [NATS](https://nats.io/) server for event streaming. Previously, this was a series of downloads and configuration updates and numerous commands to run. See `.devcontainer/chefs_local` files.
19
-
20
-
**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`.
21
-
22
-
Also included are convenient launch tasks to run and debug CHEFS.
23
-
24
-
## Open CHEFS in the devcontainer
25
-
26
-
To open CHEFS in a devcontainer, we open the _root_ of this repository. We can open in 2 ways:
27
-
28
-
1. Open Visual Studio Code, and use the Command Palette and use `Dev Containers: Open Folder in Container...`
29
-
2. Open Visual Studio Code and `File|Open Folder...`, you should be prompted to `Reopen in Container`.
30
-
31
-
## Running CHEFS locally
32
-
33
-
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.
34
-
35
-
CHEFS API and Frontend are running as node applications on the devcontainer - again, ports are forwarded to the host.
36
-
37
-
### Configuring CHEFS locally
38
-
39
-
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.
40
-
41
-
### Authorization Prerequisites
42
-
43
-
1. An IDIR account is required to access CHEFS.
44
-
45
-
### Run/Debug
46
-
47
-
1. start Postgresql and NATS. Many ways to start...
48
-
- right click on `.devcontainer/chefs_local/docker-compose.yml` and select `Compose up`
49
-
- or use command palette `Docker: Compose Up` then select `.devcontainer/chefs_local/docker-compose.yml`
50
-
- or `Terminal | Run Task...|chefs_local up`
51
-
2. start CHEFS
52
-
- Run and Debug, select 'CHEFS' which will start both the API and the frontend.
53
-
3. debug Frontend with Chrome
54
-
- Run and Debug, select 'CHEFS Frontend - chrome' which will start a Chrome browser against the frontend, will allow breakpoints in `/app/frontend/src`
55
-
4. stop Postgresql and NATS. Many ways to stop...
56
-
- right click on `.devcontainer/chefs_local/docker-compose.yml` and select `Compose down`
57
-
- or use command palette `Docker: Compose Down` then select `.devcontainer/chefs_local/docker-compose.yml`
58
-
- or `Terminal | Run Task...|chefs_local down`
59
-
60
-
_Notes_
61
-
62
-
-`CHEFS Frontend` launch configuration is using the `chefs-frontend-localhost-5300` client in Keycloak, not `chefs-frontend-xxxx` client as we do in production.
63
-
-`CHEFS API` will use the configuration found at `.devcontainer/chefs_local/local.json`
64
-
-`Postgres DB`: localhost:5432
65
-
-`CHEFS Frontend`: http://localhost:5173/app
66
-
-`CHEFS API`: http://localhost:5173/app/api/v1
67
-
68
-
## Formio Components
69
-
70
-
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`.
71
-
72
-
## KNEX - Database tools
73
-
74
-
[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.
75
-
76
-
### create a migration file
77
-
78
-
This will create a stub file with a timestamp. You will populate the up and down methods to add/update/delete database objects.
79
-
80
-
```
81
-
cd app
82
-
knex migrate:make my_new_migration_script
83
-
> Created Migration: /workspaces/common-hosted-form-service/app/src/db/migrations/20240119172630_my_new_migration_script.js
84
-
```
85
-
86
-
### rollback previous migration
87
-
88
-
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.
89
-
90
-
#### run the migration(s)
91
-
92
-
```
93
-
cd app
94
-
knex migrate:latest
95
-
> Batch 2 run: 1 migrations
96
-
```
97
-
98
-
#### rollback the migration(s)
99
-
100
-
```
101
-
cd app
102
-
knex migrate:rollback
103
-
> Batch 2 rolled back: 1 migrations
104
-
```
105
-
106
-
Please review the [knex](https://knexjs.org) for more detail and how to leverage the tool.
107
-
108
-
## Troubleshooting
109
-
110
-
All development machines are unique and here we will document problems that have been encountered and how to fix them.
111
-
112
-
### Failure during load of devcontainer when running webpack (Segmentation Fault)
113
-
114
-
Encountered on Mac Ventura 13.6, with Mac Docker Desktop 4.26.1 when running `npm run build:formio` on load, we hit a `Segmentation Fault`. The issue was resolved when turning off the virtualization settings in Docker Desktop.
115
-
116
-
Under Settings, select `gRPC Fuse` instead of `VirtioFS` then unselect `Use Virtualization framework`. Restart Docker and VS Code.
5
+
-[CHEFS Development with Dev Container](https://developer.gov.bc.ca/docs/default/component/chefs-techdocs/Developer/Contributors/CHEFS-Development-with-Dev-Container/)
0 commit comments