diff --git a/haproxy-healthcheck/compose.yml b/haproxy-healthcheck/compose.yml index 3ae8b28ca70..f5e7ea419db 100644 --- a/haproxy-healthcheck/compose.yml +++ b/haproxy-healthcheck/compose.yml @@ -1,13 +1,11 @@ version: "3.7" services: mock-couchdb: - image: mockserver/mockserver:5.15.0 - environment: - MOCKSERVER_SERVER_PORT: 5984 - # MOCKSERVER_LOG_LEVEL: WARN - MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json + image: nginx:1-alpine-slim volumes: - - ./mock-config/:/config/ + - ./mock-config/conf.d/:/etc/nginx/conf.d/:ro + ports: + - 127.0.0.1:5984:5984 haproxy-healthcheck: build: . diff --git a/haproxy-healthcheck/mock-config/conf.d/mock-couchdb.conf b/haproxy-healthcheck/mock-config/conf.d/mock-couchdb.conf new file mode 100644 index 00000000000..05ec82b16c5 --- /dev/null +++ b/haproxy-healthcheck/mock-config/conf.d/mock-couchdb.conf @@ -0,0 +1,20 @@ +server { + listen 5984; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location = / { + add_header Content-Type application/json; + return 200 '{ "couchdb": "Welcome to mock-couchdb", "status": "this field is not used" }'; + } + + location = /_membership { + add_header Content-Type application/json; + return 200 '{ "all_nodes": [ "mock-couchdb" ], "cluster_nodes": [ "mock-couchdb" ] }'; + } + + location = /error/drop { + return 444; + } +} diff --git a/haproxy-healthcheck/mock-config/initializerJson.json b/haproxy-healthcheck/mock-config/initializerJson.json deleted file mode 100644 index c7e9acbb9d1..00000000000 --- a/haproxy-healthcheck/mock-config/initializerJson.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "httpRequest": { - "path": "/" - }, - "httpResponse": { - "body": { - "couchdb": "Welcome to mock-couchdb", - "status": "this field is not used" - } - } - }, - { - "httpRequest": { - "path": "/_membership" - }, - "httpResponse": { - "body": { - "all_nodes": [ - "mock-couchdb" - ], - "cluster_nodes": [ - "mock-couchdb" - ] - } - } - }, - { - "httpRequest": { - "path": "/error/drop" - }, - "httpError": { - "dropConnection": true - } - } -] \ No newline at end of file diff --git a/haproxy/tests/Makefile b/haproxy/tests/Makefile index fa2bed8c238..ba5e8e348f9 100644 --- a/haproxy/tests/Makefile +++ b/haproxy/tests/Makefile @@ -11,3 +11,6 @@ test_with_docker_compose: bats with_mock.bats docker compose down +.PHONY: clean +clean: + docker compose down --rmi local || : diff --git a/haproxy/tests/compose.yml b/haproxy/tests/compose.yml index 10bfba9ad53..a8fa4350ed0 100644 --- a/haproxy/tests/compose.yml +++ b/haproxy/tests/compose.yml @@ -1,38 +1,33 @@ version: "3.7" services: - haproxy: - build: - context: ../ - ports: - - 127.0.0.1:5984:5984 - environment: - COUCHDB_SERVERS: mock-couchdb - COUCHDB_USER: someuser - COUCHDB_PASSWORD: insecure_pw - HAPROXY_IP: 0.0.0.0 - HAPROXY_PORT: 5984 - HEALTHCHECK_ADDR: haproxy-healthcheck - depends_on: - - mock-couchdb - - haproxy-healthcheck + haproxy: + build: + context: ../ + ports: + - 127.0.0.1:5984:5984 + environment: + COUCHDB_SERVERS: mock-couchdb1,mock-couchdb2,mock-couchdb3 + COUCHDB_USER: someuser + COUCHDB_PASSWORD: insecure_pw + HAPROXY_IP: 0.0.0.0 + HAPROXY_PORT: 5984 + HEALTHCHECK_ADDR: haproxy-healthcheck + depends_on: + - mock-couchdb1 + - haproxy-healthcheck - mock-couchdb: - image: mockserver/mockserver:5.15.0 - ports: - - 127.0.0.1:5985:5984 - environment: - MOCKSERVER_SERVER_PORT: 5984 - # MOCKSERVER_LOG_LEVEL: WARN - MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json - volumes: - - ./mock-config/initializerJson.json:/config/initializerJson.json - - haproxy-healthcheck: - build: ../../haproxy-healthcheck - ports: - - 127.0.0.1:5555:5555 - environment: - COUCHDB_SERVERS: mock-couchdb - COUCHDB_USER: someuser - COUCHDB_PASSWORD: insecure_pw + mock-couchdb1: &mockserver + image: nginx:1-alpine-slim + volumes: + - ./mock-config/conf.d/:/etc/nginx/conf.d/:ro + mock-couchdb2: *mockserver + mock-couchdb3: *mockserver + haproxy-healthcheck: + build: ../../haproxy-healthcheck + ports: + - 127.0.0.1:5555:5555 + environment: + COUCHDB_SERVERS: mock-couchdb1,mock-couchdb2,mock-couchdb3 + COUCHDB_USER: someuser + COUCHDB_PASSWORD: insecure_pw diff --git a/haproxy/tests/mock-config/conf.d/mock-couchdb.conf b/haproxy/tests/mock-config/conf.d/mock-couchdb.conf new file mode 100644 index 00000000000..1876d58ee96 --- /dev/null +++ b/haproxy/tests/mock-config/conf.d/mock-couchdb.conf @@ -0,0 +1,20 @@ +server { + listen 5984; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location = / { + add_header Content-Type application/json; + return 200 '{ "couchdb": "Welcome to mock-couchdb", "status": "this field is not used" }'; + } + + location = /_membership { + add_header Content-Type application/json; + return 200 '{ "all_nodes": [ "mock-couchdb1","mock-couchdb2","mock-couchdb3" ], "cluster_nodes": [ "mock-couchdb1","mock-couchdb2","mock-couchdb3" ] }'; + } + + location = /error/drop { + return 444; + } +} diff --git a/haproxy/tests/mock-config/initializerJson.json b/haproxy/tests/mock-config/initializerJson.json deleted file mode 100644 index c7e9acbb9d1..00000000000 --- a/haproxy/tests/mock-config/initializerJson.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "httpRequest": { - "path": "/" - }, - "httpResponse": { - "body": { - "couchdb": "Welcome to mock-couchdb", - "status": "this field is not used" - } - } - }, - { - "httpRequest": { - "path": "/_membership" - }, - "httpResponse": { - "body": { - "all_nodes": [ - "mock-couchdb" - ], - "cluster_nodes": [ - "mock-couchdb" - ] - } - } - }, - { - "httpRequest": { - "path": "/error/drop" - }, - "httpError": { - "dropConnection": true - } - } -] \ No newline at end of file diff --git a/nginx/tests/Makefile b/nginx/tests/Makefile index 7f4a6fe912b..9c84496ef30 100644 --- a/nginx/tests/Makefile +++ b/nginx/tests/Makefile @@ -4,4 +4,8 @@ test: docker compose up --wait --build bats with_mock.bats - docker compose down \ No newline at end of file + docker compose down + +.PHONY: clean +clean: + docker compose down --rmi local || : diff --git a/nginx/tests/compose.yml b/nginx/tests/compose.yml index 30b62c55d92..71b684017e2 100644 --- a/nginx/tests/compose.yml +++ b/nginx/tests/compose.yml @@ -1,29 +1,25 @@ version: "3.7" services: - cht-nginx: - build: - context: ../ - ports: - - 127.0.0.1:1080:80 - - 127.0.0.1:1443:443 - environment: - API_HOST: cht-api - API_PORT: 5988 - CERTIFICATE_MODE: SELF_SIGNED - volumes: - - cht-ssl:/root/.acme.sh/ - depends_on: - - cht-api + cht-nginx: + build: + context: ../ + ports: + - 127.0.0.1:1080:80 + - 127.0.0.1:1443:443 + environment: + API_HOST: mock-api + API_PORT: 5988 + CERTIFICATE_MODE: SELF_SIGNED + volumes: + - cht-ssl:/root/.acme.sh/ + depends_on: + - mock-api - cht-api: - image: mockserver/mockserver:5.15.0 - command: -serverPort 5988 - environment: - MOCKSERVER_PROPERTY_FILE: /config/mockserver.properties - MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json - volumes: - - ./mock-config:/config + mock-api: + image: nginx:1-alpine-slim + volumes: + - ./mock-config/conf.d/:/etc/nginx/conf.d/:ro volumes: - cht-ssl: - name: cht-ssl + cht-ssl: + name: cht-ssl diff --git a/nginx/tests/mock-config/conf.d/mock-api.conf b/nginx/tests/mock-config/conf.d/mock-api.conf new file mode 100644 index 00000000000..50ef5ea8c6e --- /dev/null +++ b/nginx/tests/mock-config/conf.d/mock-api.conf @@ -0,0 +1,18 @@ +server { + listen 5988; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + location = / { + return 200 'Hello from CHT api mock'; + } + + location = /somepath { + return 200 'Test'; + } + + location = /error/drop { + return 444; + } +} diff --git a/nginx/tests/mock-config/initializerJson.json b/nginx/tests/mock-config/initializerJson.json deleted file mode 100644 index 7816cab0629..00000000000 --- a/nginx/tests/mock-config/initializerJson.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "httpRequest": { - "path": "/" - }, - "httpResponse": { - "body": "Hello from CHT api mock" - } - }, - { - "httpRequest": { - "path": "/somepath" - }, - "httpResponse": { - "body": "Test" - } - }, - { - "httpRequest": { - "path": "/error/drop" - }, - "httpError": { - "dropConnection": true - } - } -] \ No newline at end of file diff --git a/nginx/tests/mock-config/mockserver.properties b/nginx/tests/mock-config/mockserver.properties deleted file mode 100644 index 95f32a0e6a0..00000000000 --- a/nginx/tests/mock-config/mockserver.properties +++ /dev/null @@ -1,32 +0,0 @@ -############################### -# MockServer & Proxy Settings # -############################### - -# Socket & Port Settings - -# socket timeout in milliseconds (default 120000) -mockserver.maxSocketTimeout=120000 - -# Certificate Generation - -# dynamically generated CA key pair (if they don't already exist in specified directory) -mockserver.dynamicallyCreateCertificateAuthorityCertificate=true -# save dynamically generated CA key pair in working directory -mockserver.directoryToSaveDynamicSSLCertificate=. -# certificate domain name (default "localhost") -mockserver.sslCertificateDomainName=localhost -# comma separated list of ip addresses for Subject Alternative Name domain names (default empty list) -mockserver.sslSubjectAlternativeNameDomains=www.example.com,test-nginx.dev.medicmobile.org -# comma separated list of ip addresses for Subject Alternative Name ips (default empty list) -mockserver.sslSubjectAlternativeNameIps=127.0.0.1 - -# CORS - -# enable CORS for MockServer REST API -mockserver.enableCORSForAPI=true -# enable CORS for all responses -mockserver.enableCORSForAllResponses=true - -# Json Initialization - -mockserver.initializationJsonPath=/config/initializerJson.json