Skip to content

Commit 59746a8

Browse files
committed
set buildkit version from vendor.mod at build time
Signed-off-by: CrazyMax <[email protected]>
1 parent a461373 commit 59746a8

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

cmd/dockerd/docker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/docker/pkg/reexec"
1212
"github.com/docker/docker/rootless"
1313
"github.com/moby/buildkit/util/apicaps"
14+
bkversion "github.com/moby/buildkit/version"
1415
"github.com/moby/term"
1516
"github.com/sirupsen/logrus"
1617
"github.com/spf13/cobra"
@@ -67,6 +68,9 @@ func init() {
6768
// because the system-wide directories in the current mount namespace are expected to be accessible.
6869
// ("rootful" dockerd in rootless dockerd, #38702)
6970
honorXDG = rootless.RunningWithRootlessKit()
71+
72+
// Set BuildKit version.
73+
bkversion.Version = dockerversion.BuildKitVersion
7074
}
7175

7276
func main() {

dockerversion/version_lib.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ var (
1414
PlatformName = ""
1515
ProductName = ""
1616
DefaultProductLicense = ""
17+
BuildKitVersion = ""
1718
)

hack/make.ps1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,27 @@ Function Run-IntegrationTests() {
372372
}
373373
}
374374

375+
# Same as go-mod-prepare.sh
376+
Function GoModPrepare() {
377+
$gomod = 'module github.com/docker/docker
378+
379+
go 1.17
380+
'
381+
Set-Content -NoNewline -Path 'go.mod' -Value $gomod
382+
383+
$winresGomod = 'module github.com/docker/docker/autogen/winresources/dockerd
384+
385+
go 1.17
386+
'
387+
Set-Content -NoNewline -Path 'hack/make/.resources-windows/go.mod' -Value $winresGomod
388+
}
389+
390+
# Get BuildKit version from vendor.mod
391+
Function Get-BuildKitVersion() {
392+
GoModPrepare
393+
return Invoke-Expression "$env:GO111MODULE='on' ; go list -mod=mod -modfile=vendor.mod -u -m -f '{{.Version}}' github.com/moby/buildkit"
394+
}
395+
375396
# Start of main code.
376397
Try {
377398
Write-Host -ForegroundColor Cyan "INFO: make.ps1 starting at $(Get-Date)"
@@ -421,10 +442,13 @@ Try {
421442
# Verify GOPATH is set
422443
if ($env:GOPATH.Length -eq 0) { Throw "Missing GOPATH environment variable. See https://golang.org/doc/code.html#GOPATH" }
423444

445+
# Set BuildKit version
446+
$buildkitVersion = Get-BuildKitVersion
447+
424448
# Run autogen if building binaries or running unit tests.
425449
if ($Client -or $Daemon -or $TestUnit) {
426450
Write-Host "INFO: Invoking autogen..."
427-
Try { .\hack\make\.go-autogen.ps1 -CommitString $gitCommit -DockerVersion $dockerVersion -Platform "$env:PLATFORM" -Product "$env:PRODUCT" }
451+
Try { .\hack\make\.go-autogen.ps1 -CommitString $gitCommit -DockerVersion $dockerVersion -Platform "$env:PLATFORM" -Product "$env:PRODUCT" -BuildKitVersion $buildkitVersion }
428452
Catch [Exception] { Throw $_ }
429453
}
430454

@@ -516,3 +540,5 @@ Finally {
516540
if ($global:pushed) { Pop-Location }
517541
Write-Host -ForegroundColor Cyan "INFO: make.ps1 ended at $(Get-Date)"
518542
}
543+
544+
}

hack/make/.go-autogen

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LDFLAGS="${LDFLAGS} \
1414
-X \"github.com/docker/docker/dockerversion.PlatformName=${PLATFORM}\" \
1515
-X \"github.com/docker/docker/dockerversion.ProductName=${PRODUCT}\" \
1616
-X \"github.com/docker/docker/dockerversion.DefaultProductLicense=${DEFAULT_PRODUCT_LICENSE}\" \
17+
-X \"github.com/docker/docker/dockerversion.BuildKitVersion=$(GO111MODULE=on go list -mod=mod -modfile=vendor.mod -u -m -f '{{.Version}}' "github.com/moby/buildkit")\" \
1718
"
1819

1920
# Compile the Windows resources into the sources

hack/make/.go-autogen.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ param(
1717
[Parameter(Mandatory=$true)][string]$DockerVersion,
1818
[Parameter(Mandatory=$false)][string]$Platform,
1919
[Parameter(Mandatory=$false)][string]$Product,
20-
[Parameter(Mandatory=$false)][string]$DefaultProductLicense
20+
[Parameter(Mandatory=$false)][string]$DefaultProductLicense,
21+
[Parameter(Mandatory=$false)][string]$BuildKitVersion
2122
)
2223

2324
$ErrorActionPreference = "Stop"
@@ -49,6 +50,7 @@ const (
4950
PlatformName string = "'+$Platform+'"
5051
ProductName string = "'+$Product+'"
5152
DefaultProductLicense string = "'+$DefaultProductLicense+'"
53+
BuildKitVersion string = "'+$BuildKitVersion+'"
5254
)
5355
5456
// AUTOGENERATED FILE; see hack\make\.go-autogen.ps1
@@ -58,6 +60,7 @@ const (
5860
$outputFile="$(Get-Location)\dockerversion\version_autogen.go"
5961
if (Test-Path $outputFile) { Remove-Item $outputFile }
6062
[System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))
63+
Get-Content $outputFile | Out-Host
6164

6265
New-Item -ItemType Directory -Path "autogen\winresources\tmp" | Out-Null
6366
New-Item -ItemType Directory -Path "autogen\winresources\dockerd" | Out-Null

0 commit comments

Comments
 (0)