Skip to content

Commit bfac818

Browse files
authored
Merge pull request #3280 from arixmkii/fix-windows-ci
Enable Integration tests in Windows CI
2 parents cacbbc6 + 22d86cc commit bfac818

File tree

6 files changed

+96
-55
lines changed

6 files changed

+96
-55
lines changed

.github/workflows/test.yml

+11-20
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,10 @@ jobs:
135135
- name: Enable WSL2
136136
run: |
137137
wsl --set-default-version 2
138-
# Manually install the latest kernel from MSI
139-
Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile "wsl_update_x64.msi"
140-
$pwd = (pwd).Path
141-
Start-Process msiexec.exe -Wait -ArgumentList "/I $pwd\wsl_update_x64.msi /quiet"
138+
wsl --shutdown
142139
wsl --update
143140
wsl --status
141+
wsl --version
144142
wsl --list --online
145143
- name: Install WSL2 distro
146144
timeout-minutes: 1
@@ -166,22 +164,15 @@ jobs:
166164
run: go test -v ./...
167165
- name: Make
168166
run: make
169-
# FIXME: Windows CI began to fail on Oct 21, 2024.
170-
# Something seems to have changed between win22/20241006.1 and win22/20241015.1.
171-
# https://github.com/lima-vm/lima/issues/2775
172-
# - name: Smoke test
173-
# # Make sure the path is set properly and then run limactl
174-
# run: |
175-
# $env:Path = 'C:\Program Files\Git\usr\bin;' + $env:Path
176-
# Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $env:Path
177-
# .\_output\bin\limactl.exe start template://experimental/wsl2
178-
# # TODO: run the full integration tests
179-
# - name: Debug
180-
# if: always()
181-
# run: type C:\Users\runneradmin\.lima\wsl2\ha.stdout.log
182-
# - name: Debug
183-
# if: always()
184-
# run: type C:\Users\runneradmin\.lima\wsl2\ha.stderr.log
167+
- name: Integration tests (WSL2, Windows host)
168+
run: |
169+
$env:Path = "$pwd\_output\bin;" + 'C:\Program Files\Git\usr\bin;' + $env:Path
170+
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $env:Path
171+
$env:MSYS2_ENV_CONV_EXCL='HOME_HOST;HOME_GUEST'
172+
$env:HOME_HOST=$(cygpath.exe "$env:USERPROFILE")
173+
$env:HOME_GUEST="/mnt$env:HOME_HOST"
174+
$env:LIMACTL_CREATE_ARGS='--vm-type=wsl2 --mount-type=wsl2 --containerd=system'
175+
bash.exe -c "./hack/test-templates.sh templates/experimental/wsl2.yaml"
185176
186177
qemu:
187178
name: "Integration tests (QEMU, macOS host)"

hack/common.inc.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [[ ${BASH_VERSINFO:-0} -lt 4 ]]; then
2323
exit 1
2424
fi
2525

26-
: "${LIMA_HOME:=$HOME/.lima}"
26+
: "${LIMA_HOME:=${HOME_HOST:-$HOME}/.lima}"
2727
_IPERF3=iperf3
2828
# iperf3-darwin does some magic on macOS to avoid "No route on host" on macOS 15
2929
# https://github.com/lima-vm/socket_vmnet/issues/85

hack/test-mount-home.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ if [ "$#" -ne 1 ]; then
1515
fi
1616

1717
NAME="$1"
18-
hometmp="$HOME/lima-test-tmp"
18+
hometmp="${HOME_HOST:-$HOME}/lima-test-tmp"
19+
hometmpguest="${HOME_GUEST:-$HOME}/lima-test-tmp"
1920
INFO "Testing home access (\"$hometmp\")"
2021
rm -rf "$hometmp"
2122
mkdir -p "$hometmp"
2223
defer "rm -rf \"$hometmp\""
2324
echo "random-content-${RANDOM}" >"$hometmp/random"
2425
expected="$(cat "$hometmp/random")"
25-
got="$(limactl shell "$NAME" cat "$hometmp/random")"
26+
got="$(limactl shell "$NAME" cat "$hometmpguest/random")"
2627
INFO "$hometmp/random: expected=${expected}, got=${got}"
2728
if [ "$got" != "$expected" ]; then
2829
ERROR "Home directory is not shared?"

hack/test-port-forwarding.pl

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
sleep 5;
130130

131131
# Record current log size, so we can skip prior output
132-
$ENV{LIMA_HOME} ||= "$ENV{HOME}/.lima";
132+
$ENV{HOME_HOST} ||= "$ENV{HOME}";
133+
$ENV{LIMA_HOME} ||= "$ENV{HOME_HOST}/.lima";
133134
my $ha_log = "$ENV{LIMA_HOME}/$instance/ha.stderr.log";
134135
my $ha_log_size = -s $ha_log or die;
135136

