Skip to content

Service for deploying questionnaire instrument packages to Blaise.

Notifications You must be signed in to change notification settings

ONSdigital/blaise-deploy-questionnaire-service

Repository files navigation

Deploy Questionnaire Service

codecov CI status Nisra Case Mover release verison GitHub pull requests Github last commit Github contributors Language grade: JavaScript Total alerts

Service for uploading Questionnaire files to Blaise.

This is done by uploading the Questionnaire package to a GCP Bucket then sending a request to the Blaise Rest API to install it onto Blaise.

This project is a React application which when built is rendered by a Node.js express server. The Node.js handles the file being uploaded from the client and uploads the file to a GCP bucket using the @google-cloud/storage module.

React and NodeJS server setup diagram

Questionnaire package upload process

Questionnaire package upload process

Blaise Questionnaire Metadata Service (BIMS) handles storing Instrument Metadata like the Telephone Operations start date used by Telephone Operations Blaise Interface (TOBI).

Blaise UAC Service (BUS) handles the generation of Unique Access Codes (UACs) for Questionnaires.

Setup

Prerequisites

To run Blaise Deploy Questionnaire Service locally, you'll need to have Node installed, as well as yarn.

To have the list of Questionnaires load on the page, you'll need to have Blaise Rest API running locally (On a Windows machine), or you can create an Identity-Aware Proxy (IAP) tunnel from a GCP Compute Instance running the rest API in a sandbox. An example command to connect to the rest api VM on local port 5011:

sudo gcloud compute start-iap-tunnel restapi-1 80 --local-host-port=localhost:5011 --zone europe-west2-a

Local Setup

Prerequisites

Clone the repository:

git clone https://github.com/ONSdigital/blaise-deploy-questionnaire-service.git

Create a new .env file and add the following variables.

Variable Description Var Example
PORT Optional variable, specify the Port for express server to run on. If not passed in this is set as 5000 by default.

It's best not to set this as the react project will try and use the variable as well and conflict. By default, React project locally runs on port 3000
5009
BLAISE_API_URL Url that the Blaise Rest API is running on to send calls to localhost:90
PROJECT_ID GCP Project ID ons-blaise-dev-matt55
BUCKET_NAME GCP Bucket name for the Questionnaire file to be put in ons-blaise-dev-matt55-dqs
SERVER_PARK Name of Blaise Server Park gusty
BIMS_API_URL Url that the BIMS Service is running on to send calls to set and get the live date localhost:5011
BIMS_CLIENT_ID GCP IAP ID for the BIMS Service randomKey0112
BUS_API_CLIENT Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string FOO
BUS_CLIENT_ID Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string FOO

To find the X_CLIENT_ID, navigate to the GCP console, search for IAP, click the three dots on right of the service and select OAuth. Client Id will be on the right.

The .env file should be setup as below

Example .env file:

BLAISE_API_URL=localhost:5011
PROJECT_ID=ons-blaise-v2-dev-<sandbox>
BUCKET_NAME=ons-blaise-v2-dev-<sandbox>-dqs
SERVER_PARK=gusty
BIMS_API_URL=localhost:5000
BIMS_CLIENT_ID=randomKey0778
BUS_API_URL=FOO
BUS_CLIENT_ID=FOO

Install the project dependencies:

yarn

Running yarn or yarn install will install the required modules specified in the yarn.lock file.

The versions of theses modules are fixed in the yarn.lock files, so to avoid unwanted upgrades or instability caused by incorrect modifications, DO NOT DELETE THE LOCK FILE.

More information about yarn (https://confluence.ons.gov.uk/x/zdwACQ)

Authenticate with GCP:

gcloud auth login

Set your GCP project:

gcloud config set project ons-blaise-v2-dev-<sandbox-suffix>

create a keys.json file:

gcloud iam service-accounts keys create keys.json --iam-account ons-blaise-v2-dev-<sandbox>@appspot.gserviceaccount.com

To export the Google application credentials as a runtime variable:

export GOOGLE_APPLICATION_CREDENTIALS=keys.json

Open a tunnel to our Blaise RESTful API in your GCP project:

gcloud compute start-iap-tunnel restapi-1 80 --local-host-port=localhost:8011 --zone europe-west2-a

Ensure the proxy is configured to the correct port in the 'package.json'

"proxy": "http://localhost:5000",

In a new terminal, run Node.js server and React.js client via the following package.json script

yarn dev

The UI should now be accessible via:

http://localhost:3000/

Tests can be run via the following package.json script:

yarn test

Test snapshots can be updated via:

yarn test -u

Dockerfile

You can run this service in a container, the Dockerfile is setup to:

  • Update and upgrade the Docker container image.
  • Setup Yarn and the required dependencies.
  • Run the tests, the build will fail if the tests fail.
  • Build the React project for serving by express
  • Run Yarn Start on startup

Copyright (c) 2021 Crown Copyright (Government Digital Service)