automatically detect vendored buildkit version
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
57754bebb8
commit
304959b3f5
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
make shellcheck cuelint check-buildkit-version docslint
|
make shellcheck cuelint docslint
|
||||||
|
|
||||||
- name: Markdown Lint
|
- name: Markdown Lint
|
||||||
uses: avto-dev/markdown-lint@v1
|
uses: avto-dev/markdown-lint@v1
|
||||||
|
9
Makefile
9
Makefile
@ -31,14 +31,7 @@ shellcheck:
|
|||||||
shellcheck ./universe/*.bats ./universe/*.bash
|
shellcheck ./universe/*.bats ./universe/*.bash
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: shellcheck cuelint golint check-buildkit-version docslint
|
lint: shellcheck cuelint golint docslint
|
||||||
|
|
||||||
.PHONY: check-buildkit-version
|
|
||||||
check-buildkit-version:
|
|
||||||
@test \
|
|
||||||
"$(shell grep buildkit ./go.mod | cut -d' ' -f2)" = \
|
|
||||||
"$(shell grep ' = "v' ./util/buildkitd/buildkitd.go | sed -E 's/^.*version.*=.*\"(v.*)\"/\1/' )" \
|
|
||||||
|| { echo buildkit version mismatch go.mod != util/buildkitd/buildkitd.go ; exit 1; }
|
|
||||||
|
|
||||||
.PHONY: integration
|
.PHONY: integration
|
||||||
integration: core-integration universe-test
|
integration: core-integration universe-test
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -14,14 +15,33 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// vendoredVersion is filled in by init()
|
||||||
|
vendoredVersion string
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
image = "moby/buildkit"
|
image = "moby/buildkit"
|
||||||
version = "v0.9.0-rc1"
|
|
||||||
imageVersion = image + ":" + version
|
|
||||||
containerName = "dagger-buildkitd"
|
containerName = "dagger-buildkitd"
|
||||||
volumeName = "dagger-buildkitd"
|
volumeName = "dagger-buildkitd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
bi, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
panic("unable to retrieve build info")
|
||||||
|
}
|
||||||
|
for _, d := range bi.Deps {
|
||||||
|
if d.Path == "github.com/moby/buildkit" {
|
||||||
|
vendoredVersion = d.Version
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if vendoredVersion == "" {
|
||||||
|
panic("failed to solve vendored buildkit version")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Start(ctx context.Context) (string, error) {
|
func Start(ctx context.Context) (string, error) {
|
||||||
lg := log.Ctx(ctx)
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
@ -40,11 +60,11 @@ func Start(ctx context.Context) (string, error) {
|
|||||||
lg.Debug().Str("version", currentVersion).Msg("detected buildkit version")
|
lg.Debug().Str("version", currentVersion).Msg("detected buildkit version")
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentVersion != version {
|
if currentVersion != vendoredVersion {
|
||||||
if currentVersion != "" {
|
if currentVersion != "" {
|
||||||
lg.
|
lg.
|
||||||
Info().
|
Info().
|
||||||
Str("version", version).
|
Str("version", vendoredVersion).
|
||||||
Msg("upgrading buildkit")
|
Msg("upgrading buildkit")
|
||||||
if err := remvoveBuildkit(ctx); err != nil {
|
if err := remvoveBuildkit(ctx); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -52,7 +72,7 @@ func Start(ctx context.Context) (string, error) {
|
|||||||
} else {
|
} else {
|
||||||
lg.
|
lg.
|
||||||
Info().
|
Info().
|
||||||
Str("version", version).
|
Str("version", vendoredVersion).
|
||||||
Msg("starting buildkit")
|
Msg("starting buildkit")
|
||||||
}
|
}
|
||||||
if err := startBuildkit(ctx); err != nil {
|
if err := startBuildkit(ctx); err != nil {
|
||||||
@ -85,14 +105,14 @@ func startBuildkit(ctx context.Context) error {
|
|||||||
lg := log.
|
lg := log.
|
||||||
Ctx(ctx).
|
Ctx(ctx).
|
||||||
With().
|
With().
|
||||||
Str("version", version).
|
Str("version", vendoredVersion).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
lg.Debug().Msg("pulling buildkit image")
|
lg.Debug().Msg("pulling buildkit image")
|
||||||
cmd := exec.CommandContext(ctx,
|
cmd := exec.CommandContext(ctx,
|
||||||
"docker",
|
"docker",
|
||||||
"pull",
|
"pull",
|
||||||
imageVersion,
|
image+":"+vendoredVersion,
|
||||||
)
|
)
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,7 +137,7 @@ func startBuildkit(ctx context.Context) error {
|
|||||||
"-v", volumeName+":/var/lib/buildkit",
|
"-v", volumeName+":/var/lib/buildkit",
|
||||||
"--name", containerName,
|
"--name", containerName,
|
||||||
"--privileged",
|
"--privileged",
|
||||||
imageVersion,
|
image+":"+vendoredVersion,
|
||||||
)
|
)
|
||||||
output, err = cmd.CombinedOutput()
|
output, err = cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -145,10 +165,10 @@ func waitBuildkit(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
// Try to connect every 100ms up to 50 times (5 seconds total)
|
// Try to connect every 100ms up to 100 times (10 seconds total)
|
||||||
const (
|
const (
|
||||||
retryPeriod = 100 * time.Millisecond
|
retryPeriod = 100 * time.Millisecond
|
||||||
retryAttempts = 50
|
retryAttempts = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
for retry := 0; retry < retryAttempts; retry++ {
|
for retry := 0; retry < retryAttempts; retry++ {
|
||||||
|
Reference in New Issue
Block a user