hack/test-templates.sh

+76-31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
set -eu -o pipefail
77

8+
# will prevent msys2 converting Linux path arguments into Windows paths before passing to limactl
9+
export MSYS2_ARG_CONV_EXCL='*'
10+
811
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
912
# shellcheck source=common.inc.sh
1013
source "${scriptdir}/common.inc.sh"
@@ -16,16 +19,27 @@ fi
1619

1720
FILE="$1"
1821
NAME="$(basename -s .yaml "$FILE")"
22+
OS_HOST="$(uname -o)"
23+
24+
# On Windows $HOME of the bash runner, %USERPROFILE% of the host machine and mpunting point in the guest machine
25+
# are all different folders. This will handle path differences, when values are expilictly set.
26+
HOME_HOST=${HOME_HOST:-$HOME}
27+
HOME_GUEST=${HOME_GUEST:-$HOME}
28+
FILE_HOST=$FILE
29+
if [ "${OS_HOST}" = "Msys" ]; then
30+
FILE_HOST="$(cygpath -w "$FILE")"
31+
fi
1932

20-
INFO "Validating \"$FILE\""
21-
limactl validate "$FILE"
33+
INFO "Validating \"$FILE_HOST\""
34+
limactl validate "$FILE_HOST"
2235

2336
# --cpus=1 is needed for running vz on GHA: https://github.com/lima-vm/lima/pull/1511#issuecomment-1574937888
2437
LIMACTL_CREATE=(limactl --tty=false create --cpus=1 --memory=1)
2538

2639
CONTAINER_ENGINE="nerdctl"
2740

2841
declare -A CHECKS=(
42+
["proxy-settings"]="1"
2943
["systemd"]="1"
3044
["systemd-strict"]="1"
3145
["mount-home"]="1"
@@ -73,6 +87,13 @@ case "$NAME" in
7387
"docker")
7488
CONTAINER_ENGINE="docker"
7589
;;
90+
"wsl2")
91+
# TODO https://github.com/lima-vm/lima/issues/3267
92+
CHECKS["systemd"]=
93+
# TODO https://github.com/lima-vm/lima/issues/3268
94+
CHECKS["proxy-settings"]=
95+
CHECKS["port-forwards"]=
96+
;;
7697
esac
7798

7899
if limactl ls -q | grep -q "$NAME"; then
@@ -84,7 +105,7 @@ fi
84105
# TODO: skip downloading and converting the image here.
85106
# Probably `limactl create` should have "dry run" mode that just generates `lima.yaml`.
86107
# shellcheck disable=SC2086
87-
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} --set ".additionalDisks=null" --name="${NAME}-tmp" "$FILE"
108+
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} --set ".additionalDisks=null" --name="${NAME}-tmp" "$FILE_HOST"
88109
case "$(yq '.networks[].lima' "${LIMA_HOME}/${NAME}-tmp/lima.yaml")" in
89110
"shared")
90111
CHECKS["vmnet"]=1
@@ -97,32 +118,38 @@ esac
97118
limactl rm -f "${NAME}-tmp"
98119

99120
if [[ -n ${CHECKS["port-forwards"]} ]]; then
100-
tmpconfig="$HOME/lima-config-tmp"
121+
tmpconfig="$HOME_HOST/lima-config-tmp"
101122
mkdir -p "${tmpconfig}"
102123
defer "rm -rf \"$tmpconfig\""
103124
tmpfile="${tmpconfig}/${NAME}.yaml"
104125
cp "$FILE" "${tmpfile}"
105126
FILE="${tmpfile}"
127+
FILE_HOST=$FILE
128+
if [ "${OS_HOST}" = "Msys" ]; then
129+
FILE_HOST="$(cygpath -w "$FILE")"
130+
fi
131+
106132
INFO "Setup port forwarding rules for testing in \"${FILE}\""
107133
"${scriptdir}/test-port-forwarding.pl" "${FILE}"
108-
limactl validate "$FILE"
134+
INFO "Validating \"$FILE_HOST\""
135+
limactl validate "$FILE_HOST"
109136
fi
110137

