Skip to content
9 changes: 3 additions & 6 deletions .dagger/build_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (m *Cuestomize) Build(
platform string,
// +default=""
ldflags string,
) (*dagger.Container, error) {
) *dagger.Container {
containerOpts := dagger.ContainerOpts{}
if platform != "" {
containerOpts.Platform = dagger.Platform(platform)
Expand All @@ -29,7 +29,7 @@ func (m *Cuestomize) Build(
WithFile("/usr/local/bin/cuestomize", builder.File("/workspace/cuestomize")).
WithEntrypoint([]string{"/usr/local/bin/cuestomize"})

return container, nil
return container
}

func (m *Cuestomize) BuildAndPublish(
Expand Down Expand Up @@ -73,10 +73,7 @@ func (m *Cuestomize) BuildAndPublish(

platformVariants := make([]*dagger.Container, 0, len(platforms))
for _, platform := range platforms {
container, err := m.Build(ctx, buildContext, string(platform), ldflags)
if err != nil {
return err
}
container := m.Build(ctx, buildContext, string(platform), ldflags)
platformVariants = append(platformVariants, container)
}

Expand Down
2 changes: 2 additions & 0 deletions .dagger/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var (
Exclude: []string{
".go-version", "README.md",
".vscode", "examples",
".dagger", "docs",
},
Gitignore: true,
}
)
11 changes: 4 additions & 7 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ type Cuestomize struct{}

// repoBaseContainer creates a container with the repository files in it and go dependencies installed.
// The working directory is set to `/workspace` and contains the root of the repository.
func repoBaseContainer(buildContext *dagger.Directory, excludedOpts *dagger.ContainerWithDirectoryOpts, containerOpts ...dagger.ContainerOpts) *dagger.Container {
var exOpts dagger.ContainerWithDirectoryOpts
if excludedOpts == nil {
exOpts = DefaultExcludedOpts
func repoBaseContainer(buildContext *dagger.Directory, dirOpts *dagger.ContainerWithDirectoryOpts, containerOpts ...dagger.ContainerOpts) *dagger.Container {
if dirOpts == nil {
dirOpts = &DefaultExcludedOpts
}

// Create a container to run the tests
Expand All @@ -22,10 +21,8 @@ func repoBaseContainer(buildContext *dagger.Directory, excludedOpts *dagger.Cont
WithWorkdir("/workspace").
WithFile("/workspace/go.mod", buildContext.File("go.mod")).
WithFile("/workspace/go.sum", buildContext.File("go.sum")).
WithFile("/workspace/.dagger/go.mod", buildContext.File(".dagger/go.mod")).
WithFile("/workspace/.dagger/go.sum", buildContext.File(".dagger/go.sum")).
WithExec([]string{"go", "mod", "download"}).
WithDirectory("/workspace", buildContext, exOpts)
WithDirectory("/workspace", buildContext, *dirOpts)
}

// cuestomizeBuilderContainer returns a container that can be used to build the cuestomize binary.
Expand Down
49 changes: 42 additions & 7 deletions .dagger/testing_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ func (m *Cuestomize) E2E_Test(
ctx context.Context,
// +defaultPath=./
buildContext *dagger.Directory,
// sock *dagger.Socket,
) error {
// build cuestomize
cuestomize, err := cuestomizeBuilderContainer(buildContext, "").Sync(ctx)
if err != nil {
return fmt.Errorf("failed to build cuestomize: %w", err)
}
cuestomizeBinary := cuestomize.File("/workspace/cuestomize")
cuestomize := m.Build(ctx, buildContext, "", "")

cuestomizeBinary := cuestomize.File("/usr/local/bin/cuestomize")

cuestomizeTar := cuestomize.AsTarball()

testdataDir := buildContext.Directory("e2e/testdata")

Expand All @@ -71,13 +72,49 @@ func (m *Cuestomize) E2E_Test(
return fmt.Errorf("failed to run e2e tests: %w", err)
}

dind := dag.Container().
From("docker:dind").
WithEnvVariable("TINI_SUBREAPER", "true").
WithServiceBinding("registry_auth", registryWithAuthService).
WithMountedCache("/var/lib/docker", dag.CacheVolume("dind-data")).
WithExposedPort(2375).AsService(dagger.ContainerAsServiceOpts{
Args: []string{
"dockerd", "--tls=false", "--host=tcp://0.0.0.0:2375",
},
InsecureRootCapabilities: true,
UseEntrypoint: true,
})

dindService, err := dind.Start(ctx)
if err != nil {
return fmt.Errorf("failed to start dind: %w", err)
}
defer dindService.Stop(ctx)

dockerCli := dag.Container().From("docker:cli")
// Load the image into DIND and tag it
_, err = dockerCli.
WithServiceBinding("docker-host", dindService).
WithEnvVariable("DOCKER_HOST", "tcp://docker-host:2375").
WithFile("/tmp/image.tar", cuestomizeTar).
WithExec([]string{"sh", "-c", `
SOURCE=$(docker load -i /tmp/image.tar -q | cut -d' ' -f 4)
docker tag $SOURCE cuestomize:latest
`}).Sync(ctx)
if err != nil {
return fmt.Errorf("failed to load cuestomize image into dind: %w", err)
}

// run e2e tests
// TODO: save output to file and extract it for comparison
kustomize := dag.Container().From(KustomizeImage).
WithServiceBinding("registry", registryService).
WithServiceBinding("registry_auth", registryWithAuthService).
WithServiceBinding("docker-host", dindService).
WithEnvVariable("DOCKER_HOST", "tcp://docker-host:2375").
WithDirectory("/testdata", testdataDir).
WithFile("/bin/cuestomize", cuestomizeBinary).
WithFile("/usr/local/bin/docker", dockerCli.File("/usr/local/bin/docker")).
WithDirectory("/cue-resources", dag.Directory()).
WithNewFile(
"/testdata/kustomize-auth/.env.secret",
Expand All @@ -87,8 +124,6 @@ func (m *Cuestomize) E2E_Test(
return fmt.Errorf("kustomize with no auth e2e failed: %w", err)
}

kustomize = kustomize.WithoutDirectory("/cue-resources").WithDirectory("/cue-resources", dag.Directory())

if _, err := kustomize.WithExec([]string{"kustomize", "build", "--enable-alpha-plugins", "--network", "/testdata/kustomize-auth"}).Sync(ctx); err != nil {
return fmt.Errorf("kustomize with auth e2e failed: %w", err)
}
Expand Down
6 changes: 1 addition & 5 deletions .dagger/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ func (m *Cuestomize) GoGenerate(
// +defaultPath=./
buildContext *dagger.Directory,
) *dagger.Container {
container := repoBaseContainer(buildContext, &dagger.ContainerWithDirectoryOpts{
Exclude: []string{
".go-version", "README.md", ".vscode",
},
}).
container := repoBaseContainer(buildContext, nil).
WithExec([]string{"go", "install", fmt.Sprintf("cuelang.org/go/cmd/cue@%s", CuelangVersion)}).
WithExec([]string{"go", "generate", "./..."})
return container
Expand Down
9 changes: 4 additions & 5 deletions e2e/testdata/kustomize-auth/krm-func.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ metadata:
annotations:
config.kubernetes.io/local-config: "true"
config.kubernetes.io/function: |
exec:
path: /bin/cuestomize
container:
image: cuestomize:latest
network: true
input:
configMapName: example-configmap
includes:
Expand All @@ -20,9 +21,7 @@ includes:
name: example-service
namespace: example-namespace
remoteModule:
registry: registry_auth:5000
repo: sample-module
tag: latest
ref: registry_auth:5000/sample-module:latest
auth:
kind: Secret
name: regcred
Expand Down