Skip to content

Commit

Permalink
keepwsl
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Feb 10, 2025
1 parent 76c28f2 commit 0660c50
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions .github/workflows/win-wsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: windows-2022

steps:
- name: Start Ubuntu WSL
- name: Prepare WSL
run: |
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
Expand All @@ -17,31 +17,69 @@ 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
try { wsl cat /etc/wsl.conf } catch { Write-Warning "$_" }
try { wsl ls -la /mnt/c/Windows/System32/wsl.exe } catch { Write-Warning "$_" }
# https://github.com/microsoft/WSL/issues/10138#issuecomment-2380431569
# @'
# [automount]
# enabled=true
# '@ | & wsl tee -a /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.service
& wsl -- systemctl status
& wsl -- systemctl daemon-reload
& wsl -- systemctl show keepwsl.service
& wsl -- systemctl start keepwsl.service
Start-Sleep -Seconds 5
& wsl -- systemctl status keepwsl.service
# & wsl --shutdown
- name: Start k0s controller in WSL
id: start-controller
run: |
$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://get.k0s.sh | 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 -- systemctl status
& wsl -- systemctl start k0scontroller.service
- 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
Expand Down Expand Up @@ -129,5 +167,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

0 comments on commit 0660c50

Please sign in to comment.