diff --git a/Dockerfile b/Dockerfile index 4a3b6ac..0ca6123 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM stoplight/prism RUN apk update -COPY docs docs +RUN apk add curl +COPY docs docs \ No newline at end of file diff --git a/README.md b/README.md index 85a7f40..33a7d4e 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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, diff --git a/docker-compose.yml b/docker-compose.yml index f43cfde..b39dd93 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: . @@ -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: . @@ -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 diff --git a/docs/alert-rules.yml b/docs/alert-rules.yml index 79bdf0c..bcd06a6 100644 --- a/docs/alert-rules.yml +++ b/docs/alert-rules.yml @@ -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: diff --git a/docs/alerts.yml b/docs/alerts.yml index 715dc26..4d61949 100644 --- a/docs/alerts.yml +++ b/docs/alerts.yml @@ -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: diff --git a/docs/audit-logs.yml b/docs/audit-logs.yml index e08ab1e..c833328 100644 --- a/docs/audit-logs.yml +++ b/docs/audit-logs.yml @@ -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: diff --git a/docs/cases.yml b/docs/cases.yml index b4f7f5b..8565af5 100644 --- a/docs/cases.yml +++ b/docs/cases.yml @@ -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: diff --git a/docs/connected-server.yml b/docs/connected-server.yml index 075accf..b970dde 100644 --- a/docs/connected-server.yml +++ b/docs/connected-server.yml @@ -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: diff --git a/docs/core.yml b/docs/core.yml index 57b6eb1..0fd4cf2 100644 --- a/docs/core.yml +++ b/docs/core.yml @@ -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 diff --git a/docs/detection-lists.yml b/docs/detection-lists.yml index 195835c..81e7800 100644 --- a/docs/detection-lists.yml +++ b/docs/detection-lists.yml @@ -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: diff --git a/docs/file-events.yml b/docs/file-events.yml index 507ff20..9a09e48 100644 --- a/docs/file-events.yml +++ b/docs/file-events.yml @@ -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: diff --git a/docs/preservation-data-service.yml b/docs/preservation-data-service.yml index 4bf6417..c6ce940 100644 --- a/docs/preservation-data-service.yml +++ b/docs/preservation-data-service.yml @@ -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: diff --git a/docs/storage.yml b/docs/storage.yml index 030ecd9..54bb82b 100644 --- a/docs/storage.yml +++ b/docs/storage.yml @@ -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: