From 38e52509734e85da7fa2b4dd0d625cdd1af62f4d Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Mon, 10 Feb 2025 09:44:50 +0100 Subject: [PATCH] keepwsl Signed-off-by: Tom Wieczorek --- .github/workflows/win-wsl.yaml | 59 ++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/.github/workflows/win-wsl.yaml b/.github/workflows/win-wsl.yaml index f0a771efba95..42302d5b21a7 100644 --- a/.github/workflows/win-wsl.yaml +++ b/.github/workflows/win-wsl.yaml @@ -8,7 +8,7 @@ jobs: runs-on: windows-2022 steps: - - name: Start Ubuntu WSL + - name: Prepare WSL run: | $ErrorActionPreference = "Stop" $PSNativeCommandUseErrorActionPreference = $true @@ -17,8 +17,31 @@ jobs: & wsl --set-default-version 2 & wsl --install Ubuntu & wsl --set-default Ubuntu - # https://github.com/microsoft/WSL/issues/10138#issuecomment-1593856698 - & wsl --exec dbus-launch true + + # https://github.com/microsoft/WSL/issues/10138#issuecomment-2380431569 + + @' + [boot] + systemd=true + + [automount] + enabled = true + '@ | & wsl tee /etc/wsl.conf + + & wsl -- mkdir -p /usr/local/lib/systemd/system + @' + [Unit] + Description=A simple service to keep WSL alive + Documentation=https://github.com/gardengim/keepwsl + + [Service] + ExecStart=/mnt/c/Windows/System32/wsl.exe sleep infinity + + [Install] + WantedBy=default.target + '@ | & wsl tee /usr/local/lib/systemd/keepwsl.conf + + & wsl --shutdown - name: Start k0s controller in WSL id: start-controller @@ -26,22 +49,30 @@ jobs: $ErrorActionPreference = "Stop" $PSNativeCommandUseErrorActionPreference = $true - $addr = (& wsl hostname -i).Split(" ")[-1] - Write-Host "Using $addr" - & wsl sh -c 'curl --proto =https --tlsv1.2 -sSf https://get.k0s.sh | sh' - & wsl sh -c "mkdir /etc/k0s && echo spec: \{api: \{address: $addr\}, storage: \{type: kine\}, network: \{provider: calico\}\} >/etc/k0s/k0s.yaml" - & wsl cat /etc/k0s/k0s.yaml - & wsl k0s install controller --debug --disable-components metrics-server - & wsl k0s start + & wsl -- bash -euo pipefail -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh' + & wsl mkdir /etc/k0s + @" + spec: + api: + address: $((& wsl hostname -i).Split(" ")[-1]) + storage: + type: kine + network + provider: calico + "@ | & wsl tee /etc/k0s/k0s.yaml + + & wsl -- k0s install controller --debug --disable-components metrics-server + & wsl -- k0s start - name: Download k0s for Windows run: | $ErrorActionPreference = "Stop" $PSNativeCommandUseErrorActionPreference = $true - $k0sVersion = (Invoke-WebRequest -URI https://docs.k0sproject.io/latest.txt).Content.Trim() + $k0sVersion = (Invoke-WebRequest -Uri https://docs.k0sproject.io/latest.txt).Content.Trim() + $url = "https://github.com/k0sproject/k0s/releases/download/$k0sVersion/k0s-${k0sVersion}-amd64.exe" Write-Host "Downloading k0s $k0sVersion" - & curl --proto =https --tlsv1.2 --retry 5 --retry-all-errors -sSLfo k0s.exe "https://github.com/k0sproject/k0s/releases/download/$k0sVersion/k0s-${k0sVersion}-amd64.exe" + Invoke-WebRequest -Uri $url -OutFile k0s.exe & .\k0s version - name: Prepare kubeconfig @@ -129,5 +160,5 @@ jobs: - name: k0 controller logs if: always() && steps.start-controller.conclusion == 'success' run: | - wsl systemctl status k0scontroller.service - wsl journalctl -u k0scontroller.service + & wsl systemctl status k0scontroller.service + & wsl journalctl -u k0scontroller.service