Skip to content

Stop the Windows build driver destroying the user's WSL distribution#212

Open
domiwar wants to merge 1 commit into
apache:0.9.0from
domiwar:fix/windows-wsl-build
Open

Stop the Windows build driver destroying the user's WSL distribution#212
domiwar wants to merge 1 commit into
apache:0.9.0from
domiwar:fix/windows-wsl-build

Conversation

@domiwar

@domiwar domiwar commented Jul 24, 2026

Copy link
Copy Markdown

What

build-and-test-windows.ps1 unregisters and rebuilds its WSL distribution on
every run. It defaulted to the distro named Ubuntu — the default name for a
stock WSL install — and ran wsl --unregister on it with no confirmation.
--unregister deletes the distribution's virtual disk and cannot be undone.

I hit this personally: running the script would have destroyed my main
Ubuntu WSL distribution and everything in it.

Changes

  • Default to a dedicated distro name (openserverless-build) instead of one a
    developer is likely using. Image and distro name are now separate settings
    (WSL_IMAGE / WSL_DISTRO), via wsl --install -d <image> --name <distro>.
  • Write an ownership marker during provisioning; refuse to unregister a distro
    that lacks it without a typed confirmation. -Force skips the prompt for CI.
  • Pin the image to Ubuntu-24.04 (the bare Ubuntu alias tracks latest LTS).

Also fixes Docker never actually installing inside the distro: WSL appends the
Windows PATH, so command -v docker matched Docker Desktop's docker.exe and
the install was skipped. Now strips /mnt/* from PATH, sets
appendWindowsPath=false, downloads the installer to a file instead of
curl | sh, enables the docker service, and waits for the daemon.

Testing

Ran .\build-and-test-windows.ps1 to completion on Windows 11 / WSL 2.6.3:
all build-and-test scripts reported SUCCESS. Ownership-guard logic verified
against real distros (correctly refuses Ubuntu, rebuilds the marked distro).

build-and-test-windows.ps1 unregisters and rebuilds its WSL distribution on
every run. It defaulted to the distro named "Ubuntu" - the default name for a
stock WSL install - and ran `wsl --unregister` on it with no confirmation.
`--unregister` deletes the distribution's virtual disk and cannot be undone,
so running this script would silently destroy a developer's main WSL
environment and everything in it.

- Default to a dedicated distro name ('openserverless-build') instead of a
  name a developer is likely to be using. WSL installs the same image under
  any name via `wsl --install -d <image> --name <distro>`, so the image
  (Ubuntu-24.04) and the distribution name are now separate settings,
  overridable with WSL_IMAGE / WSL_DISTRO.
- Write an ownership marker inside the distribution during provisioning, and
  refuse to unregister a distribution that lacks it without an explicit typed
  confirmation. -Force skips the prompt for CI.
- Pin the image to Ubuntu-24.04; the bare 'Ubuntu' alias tracks the latest
  LTS, so the provisioned distro could drift from the intended one.
- Document the destructive behaviour at the top of the file.

Also fixes the distro never actually getting Docker installed. WSL appends
the Windows PATH, so `command -v docker` matched Docker Desktop's docker.exe
under /mnt/c and the install was skipped, leaving no daemon - surfacing later
as a missing 'docker' group and then an unreachable daemon.

- Strip /mnt/* from PATH during provisioning, and set
  [interop] appendWindowsPath=false in /etc/wsl.conf to keep the distribution
  isolated from the Windows toolchain at runtime.
- Only count a docker binary outside /mnt as installed; fail loudly otherwise.
- Download the get.docker.com installer to a file rather than piping curl into
  sh, which hid failed downloads (sh runs an empty script and exits 0). Add
  `set -o pipefail` for the same reason.
- Enable the docker service rather than a one-shot start, which was discarded
  by the `wsl --shutdown` that follows provisioning, and wait for the daemon
  to accept connections before running the build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant