Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIC-000: custom docker image for wiremock and watching mappings #859

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ npm run build
With node being inside a docker container so to are the `node_modules` and if you make a change to package.json you will
need to rebuild the docker container. Rebuilding the containers can be is fairly slow but you shouldn't need to do it day-to-day.

Note that changes to wiremocks will not auto refresh, you'll need to restart the specific wiremock container.

```
docker compose restart hmpps-user-preferences
docker compose restart hmpps-auth
docker compose restart court-case-service
Note that changes to wiremocks will auto refresh.
```

To override the API mocks with development service(s) running on your local machine use something like
Expand Down
16 changes: 10 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,39 @@ networks:

services:
hmpps-auth:
image: wiremock/wiremock
build:
context: .
dockerfile: ./wiremock/Dockerfile
container_name: hmpps-auth
networks:
- hmpps
volumes:
- ./wiremock/mappings/hmpps-auth:/home/wiremock/mappings
entrypoint: ["/docker-entrypoint.sh", "--disable-request-logging", "--disable-banner", "--global-response-templating"] #"--verbose"
restart: always

ports:
- "9091:8080"

hmpps-user-preferences:
image: wiremock/wiremock
build:
context: .
dockerfile: ./wiremock/Dockerfile
container_name: hmpps-user-preferences
networks:
- hmpps
entrypoint: ["/docker-entrypoint.sh", "--disable-request-logging", "--disable-banner", "--global-response-templating"]
volumes:
- ./wiremock/mappings/hmpps-user-preferences:/home/wiremock/mappings
restart: always
ports:
- "9093:8080"

court-case-service:
image: wiremock/wiremock
build:
context: .
dockerfile: ./wiremock/Dockerfile
container_name: court-case-service
networks:
- hmpps
entrypoint: ["/docker-entrypoint.sh", "--disable-request-logging", "--disable-banner", "--global-response-templating"]
volumes:
- ./wiremock/mappings/court-case-service:/home/wiremock/mappings
- ./wiremock/__files:/home/wiremock/__files
Expand Down
13 changes: 13 additions & 0 deletions wiremock/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM wiremock/wiremock
MAINTAINER MoJ Digital, Probation in Court <probation-in-court-team@digital.justice.gov.uk>

ENV TZ=Europe/London
RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone
RUN apt-get update
RUN apt-get -y install inotify-tools curl

WORKDIR /home/wiremock

COPY wiremock/inotify-watch.sh ./

ENTRYPOINT ["./inotify-watch.sh", "curl -X POST \"http://localhost:8080/__admin/mappings/reset\""]
17 changes: 17 additions & 0 deletions wiremock/inotify-watch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

/docker-entrypoint.sh --disable-request-logging --disable-banner --global-response-templating &

# This script watches the current directory and all subdirectories for changes

if [ -z "$(which inotifywait)" ]; then
echo "inotifywait not installed."
echo "In most distros, it is available in the inotify-tools package."
exit 1
fi

inotifywait --recursive --monitor --format "%e %w%f" \
--event modify,move,create,delete ./mappings \
| while read changed; do
eval "$@"
done
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Offence title two",
"Loooooooooooooooooooooooooooooooooong offence title three"
],
"defendantName": "Gill Arnold"
"defendantName": "Gill Arnold YOOO"
},
{
"hearingOutcomeType": "ADJOURNED",
Expand Down