Skip to content

Commit

Permalink
dockerfile: update buildkit to 0.13.0
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 7, 2024
1 parent e7a2aa6 commit b440e2c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
fail-fast: false
matrix:
buildkit:
- ""
- v0.13.0
- v0.12.5
- v0.11.6
- v0.10.6
worker:
- docker
- docker\+containerd # same as docker, but with containerd snapshotter
Expand All @@ -55,6 +55,7 @@ jobs:
name: Prepare
run: |
echo "TESTREPORTS_NAME=${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.buildkit }}-${{ matrix.worker }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "TEST_BUILDKIT_VERSION=${{ matrix.buildkit }}" >> $GITHUB_ENV
-
name: Checkout
uses: actions/checkout@v4
Expand All @@ -77,15 +78,12 @@ jobs:
targets: integration-test
set: |
*.output=type=docker,name=${{ env.TEST_IMAGE_ID }}
env:
TEST_BUILDKIT_VERSION: "${{ matrix.buildkit }}"
-
name: Test
run: |
./hack/test
env:
TEST_REPORT_SUFFIX: "-${{ env.TESTREPORTS_NAME }}"
TEST_BUILDKIT_IMAGE: "moby/buildkit:${{ matrix.buildkit }}"
TEST_DOCKERD: "${{ startsWith(matrix.worker, 'docker') && '1' || '0' }}"
TESTFLAGS: "${{ (matrix.worker == 'docker' || matrix.worker == 'docker\\+containerd') && env.TESTFLAGS_DOCKER || env.TESTFLAGS }} --run=//worker=${{ matrix.worker }}$"
TESTPKGS: "${{ matrix.pkg }}"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ARG XX_VERSION=1.4.0
ARG DOCKER_VERSION=25.0.2
ARG GOTESTSUM_VERSION=v1.9.0
ARG REGISTRY_VERSION=2.8.0
ARG BUILDKIT_VERSION=v0.12.5
ARG BUILDKIT_VERSION=v0.13.0

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS golatest
Expand Down
4 changes: 2 additions & 2 deletions hack/test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -eu -o pipefail
: "${TEST_REPORT_SUFFIX=}"
: "${TEST_KEEP_CACHE=}"
: "${TEST_DOCKERD=}"
: "${TEST_BUILDKIT_IMAGE=}"
: "${TEST_BUILDKIT_VERSION=}"

if [ "$TEST_IMAGE_BUILD" = "1" ]; then
${BUILDX_CMD} bake integration-test --set "*.output=type=docker,name=$TEST_IMAGE_ID"
Expand All @@ -30,5 +30,5 @@ if [ "$TEST_KEEP_CACHE" != "1" ]; then
trap 'docker rm -v $cacheVolume' EXIT
fi

cid=$(docker create --rm -v /tmp $testReportsVol --volumes-from=$cacheVolume -e GITHUB_REF -e TEST_DOCKERD -e TEST_BUILDKIT_IMAGE -e SKIP_INTEGRATION_TESTS -e GOTESTSUM_FORMAT ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $TEST_IMAGE_ID gotestsum $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
cid=$(docker create --rm -v /tmp $testReportsVol --volumes-from=$cacheVolume -e GITHUB_REF -e TEST_DOCKERD -e TEST_BUILDKIT_VERSION -e SKIP_INTEGRATION_TESTS -e GOTESTSUM_FORMAT ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry --privileged $TEST_IMAGE_ID gotestsum $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
docker start -a -i $cid
6 changes: 2 additions & 4 deletions tests/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ func testBakeMultiExporters(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}
skipNoCompatBuildKit(t, ">= 0.13.0-0")

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
Expand All @@ -668,12 +669,10 @@ func testBakeMultiExporters(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
})

// TODO: use stable buildkit image when v0.13.0 released
out, err := createCmd(sb, withArgs(
"--driver", "docker-container",
"--buildkitd-flags=--allow-insecure-entitlement=network.host",
"--driver-opt", "network=host",
"--driver-opt", "image=moby/buildkit:v0.13.0-rc3",
))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)
Expand Down Expand Up @@ -725,6 +724,7 @@ func testBakeLoadPush(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}
skipNoCompatBuildKit(t, ">= 0.13.0-0")

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
Expand All @@ -748,12 +748,10 @@ func testBakeLoadPush(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
})

// TODO: use stable buildkit image when v0.13.0 released
out, err := createCmd(sb, withArgs(
"--driver", "docker-container",
"--buildkitd-flags=--allow-insecure-entitlement=network.host",
"--driver-opt", "network=host",
"--driver-opt", "image=moby/buildkit:v0.13.0-rc3",
))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)
Expand Down
13 changes: 7 additions & 6 deletions tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ func testBuildNetworkModeBridge(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}
skipNoCompatBuildKit(t, ">= 0.13.0-0")

