Skip to content

fix: Detect Buildkit version at runtime #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
--privileged \
--name "buildkitd_${GITHUB_RUN_ID}_${SUFFIX}" \
-v /run/buildkit:/run/buildkit:rw \
moby/buildkit:v0.18.1;
moby/buildkit:v0.18.2;
timeout 60 bash -c 'while [ ! -S "/run/buildkit/buildkitd.sock" ]; do sleep 1; done'
sudo chmod 666 /run/buildkit/buildkitd.sock;
env:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ runs:
--privileged \
--name buildkitd_${GITHUB_RUN_ID}_${SUFFIX} \
-v /run/buildkit:/run/buildkit:rw \
moby/buildkit:v0.18.1;
moby/buildkit:v0.18.2;
timeout 60 bash -c 'while [ ! -S "/run/buildkit/buildkitd.sock" ]; do sleep 1; done'
sudo chmod 666 /run/buildkit/buildkitd.sock;
env:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/buildkit v0.18.1
github.com/moby/buildkit v0.18.2
github.com/muesli/reflow v0.3.0
github.com/muesli/termenv v0.15.2
github.com/onsi/ginkgo/v2 v2.22.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/moby/buildkit v0.18.1 h1:Iwrz2F/Za2Gjkpwu3aM2LX92AFfJCJe2oNnvGNvh2Rc=
github.com/moby/buildkit v0.18.1/go.mod h1:vCR5CX8NGsPTthTg681+9kdmfvkvqJBXEv71GZe5msU=
github.com/moby/buildkit v0.18.2 h1:l86uBvxh4ntNoUUg3Y0eGTbKg1PbUh6tawJ4Xt75SpQ=
github.com/moby/buildkit v0.18.2/go.mod h1:vCR5CX8NGsPTthTg681+9kdmfvkvqJBXEv71GZe5msU=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
Expand Down
16 changes: 14 additions & 2 deletions initrd/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net"
"os"
"path/filepath"
"runtime/debug"
"strings"

"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -251,6 +252,17 @@ func (initrd *dockerfile) Build(ctx context.Context) (string, error) {
if connerr != nil {
log.G(ctx).Info("creating ephemeral buildkit container")

buildkitVersion := "latest"
if bi, ok := debug.ReadBuildInfo(); ok {
for _, dep := range bi.Deps {
if dep.Path == "github.com/moby/buildkit" {
buildkitVersion = dep.Version
break
}
}
log.G(ctx).Debug("could not determine BuildKit version from module list")
}

testcontainers.DefaultLoggingHook = testcontainersLoggingHook
printf := &testcontainersPrintf{ctx}
testcontainers.Logger = printf
Expand All @@ -268,7 +280,7 @@ func (initrd *dockerfile) Build(ctx context.Context) (string, error) {
log.G(ctx).Warn("can run BuildKit in a container (recommended for macOS users)")
log.G(ctx).Warn("which you can do by running:")
log.G(ctx).Warn("")
log.G(ctx).Warn(" docker run --rm -d --name buildkit --privileged moby/buildkit:latest")
log.G(ctx).Warn(" docker run --rm -d --name buildkit --privileged moby/buildkit:" + buildkitVersion)
log.G(ctx).Warn(" export KRAFTKIT_BUILDKIT_HOST=docker-container://buildkit")
log.G(ctx).Warn("")
log.G(ctx).Warn("For more usage instructions visit: https://unikraft.org/buildkit")
Expand All @@ -293,7 +305,7 @@ func (initrd *dockerfile) Build(ctx context.Context) (string, error) {
Logger: printf,
ContainerRequest: testcontainers.ContainerRequest{
AlwaysPullImage: true,
Image: "moby/buildkit:v0.18.1",
Image: "moby/buildkit:" + buildkitVersion,
WaitingFor: wait.ForLog(fmt.Sprintf("running server on [::]:%d", port)),
Privileged: true,
ExposedPorts: []string{fmt.Sprintf("%d:%d/tcp", port, port)},
Expand Down
Loading