From f320f72759b85534c405c047c09f0e479d3ddcca Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Fri, 27 Sep 2024 16:28:06 -0700 Subject: [PATCH 01/13] Use gnu-getopt on Macs --- README.md | 4 ++++ scripts/do-args.sh | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 69e21de8..1041631c 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ If it installed correctly you can run `node -v` and it will display the correct Execute the following command to initialize your local environment and start the required Docker containers. > If you run into errors with a Mac it is most likely a script needs execute permission. +> +> You will also need to install coreutils and gnu-getopt using [Homebrew](https://brew.sh): +> +> brew install coreutils gnu-getopt ```bash # Generate .env files. diff --git a/scripts/do-args.sh b/scripts/do-args.sh index e08b4808..1b969b34 100755 --- a/scripts/do-args.sh +++ b/scripts/do-args.sh @@ -4,6 +4,14 @@ # PIPESTATUS with a simple $?, but I don’t do that. set -o errexit -o pipefail -o noclobber -o nounset +# Check for Mac OS first, and use gnu-getopt if so. The built-in getopt is not +# the same as the GNU version, and it does not support long options. +if [ "$(uname)" == "Darwin" ]; then + echo 'Note: Mac OS X detected. Using gnu-getopt. If you do not have this' \ + 'installed, run `brew install gnu-getopt`.' + export PATH="$(brew --prefix gnu-getopt)/bin:$PATH" +fi + # -allow a command to fail with !’s side effect on errexit # -use return value from ${PIPESTATUS[0]}, because ! hosed $? ! getopt --test > /dev/null From 63a102e5b38ded2795f1d1149b0b26a4dd57f4dc Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Wed, 6 Nov 2024 13:45:58 -0800 Subject: [PATCH 02/13] Add log message --- src/api/Keycloak/CssHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/Keycloak/CssHelper.cs b/src/api/Keycloak/CssHelper.cs index 58a39fdd..dd07f63a 100644 --- a/src/api/Keycloak/CssHelper.cs +++ b/src/api/Keycloak/CssHelper.cs @@ -155,6 +155,8 @@ private Task AddOrUpdateUserAsync(string username, Entities.User? user, HSB.CSS. } // Fetch the roles for the user + _logger.LogDebug("User activation: Fetching roles for user: {key}", key); + var userRoles = await _cssService.GetRolesForUserAsync(key.ToString()); if (userRoles.Users.Length > 1) throw new NotAuthorizedException($"Keycloak has multiple users with the same username '{key}'"); if (user == null) From 982ade08ce5ddeabfcd0cd05c55bf184081040a2 Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Wed, 6 Nov 2024 13:47:14 -0800 Subject: [PATCH 03/13] Add .sln file to .gitignore --- src/api/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/.gitignore b/src/api/.gitignore index eabafcfa..923863eb 100644 --- a/src/api/.gitignore +++ b/src/api/.gitignore @@ -27,6 +27,7 @@ TestResults/ *.user *.userosscache *.sln.docstates +api.sln # Build results **/[Dd]ebug/ From d49c15e4e570762cb3757f74f72e2394eb1a48cd Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Wed, 6 Nov 2024 14:38:31 -0800 Subject: [PATCH 04/13] Tweak text (mainly to test deployment) --- src/dashboard/src/app/login/page.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dashboard/src/app/login/page.tsx b/src/dashboard/src/app/login/page.tsx index 6c20f9a5..3cd9d590 100644 --- a/src/dashboard/src/app/login/page.tsx +++ b/src/dashboard/src/app/login/page.tsx @@ -29,10 +29,10 @@ export default function Page() {

Need access to the Storage Dashboard?

- Please email michael.tessier@gov.bc.ca to request - access to your organization's dashboard. + Please email michael.tessier@gov.bc.ca to + request access to your organization's dashboard.

-

If you are a first time user please note:

+

If you are a first time user, please note:

  • Your first login will include a registration step within the BCGov Single Sign-On From b934b672f02e8cc7afa96c8c5e8dc7c90e33991c Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 18 Nov 2024 14:06:47 -0800 Subject: [PATCH 05/13] Revert ignoring of .sln file --- src/api/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/.gitignore b/src/api/.gitignore index 923863eb..eabafcfa 100644 --- a/src/api/.gitignore +++ b/src/api/.gitignore @@ -27,7 +27,6 @@ TestResults/ *.user *.userosscache *.sln.docstates -api.sln # Build results **/[Dd]ebug/ From d88b76fa9743637f335fbc26a5989b34185d33ab Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:34:41 -0800 Subject: [PATCH 06/13] Set rulers to match prettier printWidth setting --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5762b7c3..54815c10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,4 +8,7 @@ "notebook.codeActionsOnSave": { "source.organizeImports": true, }, + "editor.rulers": [ + 100 + ] } From bf7a6dfc8c765b186ce0562d2d4c279826cd4424 Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:35:21 -0800 Subject: [PATCH 07/13] Update emails --- devops/kustomize/base/data-service/config-map.yaml | 8 ++++---- .../overlays/dev/data-service/kustomization.yaml | 2 +- devops/kustomize/overlays/dev/kustomization.yaml | 2 +- .../overlays/prod/data-service/kustomization.yaml | 2 +- devops/kustomize/overlays/prod/kustomization.yaml | 2 +- .../overlays/test/data-service/kustomization.yaml | 2 +- devops/kustomize/overlays/test/kustomization.yaml | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/devops/kustomize/base/data-service/config-map.yaml b/devops/kustomize/base/data-service/config-map.yaml index 3e39a0f8..3773bc01 100644 --- a/devops/kustomize/base/data-service/config-map.yaml +++ b/devops/kustomize/base/data-service/config-map.yaml @@ -15,7 +15,7 @@ metadata: created-by: jeremy.foster data: API_URL: http://api:8080 - ENVIRONMENT: "DEV" + ENVIRONMENT: 'DEV' --- kind: ConfigMap apiVersion: v1 @@ -35,6 +35,6 @@ data: AUTH_URL: https://loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token HOST_URI: https://ches.api.gov.bc.ca/api/v1 FROM: Hosting Service Dashboard - TO: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca - EMAIL_ENABLED: "true" - EMAIL_AUTHORIZED: "true" + TO: frank@plotandscatter.com,michael.tessier@gov.bc.ca + EMAIL_ENABLED: 'true' + EMAIL_AUTHORIZED: 'true' diff --git a/devops/kustomize/overlays/dev/data-service/kustomization.yaml b/devops/kustomize/overlays/dev/data-service/kustomization.yaml index b48c892a..93d3295d 100644 --- a/devops/kustomize/overlays/dev/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/dev/data-service/kustomization.yaml @@ -40,7 +40,7 @@ patches: value: Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca + value: frank@plotandscatter.com - op: replace path: /data/ENVIRONMENT value: DEV diff --git a/devops/kustomize/overlays/dev/kustomization.yaml b/devops/kustomize/overlays/dev/kustomization.yaml index 6662fc3a..71629bcf 100644 --- a/devops/kustomize/overlays/dev/kustomization.yaml +++ b/devops/kustomize/overlays/dev/kustomization.yaml @@ -52,7 +52,7 @@ patches: value: (DEV) Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca + value: frank@plotandscatter.com - target: kind: ConfigMap name: dashboard diff --git a/devops/kustomize/overlays/prod/data-service/kustomization.yaml b/devops/kustomize/overlays/prod/data-service/kustomization.yaml index cb79081d..40a7cc2b 100644 --- a/devops/kustomize/overlays/prod/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/prod/data-service/kustomization.yaml @@ -40,7 +40,7 @@ patches: value: Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + value: frank@plotandscatter.com,michael.tessier@gov.bc.ca - op: replace path: /data/ENVIRONMENT value: PROD diff --git a/devops/kustomize/overlays/prod/kustomization.yaml b/devops/kustomize/overlays/prod/kustomization.yaml index 62d1442a..03b3ecdf 100644 --- a/devops/kustomize/overlays/prod/kustomization.yaml +++ b/devops/kustomize/overlays/prod/kustomization.yaml @@ -52,7 +52,7 @@ patches: value: Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + value: frank@plotandscatter.com,michael.tessier@gov.bc.ca - target: kind: ConfigMap name: dashboard diff --git a/devops/kustomize/overlays/test/data-service/kustomization.yaml b/devops/kustomize/overlays/test/data-service/kustomization.yaml index 4f584f97..70f68405 100644 --- a/devops/kustomize/overlays/test/data-service/kustomization.yaml +++ b/devops/kustomize/overlays/test/data-service/kustomization.yaml @@ -40,7 +40,7 @@ patches: value: Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + value: frank@plotandscatter.com,michael.tessier@gov.bc.ca - op: replace path: /data/ENVIRONMENT value: TEST diff --git a/devops/kustomize/overlays/test/kustomization.yaml b/devops/kustomize/overlays/test/kustomization.yaml index 291f92e8..d40e3d60 100644 --- a/devops/kustomize/overlays/test/kustomization.yaml +++ b/devops/kustomize/overlays/test/kustomization.yaml @@ -52,7 +52,7 @@ patches: value: (TEST) Hosting Service Dashboard - op: replace path: /data/TO - value: jeremy.foster@fosol.ca,michael.tessier@gov.bc.ca + value: frank@plotandscatter.com,michael.tessier@gov.bc.ca - target: kind: ConfigMap name: dashboard From 41aed4d1ce9620ed3c3087cb1d53065fc84b8c9d Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:39:14 -0800 Subject: [PATCH 08/13] Document data-service command --- scripts/help.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/help.sh b/scripts/help.sh index c0d2857f..eabfa963 100755 --- a/scripts/help.sh +++ b/scripts/help.sh @@ -16,6 +16,8 @@ nuke: Teardown w ssh: {service} SSH into docker container go: Open a browser and view app +data-service: Run the data service + npm-install: Install latest npm packages locally. tool-update: Updates the dotnet tool (default ef) From 0f363f682da8ff57e79fd0ffd6e534dad667f4ed Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:40:18 -0800 Subject: [PATCH 09/13] Tweaks to support macOS --- scripts/db-migration.sh | 23 ++++++++++++++++------- scripts/variables.sh | 10 +++++++++- src/api/Dockerfile | 4 ++-- src/dashboard/Dockerfile.prod | 4 ++-- src/data-service/Dockerfile | 4 ++-- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/scripts/db-migration.sh b/scripts/db-migration.sh index b57518c6..799cee4e 100755 --- a/scripts/db-migration.sh +++ b/scripts/db-migration.sh @@ -4,26 +4,35 @@ MNAME=$1; FILE1=./Migrations/$(basename ./Migrations/*_$MNAME.cs); echo "Updating migration '$FILE1'"; -sed -i "2iusing HSB.DAL;" $FILE1; +# Check for Mac OS first, and use gsed if so. The built-in getopt is not +# the same as the GNU version, and it does not support long options. +if [ "$(uname)" == "Darwin" ]; then + echo 'Note: Mac OS X detected. Using gsed. If you do not have this' \ + 'installed, run `brew install gsed`.' + SED_CMD=gsed +else + SED_CMD=sed +fi + +${SED_CMD} -i "2iusing HSB.DAL;" $FILE1; search=":\ Migration"; replace=":\ PostgresSeedMigration"; -sed -i "s/$search/$replace/" $FILE1; +${SED_CMD} -i "s/$search/$replace/" $FILE1; fl1=$(grep -n "protected override void Up(MigrationBuilder migrationBuilder)" $FILE1 | head -n 1 | cut -d: -f1); l1=$(($fl1 + 2)); -sed -i "${l1}i\ \ \ \ \ \ \ \ \ \ \ \ PreUp(migrationBuilder);" $FILE1; +${SED_CMD} -i "${l1}i\ \ \ \ \ \ \ \ \ \ \ \ PreUp(migrationBuilder);" $FILE1; fl=$(grep -n "protected override void Down(MigrationBuilder migrationBuilder)" $FILE1 | head -n 1 | cut -d: -f1); l2=$(($fl - 3)); -sed -i "${l2}i\ \ \ \ \ \ \ \ \ \ \ \ PostUp(migrationBuilder);" $FILE1; +${SED_CMD} -i "${l2}i\ \ \ \ \ \ \ \ \ \ \ \ PostUp(migrationBuilder);" $FILE1; l3=$(($fl + 3)); -sed -i "${l3}i\ \ \ \ \ \ \ \ \ \ \ \ PreDown(migrationBuilder);" $FILE1; +${SED_CMD} -i "${l3}i\ \ \ \ \ \ \ \ \ \ \ \ PreDown(migrationBuilder);" $FILE1; eofl=$(wc -l $FILE1 | awk '{ print $1 }'); l4=$(($eofl - 2)); -sed -i "${l4}i\ \ \ \ \ \ \ \ \ \ \ \ PostDown(migrationBuilder);" $FILE1; +${SED_CMD} -i "${l4}i\ \ \ \ \ \ \ \ \ \ \ \ PostDown(migrationBuilder);" $FILE1; code -r $FILE1 - diff --git a/scripts/variables.sh b/scripts/variables.sh index c6156c03..a18c28d3 100755 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -2,7 +2,15 @@ . ./scripts/os.sh -export dockerHost=host.docker.internal +# On Mac, use localhost instead of host.docker.internal + +if [ "$(uname)" == "Darwin" ]; then + export dockerHost=localhost +else + export dockerHost=host.docker.internal +fi + + ####################################################### # Database Variables diff --git a/src/api/Dockerfile b/src/api/Dockerfile index 188cfa08..dc996b75 100644 --- a/src/api/Dockerfile +++ b/src/api/Dockerfile @@ -1,5 +1,5 @@ ARG ASPNETCORE_ENVIRONMENT=Release -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim-amd64 AS base RUN apt-get update && apt-get -y upgrade RUN apt-get -y install curl libc6-dev libgdiplus @@ -17,7 +17,7 @@ WORKDIR /src/api COPY src/api/ . COPY src/libs/ /src/libs/ -RUN dotnet restore +RUN dotnet restore "HSB.API.csproj" RUN dotnet publish "HSB.API.csproj" -c "$ASPNETCORE_ENVIRONMENT" -o /app/publish # Runtime image diff --git a/src/dashboard/Dockerfile.prod b/src/dashboard/Dockerfile.prod index fcabe273..021c2295 100644 --- a/src/dashboard/Dockerfile.prod +++ b/src/dashboard/Dockerfile.prod @@ -1,4 +1,4 @@ -FROM node:20-bullseye as BUILD_IMAGE +FROM --platform=linux/amd64 node:20-bullseye as BUILD_IMAGE WORKDIR /usr/dashboard COPY package*.json ./ @@ -11,7 +11,7 @@ COPY . . RUN npm run build RUN npm prune --production -FROM node:20-slim +FROM --platform=linux/amd64 node:20-slim RUN apt-get update && apt-get install curl nano -y diff --git a/src/data-service/Dockerfile b/src/data-service/Dockerfile index 93119eb3..b9680e23 100644 --- a/src/data-service/Dockerfile +++ b/src/data-service/Dockerfile @@ -1,5 +1,5 @@ ARG ASPNETCORE_ENVIRONMENT=Release -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim-amd64 AS base RUN apt-get update && apt-get -y upgrade RUN apt -y install curl libc6-dev libgdiplus @@ -16,7 +16,7 @@ WORKDIR /src/data-service COPY src/data-service/ . COPY src/libs/ /src/libs/ -RUN dotnet restore +RUN dotnet restore "HSB.DataService.csproj" RUN dotnet publish "HSB.DataService.csproj" -c "$ASPNETCORE_ENVIRONMENT" -o /app/publish # Runtime image From 6c475140cf61d686ccf62e63464a5e192761c321 Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:40:59 -0800 Subject: [PATCH 10/13] Remove commented-out code --- scripts/oc.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/oc.sh b/scripts/oc.sh index d96b5e1a..deaddf17 100755 --- a/scripts/oc.sh +++ b/scripts/oc.sh @@ -292,10 +292,6 @@ oc-run () { } } }, - # { - # \"name\":\"Service__Actions__0\", - # \"value\": \"clean-organizations\" - # }, { \"name\":\"Service__SendSuccessEmail\", \"value\": \"true\" From f20b81438b6c19196afbc673e06057a647b06f6e Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:41:09 -0800 Subject: [PATCH 11/13] Setup script wording tweaks --- scripts/setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index c687bacb..3c1cddb0 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -26,7 +26,7 @@ gen_env () { if [[ -z "$dbPassword" ]] then # Generate a random password that satisfies password requirements. - echo 'A password is randomly being generated.' + echo 'A random database password is being generated.' dbPassword=$(date +%s | sha256sum | base64 | head -c 29)A8! echo "Your generated password is: $dbPassword" export dbPassword @@ -34,14 +34,14 @@ gen_env () { if [[ -z "$keycloakUser" ]] then - echo 'Enter a username for keycloak.' + echo 'Enter an admin username for your local Keycloak installation:' read -p 'Username: ' keycloakUser export keycloakUser fi if [[ -z "$keycloakPassword" ]] then - echo 'Enter a password for the keycloak user $keycloakUser.' + echo "Enter a password for the local Keycloak user \"$keycloakUser\":" read -p 'Password: ' keycloakPassword export keycloakPassword fi From 9be5b481650d9004cc57f6f2ca44b99e3a47754e Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:41:55 -0800 Subject: [PATCH 12/13] Additional logging for data service --- src/data-service/Helpers/HsbApiService.cs | 2 ++ src/data-service/Helpers/ServiceNowApiService.cs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/data-service/Helpers/HsbApiService.cs b/src/data-service/Helpers/HsbApiService.cs index d6b3a965..e2073aa3 100644 --- a/src/data-service/Helpers/HsbApiService.cs +++ b/src/data-service/Helpers/HsbApiService.cs @@ -74,6 +74,8 @@ public HsbApiService( { try { + this.Logger.LogError("HsbSendAsync {uri} {method}", uri, method); + var response = await this.ApiClient.SendAsync(uri, method, content); response.EnsureSuccessStatusCode(); diff --git a/src/data-service/Helpers/ServiceNowApiService.cs b/src/data-service/Helpers/ServiceNowApiService.cs index 5ab803a7..27949b4a 100644 --- a/src/data-service/Helpers/ServiceNowApiService.cs +++ b/src/data-service/Helpers/ServiceNowApiService.cs @@ -54,6 +54,9 @@ public ServiceNowApiService( this.Logger = logger; var authenticationString = $"{this.Options.Username}:{this.Options.Password}"; + + this.Logger.LogDebug("**** Service Now - Authenticating with {username}", this.Options.Username); + var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(authenticationString)); this.SNClient.Client.BaseAddress = new Uri($"{this.Options.ApiUrl.Replace("{instance}", this.Options.Instance)}"); this.SNClient.Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64EncodedAuthenticationString); @@ -72,6 +75,8 @@ public ServiceNowApiService( { try { + this.Logger.LogError("ServiceNowSendAsync {uri} {method}", uri, method); + var response = await this.SNClient.SendAsync(uri, method); // Treat a 404 like a 204 because so many API developers do this... It's annoying because it results in the same error if the endpoint doesn't exist. @@ -104,6 +109,8 @@ private async Task[]> ServiceNowArraySendAsync(HttpMethod meth { try { + this.Logger.LogError("ServiceNowArraySendAsync {uri} {method}", uri, method); + var response = await this.SNClient.SendAsync(uri, method); response.EnsureSuccessStatusCode(); From 08203e0e407f0da577675c8d83cac08ef88c3994 Mon Sep 17 00:00:00 2001 From: Frank Hangler Date: Mon, 9 Dec 2024 11:42:14 -0800 Subject: [PATCH 13/13] Documentation tweaks --- README.md | 106 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1041631c..3eb8b7f6 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ bash do help ## Get Started Developing -Currently you'll need to install the following. +### Prerequisites + +You'll need to install the following. | Dependency | Link | | ------------------------------------------------------------------------- | ------------------------------------------------------------------ | @@ -35,23 +37,92 @@ Run `nvm install 20.8.1` to install the version of Node required for this projec Once it is installed run `nvm use 20.8.w1`. If it installed correctly you can run `node -v` and it will display the correct version. -Execute the following command to initialize your local environment and start the required Docker containers. +#### Mac requirements + +You will need to install `coreutils`, `gnu-getopt`, and `gsed` using [Homebrew](https://brew.sh): + +> brew install coreutils gnu-getopt gsed -> If you run into errors with a Mac it is most likely a script needs execute permission. -> -> You will also need to install coreutils and gnu-getopt using [Homebrew](https://brew.sh): -> -> brew install coreutils gnu-getopt +If you run into other errors during the steps below, it is most likely a script needs execute permission. + +### Container initialization + +Execute the following command to initialize your local environment. ```bash +# Generate a local Keycloak admin username and password. # Generate .env files. # Start the database and run the migration. # Spin up all other required containers. -# This process will ask you to input usernames and passwords. +# bash do init ``` -The default configuration will initialize the database and run the web application. +The script will initialize the database and various Docker containers. + +### Update .env files and restart environment + +For the app to be fully functional, we will need to update the values of some `.env` file secrets. + +#### Obtain the local Keycloak Client Secret + +1. With the application running (check in Docker), navigate to the local Keycloak admin interface: [http://localhost:30001](http://localhost:30001). +2. Enter the username and password you created for the local Keycloak admin in the previous step. +3. From the dropdown (select) menu in the upper-right (currently showing "Keycloak"), choose "Host Services Branch Dashboard". +4. From the sidebar on the left, click Clients. +5. In the table, click `hsb-app`. +6. Click the Credentials tab. +7. In the Client Secret section of the page, click the clipboard icon to copy the Client Secret to your clipboard. This is the **Client Secret**. Take note of it, because it will be entered in several places below. (In the examples below, we will use the pretend key `Abc123`.) + +#### Update API env file + +In `/src/api/.env`: + +Update the line `Keycloak__Secret={GET FROM KEYCLOAK}` with the **Client Secret**, e.g. + +```bash +Keycloak__Secret=Abc123 +``` + +#### Update API-CSS env file + +In `/src/api-css/.env`, update two lines with `hsb-app` and the **Client Secret** respectively: + +```bash +Keycloak__ClientId=hsb-app +Keycloak__Secret=Abc123 +``` + +#### Update Dashboard env file + +In `/src/dashboard/.env`: + +Update the line `KEYCLOAK_SECRET={GET FROM KEYCLOAK}` with the **Client Secret**, e.g.: + +```bash +KEYCLOAK_SECRET=Abc123 +``` + +Note that you can also **uncomment** the following lines to skip Keycloak authentication altogether: + +```bash +# NEXT_PUBLIC_AUTH_STATUS=authenticated +# NEXT_PUBLIC_AUTH_ROLES=hsb +``` + +This should only be done for development purposes when testing authentication is not necessary. + +#### Restart environment + +The following command will rebuild the Docker containers to pick up all the `.env` file changes you've made above: + +```bash +bash do up +``` + +### Run the web application + +Now we can start the web application: ```bash # Open the web application in your default browser @@ -60,6 +131,16 @@ bash do go The Dashboard web application is setup for hot-reload within a Docker container. +## Tips + +### Find all .env files + +When recreating the environment, .env files are left behind by default. But this can cause issues when attempting a fresh install. To find .env files: + +```bash +find . -name '*.env' +``` + ## Helpful Documentation - [API Swagger](https://localhost:30005/api-docs) @@ -91,6 +172,13 @@ There are a few other helpful database migration commands that can help with dev | db-refresh | Drops the database and runs all the migrations | | db-redo | Rollback and reapply the migration | +If you get an error on a Mac with an M chip, try running: + +```bash +dotnet tool uninstall dotnet-ef --global +dotnet tool install dotnet-ef --global -a arm64 +``` + ### CI/CD Pipelines When a Pull Request is created Github Actions will build and test the images to provide feedback on issues.