|
89 | 89 | # |
90 | 90 |
|
91 | 91 |
|
| 92 | +def _get_tg_base_url(args): |
| 93 | + protocol = "https" if args.ssl_cert_file and args.ssl_key_file else "http" |
| 94 | + return f"{protocol}://localhost:{args.port}" |
| 95 | + |
| 96 | + |
92 | 97 | def collect_images_digest(action, images, env=None): |
93 | 98 | if images: |
94 | 99 | action.run_cmd( |
@@ -1661,6 +1666,7 @@ def __init__(self): |
1661 | 1666 | self.update_version = False |
1662 | 1667 | self.update_analytics = False |
1663 | 1668 | self.update_token = False |
| 1669 | + self.update_base_url = False |
1664 | 1670 | super().__init__() |
1665 | 1671 |
|
1666 | 1672 | def pre_execute(self, action, args): |
@@ -1720,12 +1726,19 @@ def pre_execute(self, action, args): |
1720 | 1726 |
|
1721 | 1727 | self.update_token = "TG_JWT_HASHING_KEY" not in contents |
1722 | 1728 |
|
1723 | | - if not any((self.update_version, self.update_analytics, self.update_token)): |
| 1729 | + self.update_base_url = "TG_UI_BASE_URL" not in contents |
| 1730 | + if self.update_base_url: |
| 1731 | + port_match = re.search(r"- (\d+):8501", contents) |
| 1732 | + port = port_match.group(1) if port_match else str(TESTGEN_DEFAULT_PORT) |
| 1733 | + protocol = "https" if "SSL_CERT_FILE" in contents else "http" |
| 1734 | + self._base_url = f"{protocol}://localhost:{port}" |
| 1735 | + |
| 1736 | + if not any((self.update_version, self.update_analytics, self.update_token, self.update_base_url)): |
1724 | 1737 | CONSOLE.msg("No changes will be applied.") |
1725 | 1738 | raise AbortAction |
1726 | 1739 |
|
1727 | 1740 | def execute(self, action, args): |
1728 | | - if not any((self.update_version, self.update_analytics, self.update_token)): |
| 1741 | + if not any((self.update_version, self.update_analytics, self.update_token, self.update_base_url)): |
1729 | 1742 | raise SkipStep |
1730 | 1743 |
|
1731 | 1744 | contents = action.get_compose_file_path(args).read_text() |
@@ -1755,6 +1768,11 @@ def execute(self, action, args): |
1755 | 1768 | var = f"\n{match.group(1)}TG_JWT_HASHING_KEY: {str(base64.b64encode(random.randbytes(32)), 'ascii')}" |
1756 | 1769 | contents = contents[0 : match.end()] + match.group(1) + var + contents[match.end() :] |
1757 | 1770 |
|
| 1771 | + if self.update_base_url: |
| 1772 | + match = re.search(r"^([ \t]+)TG_METADATA_DB_HOST:.*$", contents, flags=re.M) |
| 1773 | + var = f"\n{match.group(1)}TG_UI_BASE_URL: {self._base_url}" |
| 1774 | + contents = contents[0 : match.end()] + var + contents[match.end() :] |
| 1775 | + |
1758 | 1776 | action.get_compose_file_path(args).write_text(contents) |
1759 | 1777 |
|
1760 | 1778 |
|
@@ -1787,10 +1805,9 @@ def pre_execute(self, action, args): |
1787 | 1805 |
|
1788 | 1806 | def on_action_success(self, action, args): |
1789 | 1807 | super().on_action_success(action, args) |
1790 | | - protocol = "https" if args.ssl_cert_file and args.ssl_key_file else "http" |
1791 | 1808 | cred_file_path = action.data_folder.joinpath(CREDENTIALS_FILE.format(args.prod)) |
1792 | 1809 | with CONSOLE.tee(cred_file_path) as console_tee: |
1793 | | - console_tee(f"User Interface: {protocol}://localhost:{args.port}") |
| 1810 | + console_tee(f"User Interface: {_get_tg_base_url(args)}") |
1794 | 1811 | console_tee("CLI Access: docker compose exec engine bash") |
1795 | 1812 | console_tee("") |
1796 | 1813 | console_tee(f"Username: {self.username}") |
@@ -1849,6 +1866,7 @@ def get_compose_file_contents(self, action, args): |
1849 | 1866 | TG_EXPORT_TO_OBSERVABILITY_VERIFY_SSL: no |
1850 | 1867 | TG_INSTANCE_ID: {action.analytics.get_instance_id()} |
1851 | 1868 | TG_ANALYTICS: {"yes" if args.send_analytics_data else "no"} |
| 1869 | + TG_UI_BASE_URL: {_get_tg_base_url(args)} |
1852 | 1870 | {ssl_variables} |
1853 | 1871 |
|
1854 | 1872 | services: |
|
0 commit comments