111138
function diagnose() {
112139
NAME="$1"
113140
set -x +e
114-
tail "$HOME/.lima/${NAME}"/*.log
141+
tail "$HOME_HOST/.lima/${NAME}"/*.log
115142
limactl shell "$NAME" systemctl --no-pager status
116143
limactl shell "$NAME" systemctl --no-pager
117144
mkdir -p failure-logs
118-
cp -pf "$HOME/.lima/${NAME}"/*.log failure-logs/
145+
cp -pf "$HOME_HOST/.lima/${NAME}"/*.log failure-logs/
119146
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log
120147
set +x -e
121148
}
122149

123150
export ftp_proxy=http://localhost:2121
124151

125-
INFO "Creating \"$NAME\" from \"$FILE\""
152+
INFO "Creating \"$NAME\" from \"$FILE_HOST\""
126153
defer "limactl delete -f \"$NAME\""
127154

128155
if [[ -n ${CHECKS["disk"]} ]]; then
@@ -134,7 +161,7 @@ fi
134161

135162
set -x
136163
# shellcheck disable=SC2086
137-
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} "$FILE"
164+
"${LIMACTL_CREATE[@]}" ${LIMACTL_CREATE_ARGS} "$FILE_HOST"
138165
set +x
139166

140167
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
@@ -156,7 +183,7 @@ limactl shell "$NAME" cat /etc/os-release
156183
set +x
157184

158185
INFO "Testing that host home is not wiped out"
159-
[ -e "$HOME/.lima" ]
186+
[ -e "$HOME_HOST/.lima" ]
160187

161188
if [[ -n ${CHECKS["mount-path-with-spaces"]} ]]; then
162189
INFO 'Testing that "/tmp/lima test dir with spaces" is not wiped out'
@@ -183,23 +210,26 @@ if [[ -n ${CHECKS["set-user"]} ]]; then
183210
limactl shell "$NAME" grep "^john:x:4711:4711:John Doe:/home/john-john" /etc/passwd
184211
fi
185212

186-
INFO "Testing proxy settings are imported"
187-
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
188-
# Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
189-
# by the gateway address, and the value is set immediately without a restart
190-
gatewayIp=$(limactl shell "$NAME" ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
191-
expected="FTP_PROXY=http://${gatewayIp}:2121"
192-
INFO "FTP_PROXY: expected=${expected} got=${got}"
193-
if [ "$got" != "$expected" ]; then
194-
ERROR "proxy environment variable not set to correct value"
195-
exit 1
213+
if [[ -n ${CHECKS["proxy-settings"]} ]]; then
214+
INFO "Testing proxy settings are imported"
215+
got=$(limactl shell "$NAME" env | grep FTP_PROXY)
216+
# Expected: FTP_PROXY is set in addition to ftp_proxy, localhost is replaced
217+
# by the gateway address, and the value is set immediately without a restart
218+
gatewayIp=$(limactl shell "$NAME" ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3)
219+
expected="FTP_PROXY=http://${gatewayIp}:2121"
220+
INFO "FTP_PROXY: expected=${expected} got=${got}"
221+
if [ "$got" != "$expected" ]; then
222+
ERROR "proxy environment variable not set to correct value"
223+
exit 1
224+
fi
196225
fi
197226

198227
INFO "Testing limactl copy command"
199228
tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/lima-test-templates.XXXXXX)"
200229
defer "rm -rf \"$tmpdir\""
201230
tmpfile="$tmpdir/lima-hostname"
202231
rm -f "$tmpfile"
232+
# TODO support Windows path https://github.com/lima-vm/lima/issues/3215
203233
limactl cp "$NAME":/etc/hostname "$tmpfile"
204234
expected="$(limactl shell "$NAME" cat /etc/hostname)"
205235
got="$(cat "$tmpfile")"
@@ -238,32 +268,38 @@ nginx_image="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
238268
alpine_image="ghcr.io/containerd/alpine:3.14.0"
239269

240270
if [[ -n ${CHECKS["container-engine"]} ]]; then
271+
sudo=""
272+
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
273+
if [[ "$(limactl ls --json "${NAME}" | jq -r .vmType)" == "wsl2" ]]; then
274+
sudo="sudo"
275+
fi
241276
INFO "Run a nginx container with port forwarding 127.0.0.1:8080"
242277
set -x
243-
if ! limactl shell "$NAME" $CONTAINER_ENGINE info; then
244-
limactl shell "$NAME" sudo cat /var/log/cloud-init-output.log
278+
if ! limactl shell "$NAME" $sudo $CONTAINER_ENGINE info; then
279+
limactl shell "$NAME" cat /var/log/cloud-init-output.log
245280
ERROR "\"${CONTAINER_ENGINE} info\" failed"
246281
exit 1
247282
fi
248-
limactl shell "$NAME" $CONTAINER_ENGINE pull --quiet ${nginx_image}
249-
limactl shell "$NAME" $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
283+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
284+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE run -d --name nginx -p 127.0.0.1:8080:80 ${nginx_image}
250285

251286
timeout 3m bash -euxc "until curl -f --retry 30 --retry-connrefused http://127.0.0.1:8080; do sleep 3; done"
252287

253-
limactl shell "$NAME" $CONTAINER_ENGINE rm -f nginx
288+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
254289
set +x
255290
if [[ -n ${CHECKS["mount-home"]} ]]; then
256-
hometmp="$HOME/lima-container-engine-test-tmp"
291+
hometmp="$HOME_HOST/lima-container-engine-test-tmp"
292+
hometmpguest="$HOME_GUEST/lima-container-engine-test-tmp"
257293
# test for https://github.com/lima-vm/lima/issues/187
258294
INFO "Testing home bind mount (\"$hometmp\")"
259295
rm -rf "$hometmp"
260296
mkdir -p "$hometmp"
261297
defer "rm -rf \"$hometmp\""
262298
set -x
263-
limactl shell "$NAME" $CONTAINER_ENGINE pull --quiet ${alpine_image}
299+
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${alpine_image}
264300
echo "random-content-${RANDOM}" >"$hometmp/random"
265301
expected="$(cat "$hometmp/random")"
266-
got="$(limactl shell "$NAME" $CONTAINER_ENGINE run --rm -v "$hometmp/random":/mnt/foo ${alpine_image} cat /mnt/foo)"
302+
got="$(limactl shell "$NAME" $sudo $CONTAINER_ENGINE run --rm -v "$hometmpguest/random":/mnt/foo ${alpine_image} cat /mnt/foo)"
267303
INFO "$hometmp/random: expected=${expected}, got=${got}"
268304
if [ "$got" != "$expected" ]; then
269305
ERROR "Home directory is not shared?"
@@ -288,6 +324,9 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
288324
if [ "${NAME}" = "opensuse" ]; then
289325
limactl shell "$NAME" sudo zypper in -y netcat-openbsd
290326
fi
327+
if limactl shell "$NAME" command -v dnf; then
328+
limactl shell "$NAME" sudo dnf install -y nc
329+
fi
291330
"${scriptdir}/test-port-forwarding.pl" "${NAME}"
292331

293332
if [[ -n ${CHECKS["container-engine"]} || ${NAME} == "alpine"* ]]; then
@@ -310,6 +349,10 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
310349
rm nerdctl-full.tgz
311350
sudo="sudo"
312351
fi
352+
# Currently WSL2 machines only support privileged engine. This requirement might be lifted in the future.
353+
if [[ "$(limactl ls --json "${NAME}" | jq -r .vmType)" == "wsl2" ]]; then
354+
sudo="sudo"
355+
fi
313356
limactl shell "$NAME" $sudo $CONTAINER_ENGINE info
314357
limactl shell "$NAME" $sudo $CONTAINER_ENGINE pull --quiet ${nginx_image}
315358

@@ -364,7 +407,8 @@ if [[ -n ${CHECKS["restart"]} ]]; then
364407
fi
365408

366409
INFO "Stopping \"$NAME\""
367-
limactl stop "$NAME"
410+
# TODO https://github.com/lima-vm/lima/issues/3221
411+
limactl stop "$NAME" || [ "${OS_HOST}" = "Msys" ]
368412
sleep 3
369413

370414
if [[ -n ${CHECKS["disk"]} ]]; then
@@ -410,7 +454,7 @@ fi
410454
if [[ -n ${CHECKS["user-v2"]} ]]; then
411455
INFO "Testing user-v2 network"
412456
secondvm="$NAME-1"
413-
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE" --name "$secondvm"
457+
"${LIMACTL_CREATE[@]}" --set ".additionalDisks=null" "$FILE_HOST" --name "$secondvm"
414458
if ! limactl start "$secondvm"; then
415459
ERROR "Failed to start \"$secondvm\""
416460
diagnose "$secondvm"
@@ -478,7 +522,8 @@ if [[ $NAME == "fedora" && "$(limactl ls --json "$NAME" | jq -r .vmType)" == "vz
478522
fi
479523

480524
INFO "Stopping \"$NAME\""
481-
limactl stop "$NAME"
525+
# TODO https://github.com/lima-vm/lima/issues/3221
526+
limactl stop "$NAME" || [ "${OS_HOST}" = "Msys" ]
482527
sleep 3
483528

484529
INFO "Deleting \"$NAME\""

pkg/osutil/user.go

+3
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ func LimaUser(limaVersion string, warn bool) *user.User {
147147
home, err := call([]string{"cygpath", limaUser.HomeDir})
148148
if err != nil {
149149
logrus.Debug(err)
150+
} else {
151+
home += ".linux"
150152
}
151153
if home == "" {
152154
drive := filepath.VolumeName(limaUser.HomeDir)
153155
home = filepath.ToSlash(limaUser.HomeDir)
154156
// replace C: with /c
155157
prefix := strings.ToLower(fmt.Sprintf("/%c", drive[0]))
156158
home = strings.Replace(home, drive, prefix, 1)
159+
home += ".linux"
157160
}
158161
if !regexPath.MatchString(limaUser.HomeDir) {
159162
warning := fmt.Sprintf("local home %q is not a valid Linux path (must match %q); using %q home instead",

0 commit comments

Comments
 (0)