2424
2525class WinRunner :
2626
27- VCPUS = os .environ .get ("RACKER_VM_VCPUS " , 6 )
28- MEMORY = os .environ .get ("RACKER_VM_MEMORY " , 6144 )
27+ VCPUS = os .environ .get ("RACKER_WDM_VCPUS " , 6 )
28+ MEMORY = os .environ .get ("RACKER_WDM_MEMORY " , 6144 )
2929
3030 def __init__ (self , image : str ):
3131 self .image_base = image
3232 self .image_real = "racker-runtime/" + self .image_base .replace ("/" , "-" )
3333
34- self .BOX = None
35- self .choose_box ()
36- logger .info (f"Using host machine box image { self .BOX } for launching container image { self .image_base } " )
34+ self .wdm_machine = None
35+ self .choose_wdm_machine ()
36+ logger .info (f"Using WDM host machine { self .wdm_machine } for launching container image { self .image_base } " )
3737
3838 self .workdir = Path (appdirs .user_state_dir (appname = "racker" ))
3939 self .workdir .mkdir (exist_ok = True , parents = True )
@@ -58,9 +58,9 @@ def setup(self):
5858 else :
5959 logger .info (f"Windows Docker Machine already installed into { self .wdmdir } " )
6060
61- def choose_box (self ):
61+ def choose_wdm_machine (self ):
6262 """
63- Choose the right box based on the container image to launch.
63+ Choose the right virtual machine based on the container image to launch.
6464 """
6565
6666 image = self .image_base
@@ -69,8 +69,8 @@ def choose_box(self):
6969
7070 logger .info (f"Inquiring information about OCI image '{ image } '" )
7171
72- if "RACKER_VM_BOX " in os .environ :
73- self .BOX = os .environ ["RACKER_VM_BOX " ]
72+ if "RACKER_WDM_MACHINE " in os .environ :
73+ self .wdm_machine = os .environ ["RACKER_WDM_MACHINE " ]
7474 return
7575
7676 # TODO: Cache the response from `skopeo inspect` to avoid the 3-second speed bump.
@@ -103,12 +103,12 @@ def choose_box(self):
103103 "10.0.20348" : "2022-box" ,
104104 }
105105
106- for os_version , box in os_version_box_map .items ():
106+ for os_version , machine in os_version_box_map .items ():
107107 if image_os_version .startswith (os_version ):
108- self .BOX = box
108+ self .wdm_machine = machine
109109
110- if self .BOX is None :
111- raise ValueError (f"Unable to choose host machine box image for container image { image } , matching OS version { image_os_version } . "
110+ if self .wdm_machine is None :
111+ raise ValueError (f"Unable to choose WDM host machine for container image { image } , matching OS version { image_os_version } . "
112112 f"Please report this error to https://github.com/cicerops/racker/issues/new." )
113113
114114 def start (self , provision = False ):
@@ -129,23 +129,23 @@ def start(self, provision=False):
129129 provision_option = ""
130130 if provision :
131131 provision_option = "--provision"
132- cmd (f"vagrant up --provider=virtualbox { provision_option } { self .BOX } " , cwd = self .wdmdir , use_stderr = True )
132+ cmd (f"vagrant up --provider=virtualbox { provision_option } { self .wdm_machine } " , cwd = self .wdmdir , use_stderr = True )
133133
134134 logger .info ("Pinging Docker context" )
135135 if not self .docker_context_online ():
136- raise IOError (f"Unable to bring up Docker context { self .BOX } " )
136+ raise IOError (f"Unable to bring up Docker context { self .wdm_machine } " )
137137
138138 # Attention: This can run into 60 second timeouts.
139139 # TODO: Use ``with stopit.ThreadingTimeout(timeout) as to_ctx_mgr``.
140140 # TODO: Make timeout values configurable.
141141 # https://github.com/moby/moby/blob/0e04b514fb/integration-cli/docker_cli_run_test.go
142- cmd (f"docker --context={ self .BOX } ps" , capture = True )
142+ cmd (f"docker --context={ self .wdm_machine } ps" , capture = True )
143143
144144 # Skip installing software using Chocolatey for specific Windows OS versions.
145145 # - Windows Nanoserver does not have PowerShell.
146146 # - Windows 2016 croaks like:
147147 # `The command 'cmd /S /C choco install --yes ...' returned a non-zero code: 3221225785`
148- if "nanoserver" in self .image_base or self .BOX == "2016-box" :
148+ if "nanoserver" in self .image_base or self .wdm_machine == "2016-box" :
149149 self .image_real = self .image_base
150150 else :
151151 self .provision_image ()
@@ -163,7 +163,7 @@ def provision_image(self):
163163 logger .info (f"Provisioning Docker image for Windows environment based on { self .image_base } " )
164164 dockerfile = pkg_resources .resource_filename ("postroj" , "winrunner.Dockerfile" )
165165 tmpdir = tempfile .mkdtemp ()
166- command = f"docker --context={ self .BOX } build --platform=windows/amd64 " \
166+ command = f"docker --context={ self .wdm_machine } build --platform=windows/amd64 " \
167167 f"--file={ dockerfile } --build-arg=BASE_IMAGE={ self .image_base } --tag={ self .image_real } { tmpdir } "
168168 logger .debug (f"Running command: { command } " )
169169 try :
@@ -188,7 +188,8 @@ def run(self, command, interactive: bool = False, tty: bool = False):
188188 if interactive or tty :
189189 option_interactive = "-it"
190190
191- command = f"docker --context={ self .BOX } run { option_interactive } --rm { self .image_real } { command } "
191+ # TODO: Propagate ``--rm`` appropriately.
192+ command = f"docker --context={ self .wdm_machine } run { option_interactive } --rm { self .image_real } { command } "
192193
193194 # When an interactive prompt is requested, spawn a shell without further ado.
194195 if interactive or tty :
@@ -203,11 +204,11 @@ def docker_context_online(self):
203204 """
204205 Test if the Docker context is online.
205206 """
206- logger .info (f"Checking connectivity to Docker daemon in Windows context '{ self .BOX } '" )
207+ logger .info (f"Checking connectivity to Docker daemon in Windows context '{ self .wdm_machine } '" )
207208 try :
208- response = cmd (f"docker context inspect { self .BOX } " , capture = True )
209+ response = cmd (f"docker context inspect { self .wdm_machine } " , capture = True )
209210 except :
210- logger .warning (f"Docker context { self .BOX } not online or not created yet" )
211+ logger .warning (f"Docker context { self .wdm_machine } not online or not created yet" )
211212 return False
212213
213214 data = json .loads (response .stdout )
0 commit comments