diff --git a/.dagger/build_publish.go b/.dagger/build_publish.go index 31a7f23..2b7f8ac 100644 --- a/.dagger/build_publish.go +++ b/.dagger/build_publish.go @@ -3,6 +3,7 @@ package main import ( "context" "dagger/cuestomize/internal/dagger" + "fmt" ) func (m *Cuestomize) Build( @@ -19,15 +20,9 @@ func (m *Cuestomize) Build( containerOpts.Platform = dagger.Platform(platform) } - // Build stage: compile the Go binary - builder := cuestomizeBuilderContainer(buildContext, ldflags, containerOpts) - - // Final stage: create the runtime container with distroless - container := dag.Container(containerOpts). - From(DistrolessStaticImage). - WithDirectory("/cue-resources", dag.Directory(), dagger.ContainerWithDirectoryOpts{Owner: "nobody"}). - WithFile("/usr/local/bin/cuestomize", builder.File("/workspace/cuestomize")). - WithEntrypoint([]string{"/usr/local/bin/cuestomize"}) + container := buildContext.DockerBuild(dagger.DirectoryDockerBuildOpts{ + Dockerfile: "Containerfile", + }) return container } @@ -83,7 +78,7 @@ func (m *Cuestomize) BuildAndPublish( } for _, t := range tags { _, err := dag.Container().WithRegistryAuth(registry, username, password). - Publish(ctx, registry+"/"+repository+":"+t, dagger.ContainerPublishOpts{ + Publish(ctx, fmt.Sprintf("%v/%v:%v", registry, repository, t), dagger.ContainerPublishOpts{ PlatformVariants: platformVariants, }) if err != nil { diff --git a/.dagger/constants.go b/.dagger/constants.go index 0b54edc..8be695d 100644 --- a/.dagger/constants.go +++ b/.dagger/constants.go @@ -5,22 +5,22 @@ import "dagger/cuestomize/internal/dagger" // Note: when updating these constants, also update renovate.json5 // as they are updated in there through regexes. const ( - // GolangImage is the Golang base image + // GolangImage is the Golang base image. GolangImage = "golang:1.26" - // RegistryImage is image for local container registry + // RegistryImage is image for local container registry. RegistryImage = "registry:3" - // DistrolessStaticImage is the distroless static image + // DistrolessStaticImage is the distroless static image. DistrolessStaticImage = "gcr.io/distroless/static:latest" - // KustomizeImage is the Kustomize image + // KustomizeImage is the Kustomize image. KustomizeImage = "registry.k8s.io/kustomize/kustomize:v5.8.1" - // CuelangVersion is the version of Cuelang + // CuelangVersion is the version of Cuelang. CuelangVersion = "v0.16.0" - // GolangciLintImage is the GolangCI-Lint image used by default + // GolangciLintImage is the GolangCI-Lint image used by default. GolangciLintImage = "golangci/golangci-lint:v2.11.4-alpine" ) const ( - // GolangciLintImageFmt is the format for the GolangCI-Lint image. It accepts the version as a string + // GolangciLintImageFmt is the format for the GolangCI-Lint image. It accepts the version as a string. GolangciLintImageFmt = "golangci/golangci-lint:%s-alpine" ) diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..e6153dd --- /dev/null +++ b/Containerfile @@ -0,0 +1,23 @@ +from golang:1.26 as builder + +workdir /workspace + +add go.mod go.mod +add go.sum go.sum + +run go mod download + +add internal/ internal/ +add api/ api/ +add pkg/ pkg/ +add main.go main.go + +add semver semver + +run CGO_ENABLED=0 go build -o cuestomize main.go + +from gcr.io/distroless/static:latest + +copy --from=builder /workspace/cuestomize /usr/local/bin/cuestomize + +entrypoint ["/usr/local/bin/cuestomize"]