Last active
July 7, 2024 17:44
-
-
Save gabriel-samfira/6e56238ad11c24f490ac109bdd378471 to your computer and use it in GitHub Desktop.
Install buildkitd on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference="Stop" | |
$containerdDir = join-path $env:ProgramFiles containerd | |
if (!(Test-Path $containerdDir)){ | |
mkdir $containerdDir | |
} | |
$downloadPath = Join-Path $env:Tmp "containerd.tar.gz" | |
$downloadLink = "https://github.com/containerd/containerd/releases/download/v1.7.5/containerd-1.7.5-windows-amd64.tar.gz" | |
$cli = [System.Net.WebClient]::new() | |
$cli.DownloadFile($downloadLink, $downloadPath) | |
tar xf $downloadPath -C $containerdDir | |
if ($LASTEXITCODE) { | |
Throw "failed to extract containerd" | |
} | |
$cniDir = Join-Path $containerdDir "cni" | |
$cniConfDir = Join-Path $cniDir "conf" | |
$cniBinDir = Join-Path $cniDir "bin" | |
$cniConfPath = Join-Path $cniConfDir "0-containerd-nat.conf" | |
if (!(Test-Path $cniBinDir)) { | |
mkdir $cniBinDir | |
} | |
$prepareEnvScriptLink = "https://gist.githubusercontent.com/gabriel-samfira/c80ccb1d79be737e5e61214181e48ad8/raw/e393047c93b1755897cf0a1efc786557aba1f428/prepare_env_windows.ps1" | |
$prepareEnvScriptPath = Join-Path $env:TMP "prepare_env_windows.ps1" | |
$cli.DownloadFile($prepareEnvScriptLink, $prepareEnvScriptPath) | |
& $prepareEnvScriptPath | |
git clone https://github.com/Microsoft/windows-container-networking $HOME\windows-container-networking | |
cd $HOME\windows-container-networking | |
git checkout aa10a0b31e9f72937063436454def1760b858ee2 | |
make all | |
cp .\out\*.exe $cniBinDir\ | |
if (!(Test-Path $cniConfDir)) { | |
mkdir $cniConfDir | |
} | |
Set-Content $cniConfPath @" | |
{ | |
"cniVersion": "0.2.0", | |
"name": "nat", | |
"type": "nat", | |
"master": "Ethernet", | |
"ipam": { | |
"subnet": "172.19.208.0/20", | |
"routes": [ | |
{ | |
"GW": "172.19.208.1" | |
} | |
] | |
}, | |
"capabilities": { | |
"portMappings": true, | |
"dns": true | |
} | |
} | |
"@ | |
& 'C:\Program Files\containerd\bin\containerd.exe' --register-service --log-level debug --service-name containerd --log-file C:/Windows/temp/containerd.log | |
Set-Service containerd -StartupType Automatic | |
Start-Service containerd | |
Get-HnsEndpoint | Remove-HnsEndpoint | |
git clone https://github.com/moby/buildkit.git $HOME/buildkit | |
cd $HOME/buildkit | |
go install .\cmd\... | |
if ($LASTEXITCODE) { | |
Throw "failed to build buildkitd" | |
} | |
$goDir = (go env GOPATH) | |
$goBinDir = Join-Path $goDir "bin" | |
$buildkitdPath = Join-Path $env:ProgramFiles buildkitd | |
$buildkitBinDir = Join-Path $buildkitdPath "bin" | |
if (!(Test-Path $buildkitBinDir)) { | |
mkdir $buildkitBinDir | |
} | |
cp $goBinDir\buildkitd.exe $buildkitBinDir | |
cp $goBinDir\buildctl.exe $buildkitBinDir | |
$buildkitdExecutablePath = Join-Path $buildkitBinDir "buildkitd.exe" | |
& $buildkitdExecutablePath --register-service --debug --containerd-worker=true "--containerd-cni-config-path=$cniConfPath" "--containerd-cni-binary-dir=$cniBinDir" --service-name buildkitd | |
if ($LASTEXITCODE) { | |
Throw "failed to install buildkitd service" | |
} | |
Set-Service buildkitd -StartupType Automatic | |
sc.exe config buildkitd depend= containerd | |
if ($LASTEXITCODE) { | |
Throw "failed set dependency for buildkitd on containerd" | |
} | |
Start-Service buildkitd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment