Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save profnandaa/5f1bf3b834c6e3e20d6d5704f549fd86 to your computer and use it in GitHub Desktop.
Save profnandaa/5f1bf3b834c6e3e20d6d5704f549fd86 to your computer and use it in GitHub Desktop.
Install buildkitd on Windows
$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