Skip to content

Commit 387dc20

Browse files
committed
[windows] Rename environment variables for controlling the WDM
The new names are ``RACKER_WDM_VCPUS``, ``RACKER_WDM_MEMORY``, and ``RACKER_WDM_MACHINE``. WDM means "Windows Docker Machine".
1 parent f49c209 commit 387dc20

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ in progress
1919
``windows/servercore:ltsc2016``, ``windows/servercore:ltsc2022``, or
2020
``windows/nanoserver:ltsc2022``.
2121
- Improve documentation about the Windows backend
22+
- Rename environment variables used to control the Windows Docker Machine
23+
subsystem. The new names are ``RACKER_WDM_VCPUS``, ``RACKER_WDM_MEMORY``,
24+
and ``RACKER_WDM_MACHINE``.
2225

2326
2022-05-20 0.2.0
2427
================

doc/cratedb.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Run the CrateDB test suite on OpenJDK 18 (Eclipse Temurin)::
1717

1818
Use the same image, but select a specific operating system version::
1919

20-
export RACKER_VM_BOX=2019-box
20+
export RACKER_WDM_MACHINE=2019-box
2121
racker --verbose run --rm --platform=windows/amd64 eclipse-temurin:18-jdk -- wmic os get caption
2222

2323
Invoke a Java command prompt (JShell) with OpenJDK 18::

doc/winrunner.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ when possible, the image will be launched on a Windows 2022 machine. If you
9898
want to explicitly control on which runner host the container will be launched,
9999
use another environment variable::
100100

101-
export RACKER_VM_BOX=2019-box
101+
export RACKER_WDM_MACHINE=2019-box
102102

103103
If you receive error messages like ``docker: no matching manifest for
104104
windows/amd64 10.0.17763 in the manifest list entries.``, reset this setting
105105
by typing::
106106

107-
unset RACKER_VM_BOX
107+
unset RACKER_WDM_MACHINE
108108

109109
Vagrant stores the boxes in this directory:
110110

@@ -296,7 +296,7 @@ Display Python version, launched within containers in different environments::
296296

297297
# Explicitly select `2019-box` as different host OS.
298298
# The default would be to automatically select `2022-box`.
299-
RACKER_VM_BOX=2019-box racker --verbose run --rm --platform=windows/amd64 winamd64/python:3.11-rc -- python -V
299+
RACKER_WDM_MACHINE=2019-box racker --verbose run --rm --platform=windows/amd64 winamd64/python:3.11-rc -- python -V
300300

301301
# Nano Server
302302
racker --verbose run --rm --platform=windows/amd64 stefanscherer/python-windows:nano -- python -V
@@ -327,7 +327,7 @@ Display Java version, launched within containers in different environments::
327327

328328
# Explicitly select `2019-box` as different host OS.
329329
# The default would be to automatically select `2022-box`.
330-
RACKER_VM_BOX=2019-box racker --verbose run --rm --platform=windows/amd64 openjdk:19 -- java --version
330+
RACKER_WDM_MACHINE=2019-box racker --verbose run --rm --platform=windows/amd64 openjdk:19 -- java --version
331331

332332
# Nano Server
333333
racker --verbose run --rm --platform=windows/amd64 openjdk:19-nanoserver -- java --version

postroj/winrunner.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424

2525
class 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

Comments
 (0)