This repository contains the ui code for the Find and Refer an Intervention UI.
Most software can be installed using homebrew.
- Docker
- Node (>=22)
After setting up the dependencies (below), run the application locally with with:
npm run start:devThe dev server comes with Hot Module Reloading (reloads and restarts when any file changes are detected)
This project includes docker compose files to start the required dependencies for running the UI locally.
Run the following command to pull the relevant dependencies for the project.
docker-compose pulland then the following command to run the containers.
docker-compose upcan optionally be run in detached mode in order to retain terminal use
docker-compose up -dNode requires a .env file to start the application, but the project does not make heavy use of environmental variables.
Before starting the application create a new blank .env file by either creating a blank .env file:
touch .envor copying the example file:
cp .env.example .envThe service uses a postgres database alongside flyaway migrations to create and populate the database. To connect to the database locally in your preferred database client (IntelliJ Ultimate, Dbeaver, Pgadmin, etc).
Create new connection using local database credentials;
| Variable | Value |
|---|---|
| Port | 5432 |
| Username | root |
| Password | dev |
The service uses an Oauth 2.0 setup managed through the Hmpps Auth project. To call any endpoints locally a bearer token must be generated. This can be done through calling the auth endpoint in the Hmpps-auth service.
| Variable | Value |
|---|---|
| Grant type | Client credentials |
| Access token URL | http://hmpps-auth:8090/auth/oauth/token |
| Client ID | hmpps-find-and-refer-an-intervention-ui-client |
| Client Secret | clientsecret |
| Scope | Read |
For Client ID and Secret refer to the relevant credentials for the Find and Refer Project.
These are used by the application to request tokens to make calls to APIs. These are system accounts that will have their own sets of roles.
Most API calls that occur as part of the request/response cycle will be on behalf of a user.
To make a call on behalf of a user, a username should be passed when requesting a system token. The username will then become part of the JWT and can be used downstream for auditing purposes.
These tokens are cached until expiration.
These credentials are configured using the following env variables:
- CLIENT_CREDS_CLIENT_ID
- CLIENT_CREDS_CLIENT_SECRET
System tokens are obtained by making a call to HMPPS-Auth using the username of the logged in user. This token can then be added to the appropriate rest client calling to another service.
Once the application is running you should then be able to login with:
Community User username: REFER_MONITOR_PP password: R8Mpassword
Custody User username: FRI_USER_ACP_REF_TEAM password: password123456
npm run lintrunseslint.npm run typecheckruns the TypeScript compilertsc.
npm run test
Deployments are part of our CI process, on the main branch using the build-test-and-deploy Workflow.
This is a link to the most recent runs of that Workflow.
Deployments require a manual approval step.
The Find & Refer an Intervention Service is not presently live. We therefore do not have a Production environment available.
It is only possible to do User Acceptance Testing (UAT), i.e. click around a browser, on our Dev environment.
To test a deployment to production, we have to examine the logs of a pod, to assert if it has spun up successfully or not. This is obviously not ideal.
All deployments and environments are managed through Kubernetes.
For information on how to connect to the Cloud Platform's Kubernetes cluster follow the setup guide here.
For further Kubernetes commands a useful cheat sheet is
provided here. Similarly, the --help flag on any kubectl command will give you more information.
$ kubectl get deployments -n hmpps-find-and-refer-an-intervention-prod
NAME READY UP-TO-DATE AVAILABLE AGE
hmpps-find-and-refer-an-intervention-service 0/0 0 0 41d
hmpps-find-and-refer-an-intervention-ui 2/2 2 2 41dIf you have done a deployment of UI, there should be more than 0 Pods marked as READY in that response, indicating that they have, indeed, been spun up.
Per Kubernete's docs:
A Pod is similar to a set of containers with shared namespaces and shared filesystem volumes.
View the Pods in the namespace, these are what the READY column in the get deployments refer to:
$ kubectl get pods -n hmpps-find-and-refer-an-intervention-prod
NAME READY STATUS RESTARTS AGE
hmpps-find-and-refer-an-intervention-ui-58b989489d-blprx 1/1 Running 0 2m49s
hmpps-find-and-refer-an-intervention-ui-58b989489d-mkb7p 1/1 Running 0 2m49sIt is possible to read the logs of a given Pod to check that the build and spin-up process for the Pod has been successful.
To view the logs from any of the Pods whose name is given in the previous responses:
$ kubectl logs $POD_NAME --namespace hmpps-find-and-refer-an-intervention-prod
# ...
Application Insights 2.X SDK. []
14:25:13.500Z INFO HMPPS Find And Refer An Intervention Ui: Server listening on port 3000Where $POD_NAME is the full string Pod name given in the get pods response.
While we are in pre-release, it's important not to leave the pods running.
We scale down the number of running Pods in the Kubernetes deployment with the following:
$ kubectl scale deployment hmpps-find-and-refer-an-intervention-ui --namespace hmpps-find-and-refer-an-intervention-prod --replicas=0
deployment.apps/hmpps-find-and-refer-an-intervention-ui scaledAnd then double-check this has taken effect:
$ kubectl get deployments --namespace=hmpps-find-and-refer-an-intervention-prod
NAME READY UP-TO-DATE AVAILABLE AGE
hmpps-find-and-refer-an-intervention-service 0/0 0 0 41d
hmpps-find-and-refer-an-intervention-ui 0/0 0 0 41dBy checking for the 0 in the READY column.
A changelog for the service is available here
For any issues please reach out to the Find and Refer Interventions team in slack #find-refer-interventions-team