Skip to content

Commit

Permalink
tests: create remote with container helper
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 9, 2024
1 parent 8f576e5 commit 52c454d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
}
}

d, err := driver.GetDriver(ctx, "buildx_buildkit_"+n.Name, factory, n.Endpoint, dockerapi, imageopt.Auth, kcc, n.BuildkitdFlags, n.Files, n.DriverOpts, n.Platforms, b.opts.contextPathHash, lno.dialMeta)
d, err := driver.GetDriver(ctx, driver.BuilderNamePrefix+n.Name, factory, n.Endpoint, dockerapi, imageopt.Auth, kcc, n.BuildkitdFlags, n.Files, n.DriverOpts, n.Platforms, b.opts.contextPathHash, lno.dialMeta)
if err != nil {
node.Err = err
return nil
Expand Down
2 changes: 2 additions & 0 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
Running
Stopping
Stopped

BuilderNamePrefix = "buildx_buildkit_"
)

func (s Status) String() string {
Expand Down
6 changes: 3 additions & 3 deletions driver/kubernetes/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ func (f *factory) AllowsInstances() bool {
// eg. "buildx_buildkit_loving_mendeleev0" -> "loving-mendeleev0"
func buildxNameToDeploymentName(bx string) (string, error) {
// TODO: commands.util.go should not pass "buildx_buildkit_" prefix to drivers
if !strings.HasPrefix(bx, "buildx_buildkit_") {
return "", errors.Errorf("expected a string with \"buildx_buildkit_\", got %q", bx)
if !strings.HasPrefix(bx, driver.BuilderNamePrefix) {
return "", errors.Errorf("expected a string with %q, got %q", driver.BuilderNamePrefix, bx)
}
s := strings.TrimPrefix(bx, "buildx_buildkit_")
s := strings.TrimPrefix(bx, driver.BuilderNamePrefix)
s = strings.ReplaceAll(s, "_", "-")
return s, nil
}
2 changes: 1 addition & 1 deletion driver/kubernetes/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestFactory_processDriverOpts(t *testing.T) {
}

cfg := driver.InitConfig{
Name: "buildx_buildkit_test",
Name: driver.BuilderNamePrefix + "test",
KubeClientConfig: &kcc,
}
f := factory{}
Expand Down
28 changes: 28 additions & 0 deletions tests/create.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package tests

import (
"fmt"
"strings"
"testing"

"github.com/docker/buildx/driver"
"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
)
Expand All @@ -18,6 +20,7 @@ func createCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
var createTests = []func(t *testing.T, sb integration.Sandbox){
testCreateMemoryLimit,
testCreateRestartAlways,
testCreateRemoteContainer,
}

func testCreateMemoryLimit(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -57,3 +60,28 @@ func testCreateRestartAlways(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)
}

func testCreateRemoteContainer(t *testing.T, sb integration.Sandbox) {
if sb.Name() != "docker" {
t.Skip("skipping test for non-docker workers")
}

var builderName string
t.Cleanup(func() {
if builderName == "" {
return
}
out, err := rmCmd(sb, withArgs(builderName))
require.NoError(t, err, out)
})

out, err := createCmd(sb, withArgs("--driver", "docker-container"))
require.NoError(t, err, out)
builderName = strings.TrimSpace(out)

out, err = inspectCmd(sb, withArgs("--bootstrap", builderName))
require.NoError(t, err, out)

out, err = createCmd(sb, withArgs("--driver", "remote", fmt.Sprintf("docker-container://%s%s0", driver.BuilderNamePrefix, builderName), "--bootstrap"))
require.NoError(t, err, out)
}

0 comments on commit 52c454d

Please sign in to comment.