Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: streamline image building process #46

Open
wants to merge 1 commit into
base: build/daggerize
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 13 additions & 47 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,65 +41,31 @@ type Harbor struct {
Source *dagger.Directory
}

func (m *Harbor) BuildAllImages(ctx context.Context) []*dagger.Container {
var buildImages []*dagger.Container
for _, platform := range SupportedPlatforms {
for _, pkg := range packages {
image := m.BuildImage(ctx, platform, pkg)
buildImages = append(buildImages, image)
}
// build portal
}
return buildImages
}

func (m *Harbor) buildAllImages(ctx context.Context) []*BuildMetadata {
var buildMetadata []*BuildMetadata
for _, platform := range SupportedPlatforms {
func (m *Harbor) BuildImages(ctx context.Context,
// +optional
// +default=["linux/arm64","linux/amd64"]
platforms []string,
// +optional
// +default=["core", "jobservice", "registryctl", "cmd/exporter", "cmd/standalone-db-migrator"]
packages []string) []*dagger.Container {
var images []*dagger.Container
for _, platform := range platforms {
for _, pkg := range packages {
image := m.buildImage(ctx, platform, pkg)
buildImages = append(buildImages, image)
img := m.buildImage(ctx, platform, pkg)
images = append(images, img)
}
// build portal
}
return buildImages
return images
}

func (m *Harbor) BuildImage(ctx context.Context, platform string, pkg string) *dagger.Container {
func (m *Harbor) buildImage(ctx context.Context, platform string, pkg string) *dagger.Container {
bc := m.buildBinary(ctx, platform, pkg)
img := dag.Container(dagger.ContainerOpts{Platform: dagger.Platform(platform)}).
WithFile("/"+pkg, bc.Container.File(bc.BinaryPath)).
WithEntrypoint([]string{"/" + pkg})
return img
}

func (m *Harbor) BuildAllBinaries(ctx context.Context) *dagger.Directory {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would like to build binaries and have them on my host.

Its not clear to me how I can use BuildImages function and get to the binaries out of that array, so that I can copy them to the host

With a single image it woudl work but not with an array

output := dag.Directory()
builds := m.buildAllBinaries(ctx)
for _, build := range builds {
output = output.WithFile(build.BinaryPath, build.Container.File(build.BinaryPath))
}
return output

}

func (m *Harbor) buildAllBinaries(ctx context.Context) []*BuildMetadata {
var buildContainers []*BuildMetadata
for _, platform := range SupportedPlatforms {
for _, pkg := range packages {
buildContainer := m.buildBinary(ctx, platform, pkg)
buildContainers = append(buildContainers, buildContainer)
}
// build portal
}
return buildContainers
}

func (m *Harbor) BuildBinary(ctx context.Context, platform string, pkg string) *dagger.File {
build := m.buildBinary(ctx, platform, pkg)
return build.Container.File(build.BinaryPath)
}

func (m *Harbor) buildBinary(ctx context.Context, platform string, pkg string) *BuildMetadata {

os, arch, err := parsePlatform(platform)
Expand Down
Loading