2121import click
2222import paramiko
2323
24- from environment .aws .common .io import LIGHT_GRAY , sftp_progress_bar
24+ from environment .aws .common .docker import start_container
25+ from environment .aws .common .io import LIGHT_GRAY , get_ec2_hostname , sftp_progress_bar
2526from environment .aws .common .output import header
2627from environment .aws .topology_setup .setup_topology import TopologyConfig
2728
@@ -63,6 +64,7 @@ def setup_node(
6364 hostname : str ,
6465 pkey : paramiko .Ed25519Key | None ,
6566 version : str ,
67+ tag : str ,
6668 cluster : str | None = None ,
6769) -> None :
6870 """
@@ -74,11 +76,6 @@ def setup_node(
7476 version (str): The version of Couchbase Server to install.
7577 cluster (Optional[str]): The cluster to join, if any.
7678 """
77- couchbase_filename = f"couchbase-server-enterprise-{ version } -linux.x86_64.rpm"
78- couchbase_url = (
79- f"http://packages.couchbase.com/releases/{ version } /{ couchbase_filename } "
80- )
81-
8279 header (f"Setting up server { hostname } with version { version } " )
8380 ssh = paramiko .SSHClient ()
8481 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
@@ -90,45 +87,42 @@ def setup_node(
9087 sftp_progress_bar (
9188 sftp , SCRIPT_DIR / "configure-system.sh" , "/tmp/configure-system.sh"
9289 )
93- sftp_progress_bar (
94- sftp , SCRIPT_DIR / "disable-thp.service" , "/tmp/disable-thp.service"
95- )
9690 sftp .close ()
9791
9892 global current_ssh
9993 current_ssh = hostname
10094
101- remote_exec (ssh , "sudo bash /tmp/configure-system.sh" , "Setting up machine" )
10295 remote_exec (
10396 ssh ,
104- f"wget -nc -O /tmp/{ couchbase_filename } { couchbase_url } 2>&1" ,
105- f"Downloading Couchbase Server { version } " ,
106- fail_on_error = False ,
107- )
108- remote_exec (
109- ssh ,
110- "sudo rpm -e couchbase-server" ,
111- "Uninstalling Couchbase Server" ,
112- fail_on_error = False ,
113- )
114- remote_exec (
115- ssh ,
116- f"sudo rpm -i /tmp/{ couchbase_filename } " ,
117- f"Installing Couchbase Server { version } " ,
118- )
119- remote_exec (
120- ssh , "sudo systemctl start couchbase-server" , "Starting Couchbase Server"
97+ "chmod +x /tmp/configure-node.sh && bash /tmp/configure-system.sh" ,
98+ "Setting up machine" ,
12199 )
100+ ssh .close ()
122101
123- # Some magic here that might be overlooked. If we pass in a cluster
124- # address to the configure node script, it will join an existing cluster
125- # rather than using itself to create a new one
126- config_command = "bash /tmp/configure-node.sh"
127- if cluster is not None :
128- config_command += f" { cluster } "
129- remote_exec ( ssh , config_command , "Setting up node" )
102+ ec2_hostname = get_ec2_hostname ( hostname )
103+ docker_args = [
104+ "--network" ,
105+ "host" ,
106+ "-v" ,
107+ "/tmp/configure-node.sh:/etc/service/couchbase-config/run" ,
108+ ]
130109
131- ssh .close ()
110+ if cluster is not None :
111+ docker_args .extend (
112+ [
113+ "-e" ,
114+ f"E2E_PARENT_CLUSTER={ cluster } " ,
115+ ]
116+ )
117+ context_name = "cbs" if tag == "" else f"cbs-{ tag } "
118+ start_container (
119+ "cbs-e2e" ,
120+ context_name ,
121+ f"couchbase/server:enterprise-{ version } " ,
122+ ec2_hostname ,
123+ docker_args ,
124+ replace_existing = True ,
125+ )
132126
133127
134128def setup_topology (pkey : paramiko .Ed25519Key | None , topology : TopologyConfig ) -> None :
@@ -144,10 +138,19 @@ def setup_topology(pkey: paramiko.Ed25519Key | None, topology: TopologyConfig) -
144138 return
145139
146140 for cluster_config in topology .clusters :
147- setup_node (cluster_config .public_hostnames [0 ], pkey , cluster_config .version )
141+ setup_node (
142+ cluster_config .public_hostnames [0 ],
143+ pkey ,
144+ cluster_config .version ,
145+ topology .tag ,
146+ )
148147 for server in cluster_config .public_hostnames [1 :]:
149148 setup_node (
150- server , pkey , cluster_config .version , cluster_config .public_hostnames [0 ]
149+ server ,
150+ pkey ,
151+ cluster_config .version ,
152+ topology .tag ,
153+ cluster_config .internal_hostnames [0 ],
151154 )
152155
153156
0 commit comments