Skip to content

Commit 56a02d0

Browse files
authored
Merge pull request #86 from DataKitchen/add-api-port
feat: set API/MCP port in TestGen compose file
2 parents 648425c + 4bd3c0f commit 56a02d0

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

dk-installer.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
TESTGEN_PULL_TIMEOUT = 5
5252
TESTGEN_PULL_RETRIES = 3
5353
TESTGEN_DEFAULT_PORT = 8501
54+
TESTGEN_DEFAULT_API_PORT = 8530
5455
TESTGEN_LATEST_VERSIONS_URL = (
5556
"https://dk-support-external.s3.us-east-1.amazonaws.com/testgen-observability/testgen-latest-versions.json"
5657
)
@@ -1728,17 +1729,38 @@ def pre_execute(self, action, args):
17281729

17291730
self.update_base_url = "TG_UI_BASE_URL" not in contents
17301731
if self.update_base_url:
1731-
port_match = re.search(r"- (\d+):8501", contents)
1732+
port_match = re.search(rf"- (\d+):{TESTGEN_DEFAULT_PORT}", contents)
17321733
port = port_match.group(1) if port_match else str(TESTGEN_DEFAULT_PORT)
17331734
protocol = "https" if "SSL_CERT_FILE" in contents else "http"
17341735
self._base_url = f"{protocol}://localhost:{port}"
17351736

1736-
if not any((self.update_version, self.update_analytics, self.update_token, self.update_base_url)):
1737+
self.update_api_port = bool(
1738+
re.search(rf"- \d+:{TESTGEN_DEFAULT_PORT}\b", contents)
1739+
and not re.search(rf"- \d+:{TESTGEN_DEFAULT_API_PORT}\b", contents)
1740+
)
1741+
1742+
if not any(
1743+
(
1744+
self.update_version,
1745+
self.update_analytics,
1746+
self.update_token,
1747+
self.update_base_url,
1748+
self.update_api_port,
1749+
)
1750+
):
17371751
CONSOLE.msg("No changes will be applied.")
17381752
raise AbortAction
17391753

17401754
def execute(self, action, args):
1741-
if not any((self.update_version, self.update_analytics, self.update_token, self.update_base_url)):
1755+
if not any(
1756+
(
1757+
self.update_version,
1758+
self.update_analytics,
1759+
self.update_token,
1760+
self.update_base_url,
1761+
self.update_api_port,
1762+
)
1763+
):
17421764
raise SkipStep
17431765

17441766
contents = action.get_compose_file_path(args).read_text()
@@ -1773,6 +1795,11 @@ def execute(self, action, args):
17731795
var = f"\n{match.group(1)}TG_UI_BASE_URL: {self._base_url}"
17741796
contents = contents[0 : match.end()] + var + contents[match.end() :]
17751797

1798+
if self.update_api_port:
1799+
match = re.search(rf"^([ \t]+)- \d+:{TESTGEN_DEFAULT_PORT}\b.*$", contents, flags=re.M)
1800+
new_mapping = f"\n{match.group(1)}- {TESTGEN_DEFAULT_API_PORT}:{TESTGEN_DEFAULT_API_PORT}"
1801+
contents = contents[0 : match.end()] + new_mapping + contents[match.end() :]
1802+
17761803
action.get_compose_file_path(args).write_text(contents)
17771804

17781805

@@ -1879,6 +1906,7 @@ def get_compose_file_contents(self, action, args):
18791906
{ssl_volumes}
18801907
ports:
18811908
- {args.port}:{TESTGEN_DEFAULT_PORT}
1909+
- {args.api_port}:{TESTGEN_DEFAULT_API_PORT}
18821910
extra_hosts:
18831911
- host.docker.internal:host-gateway
18841912
depends_on:
@@ -2019,7 +2047,14 @@ def get_parser(self, sub_parsers):
20192047
dest="port",
20202048
action="store",
20212049
default=TESTGEN_DEFAULT_PORT,
2022-
help="Which port will be used to access Testgen UI. Defaults to %(default)s",
2050+
help="Which port will be used to access TestGen UI. Defaults to %(default)s",
2051+
)
2052+
parser.add_argument(
2053+
"--api-port",
2054+
dest="api_port",
2055+
action="store",
2056+
default=TESTGEN_DEFAULT_API_PORT,
2057+
help="Which port will be used to access TestGen's API and MCP server. Defaults to %(default)s",
20232058
)
20242059
parser.add_argument(
20252060
"--image",

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def args_mock():
170170
ns.compose_project_name = "test-project"
171171
ns.compose_file_name = "test-compose.yml"
172172
ns.port = 8501
173+
ns.api_port = 8530
173174
ns.keep_images = False
174175
ns.keep_config = False
175176
ns.skip_verify = False

0 commit comments

Comments
 (0)