Skip to content

Commit

Permalink
Merge pull request #78 from nhsconnect/PRMT-4402
Browse files Browse the repository at this point in the history
PRMT-4402
  • Loading branch information
martin-nhs committed Mar 21, 2024
2 parents a183f22 + 1549922 commit 94d271b
Show file tree
Hide file tree
Showing 75 changed files with 9,807 additions and 7,825 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"printWidth": 100
"printWidth": 100,
"trailingComma": "none"
}
7 changes: 0 additions & 7 deletions .sequelizerc

This file was deleted.

13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM node:16.19.0-alpine AS builder

# install python and postgres native requirements
# install python native requirements
RUN apk update && \
apk add --no-cache bash tini postgresql-client && \
apk add --no-cache bash tini && \
rm -rf /var/cache/apk/*

RUN apk add --no-cache \
Expand All @@ -14,7 +14,7 @@ RUN apk add --no-cache \
&& rm -rf /var/cache/apk/*

# Install sequelize postgress native dependencies
RUN apk add --no-cache postgresql-dev g++ make
RUN apk add --no-cache g++ make

COPY package*.json /app/

Expand All @@ -31,10 +31,10 @@ COPY --from=builder /usr/local/bin/node /usr/local/bin
# take native-install node modules
COPY --from=builder /app /app

# install python and postgres native requirements (again, as per builder)
# install python native requirements (again, as per builder)
# add root CA from deductions team to trusted certificates
RUN apk update && \
apk add --no-cache openssl ca-certificates bash tini postgresql-client && \
apk add --no-cache openssl ca-certificates bash tini && \
rm -rf /var/cache/apk/*

RUN apk add --no-cache \
Expand All @@ -46,9 +46,6 @@ RUN apk add --no-cache \
&& rm -rf /var/cache/apk/*

COPY build/ /app/build
COPY database/ /app/database
COPY build/config/database.js /app/src/config/
COPY .sequelizerc /app/

COPY scripts/load-api-keys.sh /app/scripts/load-api-keys.sh
COPY scripts/run-server-with-db.sh /usr/bin/run-ehr-server
Expand Down
47 changes: 17 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ The stored the EHR is composed of the messages sent from its previous holder in
- [Docker](https://docs.docker.com/install/)
- [kudulab/dojo](https://github.com/kudulab/dojo#installation)

In order to run npm install locally on your host (outside of dojo), you'll need to install postgresql:
```
brew install postgresql
```

### AWS helpers

This repository imports shared AWS helpers from [prm-deductions-support-infra](https://github.com/nhsconnect/prm-deductions-support-infra/).
Expand All @@ -31,45 +26,37 @@ If you would like to run the app locally outside `dojo`, you need to:
```
- `NHS_ENVIRONMENT` - should be set to current environment in which the container is deployed. The name must also exist in the `database.json` file.
- `S3_BUCKET_NAME` - the name of S3 bucket to store the EHR fragments in.
- `DATABASE_USER` - username for the database
- `DATABASE_PASSWORD` - password to the database
- `DATABASE_NAME` - name of the database on server.
- `DATABASE_HOST` - database server hostname to connect with.
- `LOCALSTACK_URL` - (Test) the location of localstack, only used for tests
- `LOCALSTACK_URL` - (Test) the location of localstack, only used for s3 related tests
- `DYNAMODB_NAME` - The table name of the dynamodb table (ehr-transfer-tracker) used
```

## Running the tests

Run the unit tests with

by entering the `dojo` container and running `./tasks _test_unit`
Run the unit tests by entering the `dojo` container and running `./tasks _test_unit`
or on your machine with `npm run test:unit`

Run the integration tests within a Dojo container

1. Run `dojo -c Dojofile-itest` which will spin up the testing container
1. Run `./tasks test_integration_shell` which will spin up the testing container
2. Run `./tasks _test_integration`

You can also run them with `npm run test:integration` but that will require some additional manual set-up:
You can also run them with `./tasks test_integration` from out of dojo.

```bash
# Brings up the local test environment
docker-compose up &

# Alternative with node-dojo (interactive)
# Requires changes to Environment Variables:
# DATABASE_HOST=db
# LOCALSTACK_URL=http://localstack:4572
dojo -c Dojofile-itest
You can also run each individual integration test separately in an IDE (assuming IntelliJ),
but that will require some additional manual set-up:

npm run test-local

# This is equivalent of:
sequelize-cli db:migrate # Runs the migration
```bash
# Config env var, spin up docker containers and enter interactive dojo environment
./tasks test_integration_shell

npm test
# If things work as expected your prompts should looks like `dojo@xxxx(node-dojo):/dojo/work$`
# inside dojo, run the below script to create a dynamodb table for integration test
scripts/create-dynamodb-table.sh

sequelize-cli db:migrate:undo:all # Undoes the migration to leave clean env
# The above script will create a test table in dynamodb-local docker image.
# The dynamodb-local is accessible at endpoint http://dynamodb-local:8000 within docker,
# or at endpoint http://localhost:4573 from out of docker.
# This should allow you to run or debug db-related integration tests from Intellij's play button.
```

## Run the coverage tests (unit test and integration test)
Expand Down
50 changes: 0 additions & 50 deletions database/migrations/20210302112415-create-health-records-table.js

This file was deleted.

61 changes: 0 additions & 61 deletions database/migrations/20210302112617-create-message-table.js

This file was deleted.

30 changes: 0 additions & 30 deletions database/migrations/20210302113224-create-health-checks-table.js

This file was deleted.

14 changes: 6 additions & 8 deletions docker-compose-dtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ services:
ehr-repo:
image: ${REPOSITORY_URI}:${IMAGE_TAG}
links:
- db:db
- localstack:localstack
- dynamodb-local:dynamodb-local
ports:
- 3000:3000
db:
image: postgres:12.1
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
localstack:
image: localstack/localstack:0.10.9
environment:
Expand All @@ -31,3 +24,8 @@ services:
volumes:
- ./scripts/create-bucket.sh:/docker-entrypoint-initaws.d/create-bucket.sh
- /var/run/docker.sock:/var/run/docker.sock
dynamodb-local:
image: amazon/dynamodb-local
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
ports:
- "4573:8000"
19 changes: 8 additions & 11 deletions docker-compose-itest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ version: '2'
services:
default:
links:
- db:db
- localstack:localstack
- dynamodb-local:dynamodb-local
ports:
- "3000:3000"
db:
image: postgres:12.1
environment:
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
ports:
- "5432:5432"
localstack:
image: localstack/localstack:0.10.9
environment:
Expand All @@ -27,4 +18,10 @@ services:
- ./scripts/create-bucket.sh:/docker-entrypoint-initaws.d/create-bucket.sh
- /var/run/docker.sock:/var/run/docker.sock
logging:
driver: none
driver: none
dynamodb-local:
image: amazon/dynamodb-local
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
ports:
- "4573:8000"

11 changes: 0 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version: '3.4'
services:
postgres:
image: postgres:12.1
ports:
- 5432:5432
expose:
- 5432
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
LC_ALL: C
localstack:
image: localstack/localstack
ports:
Expand Down
Loading

0 comments on commit 94d271b

Please sign in to comment.