var builderName string
t.Cleanup(func() {
Expand All @@ -439,8 +440,10 @@ func testBuildNetworkModeBridge(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
})

// TODO: use stable buildkit image when v0.13.0 released
out, err := createCmd(sb, withArgs("--driver", "docker-container", "--buildkitd-flags=--oci-worker-net=bridge --allow-insecure-entitlement=network.host", "--driver-opt", "image=moby/buildkit:v0.13.0-rc3"))
out, err := createCmd(sb, withArgs(
"--driver", "docker-container",
"--buildkitd-flags=--oci-worker-net=bridge --allow-insecure-entitlement=network.host",
))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)

Expand Down Expand Up @@ -549,6 +552,7 @@ func testBuildMultiExporters(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}
skipNoCompatBuildKit(t, ">= 0.13.0-0")

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
Expand All @@ -573,12 +577,10 @@ func testBuildMultiExporters(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
})

// TODO: use stable buildkit image when v0.13.0 released
out, err := createCmd(sb, withArgs(
"--driver", "docker-container",
"--buildkitd-flags=--allow-insecure-entitlement=network.host",
"--driver-opt", "network=host",
"--driver-opt", "image=moby/buildkit:v0.13.0-rc3",
))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)
Expand Down Expand Up @@ -617,6 +619,7 @@ func testBuildLoadPush(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}
skipNoCompatBuildKit(t, ">= 0.13.0-0")

registry, err := sb.NewRegistry()
if errors.Is(err, integration.ErrRequirements) {
Expand All @@ -640,12 +643,10 @@ func testBuildLoadPush(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
})

// TODO: use stable buildkit image when v0.13.0 released
out, err := createCmd(sb, withArgs(
"--driver", "docker-container",
"--buildkitd-flags=--allow-insecure-entitlement=network.host",
"--driver-opt", "network=host",
"--driver-opt", "image=moby/buildkit:v0.13.0-rc3",
))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)
Expand Down
29 changes: 29 additions & 0 deletions tests/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"strings"
"testing"

"github.com/Masterminds/semver/v3"
"github.com/containerd/continuity/fs/fstest"
"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
)

const defaultBuildKitVersion = "v0.13.0"

func tmpdir(t *testing.T, appliers ...fstest.Applier) string {
t.Helper()
tmpdir := t.TempDir()
Expand Down Expand Up @@ -75,3 +78,29 @@ func isDockerWorker(sb integration.Sandbox) bool {
sbDriver, _, _ := strings.Cut(sb.Name(), "+")
return sbDriver == "docker"
}

func matchesBuildKitVersion(version, constraint string) bool {
c, err := semver.NewConstraint(constraint)
if err != nil {
return false
}
v, err := semver.NewVersion(version)
if err != nil {
return false
}
return c.Check(v)
}

func buildKitVersion() string {
if v := os.Getenv("TEST_BUILDKIT_VERSION"); v != "" {
return v
}
return defaultBuildKitVersion
}

func skipNoCompatBuildKit(t *testing.T, constraint string) {
version := buildKitVersion()
if !matchesBuildKitVersion(version, constraint) {
t.Skipf("buildkit version %s does not match %s constraint", version, constraint)
}
}
13 changes: 1 addition & 12 deletions tests/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package tests

import (
"os"
"testing"

"github.com/distribution/reference"
"github.com/docker/buildx/tests/workers"
"github.com/moby/buildkit/util/testutil/integration"
bkworkers "github.com/moby/buildkit/util/testutil/workers"
Expand Down Expand Up @@ -35,16 +33,7 @@ func TestIntegration(t *testing.T) {

func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sandbox)) {
mirroredImages := integration.OfficialImages("busybox:latest", "alpine:latest")
buildkitImage := "docker.io/moby/buildkit:buildx-stable-1"
if bkworkers.IsTestDockerd() {
if img, ok := os.LookupEnv("TEST_BUILDKIT_IMAGE"); ok {
ref, err := reference.ParseNormalizedNamed(img)
if err == nil {
buildkitImage = ref.String()
}
}
}
mirroredImages["moby/buildkit:buildx-stable-1"] = buildkitImage
mirroredImages["moby/buildkit:buildx-stable-1"] = "docker.io/moby/buildkit:" + buildKitVersion()
mirrors := integration.WithMirroredImages(mirroredImages)

tests := integration.TestFuncs(funcs...)
Expand Down

0 comments on commit b440e2c

Please sign in to comment.