diff --git a/library/1.0.0/healthchecks.py b/library/1.0.0/healthchecks.py index 8d1f8116d0..f099047f06 100644 --- a/library/1.0.0/healthchecks.py +++ b/library/1.0.0/healthchecks.py @@ -14,33 +14,48 @@ def check_health(test, interval=10, timeout=10, retries=5, start_period=30): } -def pg_test(user, db, host="127.0.0.1", port=5432): +def pg_test(user, db, config={}): if not user or not db: utils.throw_error("Postgres container: [user] and [db] must be set") + + host = config.get("host", "127.0.0.1") + port = config.get("port", 5432) + return f"pg_isready -h {host} -p {port} -d {db} -U {user}" -def curl_test(port, path, headers=[], scheme="http", host="127.0.0.1"): - if not port or not path or not host or not scheme: - utils.throw_error("Expected [port], [path], [host] and [scheme] to be set") +def curl_test(port, path, config={}): + if not port or not path: + utils.throw_error("Expected [port] and [path] to be set") + + scheme = config.get("scheme", "http") + host = config.get("host", "127.0.0.1") + headers = config.get("headers", []) opts = [] if scheme == "https": opts.append("--insecure") + for header in headers: if not header[0] or not header[1]: utils.throw_error("Expected [header] to be a list of two items") opts.append(f'--header "{header[0]}: {header[1]}"') + return f"curl --silent --output /dev/null --show-error --fail {' '.join(opts)} {scheme}://{host}:{port}{path}" -def wget_test(port, path, headers=[], scheme="http", host="127.0.0.1"): - if not port or not path or not host or not scheme: - utils.throw_error("Expected [port], [path], [host] and [scheme] to be set") +def wget_test(port, path, config={}): + if not port or not path: + utils.throw_error("Expected [port] and [path] to be set") + + scheme = config.get("scheme", "http") + host = config.get("host", "127.0.0.1") + headers = config.get("headers", []) opts = [] if scheme == "https": opts.append("--no-check-certificate") + for header in headers: if not header[0] or not header[1]: utils.throw_error("Expected [header] to be a list of two items") @@ -49,8 +64,10 @@ def wget_test(port, path, headers=[], scheme="http", host="127.0.0.1"): return f"wget --spider --quiet {' '.join(opts)} {scheme}://{host}:{port}{path}" -def http_test(port, path, host="127.0.0.1"): +def http_test(port, path, config={}): if not port or not path: utils.throw_error("Expected [port] and [path] to be set") + host = config.get("host", "127.0.0.1") + return f"/bin/bash -c 'exec {{health_check_fd}}<>/dev/tcp/{host}/{port} && echo -e \"GET {path} HTTP/1.1\\r\\nHost: {host}\\r\\nConnection: close\\r\\n\\r\\n\" >&$${{health_check_fd}} && cat <&$${{health_check_fd}}'" diff --git a/library/hashes.yaml b/library/hashes.yaml index 10e7c06b69..39d01140b5 100644 --- a/library/hashes.yaml +++ b/library/hashes.yaml @@ -1,2 +1,2 @@ 0.0.1: f074617a82a86d2a6cc78a4c8a4296fc9d168e456f12713e50c696557b302133 -1.0.0: 1644591cef9fa1e1d580a435377ac66d71c472763ab6828839316fd92323019a +1.0.0: 449b47221de4849a92b4f807987adfa6c5fc808bc80c721208366404cd2c5f3e