Skip to content

Commit

Permalink
Merge pull request #5 from code42/feature/make-containers-use-host
Browse files Browse the repository at this point in the history
Add healthcheck system to docker-compose configuration
  • Loading branch information
peterbriggs42 authored Feb 22, 2021
2 parents c1b3bec + 576dfdb commit 6aca3b9
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM stoplight/prism

RUN apk update
COPY docs docs
RUN apk add curl
COPY docs docs
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mock Microservice Endpoints

***Warning: This repo is for internal Code42 use and may change or seize to exist at any time.***
***Warning: This repo is for internal Code42 use and may change or cease to exist at any time.***

To start the servers:

Expand Down Expand Up @@ -143,6 +143,39 @@ the mock key-value store endpoint).

Notice the port number appears in three places in the `yml` for the docker-compose file.

## Integration Tests and CI/CD

To successfully execute integration tests against the mock server in a CI/CD context, you must ensure that the `docker-compose up` command does not return before your mock microservice container is fully instantiated and ready to receive requests.

First, add a healthcheck endpoint to your OpenAPI yml file:
```yml
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
```

Then, in `docker-compose.yml`, add a `healthcheck` configuration section to your service definition. Be sure to modify the port to match the port exposed by your mock microservice container.
```yml
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4200 || exit 1"]
interval: 10s
timeout: 5s
retries: 3
```

Finally, add a service dependency to the `health_checker` service at the bottom of `docker-compose.yml` so that the `docker-compose up` command will not return until your container is fully instantiated and responding to HTTP requests:
```yml
depends_on:
core:
condition: service_healthy
```

## Returning empty JSON responses

If your endpoint claims to return application/json but you are returning an empty response,
Expand Down
79 changes: 77 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ services:
ports:
- "4200:4200"
command: mock docs/core.yml -p 4200 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4200 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

alerts:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -22,6 +27,11 @@ services:
ports:
- "4201:4201"
command: mock docs/alerts.yml -p 4201 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4201 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

alert_rules:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -33,6 +43,11 @@ services:
ports:
- "4202:4202"
command: mock docs/alert-rules.yml -p 4202 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4202 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

detection_lists:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -44,6 +59,11 @@ services:
ports:
- "4203:4203"
command: mock docs/detection-lists.yml -p 4203 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4203 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

cases:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -55,6 +75,11 @@ services:
ports:
- "4204:4204"
command: mock docs/cases.yml -p 4204 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4204 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

storage:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -66,6 +91,11 @@ services:
ports:
- "4205:4205"
command: mock docs/storage.yml -p 4205 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4205 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

connected_server:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -77,6 +107,11 @@ services:
ports:
- "4206:4206"
command: mock docs/connected-server.yml -p 4206 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4206 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

audit_logs:
image: c42/mock-microservice-endpoints:1.0
Expand All @@ -88,8 +123,13 @@ services:
ports:
- "4207:4207"
command: mock docs/audit-logs.yml -p 4207 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4207 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

file-events:
file_events:
image: c42/mock-microservice-endpoints:1.0
build:
context: .
Expand All @@ -99,8 +139,13 @@ services:
ports:
- "4208:4208"
command: mock docs/file-events.yml -p 4208 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4208 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

preservation-data-service:
preservation_data_service:
image: c42/mock-microservice-endpoints:1.0
build:
context: .
Expand All @@ -110,3 +155,33 @@ services:
ports:
- "4209:4209"
command: mock docs/preservation-data-service.yml -p 4209 -h 0.0.0.0
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:4209 || exit 1"]
interval: 10s
timeout: 5s
retries: 3

health_checker:
build: .
command: [":"]
depends_on:
core:
condition: service_healthy
alerts:
condition: service_healthy
alert_rules:
condition: service_healthy
detection_lists:
condition: service_healthy
cases:
condition: service_healthy
storage:
condition: service_healthy
connected_server:
condition: service_healthy
audit_logs:
condition: service_healthy
file_events:
condition: service_healthy
preservation_data_service:
condition: service_healthy
9 changes: 9 additions & 0 deletions docs/alert-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ info:
servers:
- url: /
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/svc/api/v1/Rules/update-is-enabled:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ info:
servers:
- url: /
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/svc/api/v1/update-state:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/audit-logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ tags:
- name: AuditLogs
description: A collection of data for an insider threat investigation.
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/rpc/search/search-audit-log:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ tags:
- name: Cases
description: A collection of data for an insider threat investigation.
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/api/v1/case:
get:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/connected-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ tags:
description: A collection of data for storage archive actions.

paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/api/WebRestoreSession:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ tags:
- name: Core
description: A collection of data for core Code42 actions.
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success

# AUTH

Expand Down
9 changes: 9 additions & 0 deletions docs/detection-lists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ servers:
- url: /
- name: Detection Lists
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/svc/api/v2/departingemployee/get:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/file-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ tags:
- name: File Events
description: Security file events detected by Code42.
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/forensic-search/queryservice/api/v1/fileevent:
post:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/preservation-data-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ servers:
tags:
- name: Preservation Data Service
paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/api/v1/FileVersionListing:
get:
tags:
Expand Down
9 changes: 9 additions & 0 deletions docs/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ tags:
description: A collection of data for storage archive actions.

paths:
/:
get:
summary: Check the health of the mock microservice container
responses:
200:
description: A successful response
content:
text/plain:
example: healthcheck-success
/api/AuthToken:
post:
tags:
Expand Down

0 comments on commit 6aca3b9

Please sign in to comment.