#How to Export multiple Images to Host

1 messages · Page 1 of 1 (latest)

haughty depot
#

How would I export multiple images to Host?

type BuildMetadata struct {
    Package    string
    BinaryPath string
    Container  *dagger.Container
    Platform   string
}

func (m *Harbor) ExportAllImages(ctx context.Context) (string, error) {
    metdata := m.buildAllImages(ctx)
    for _, meta := range metdata {
        export, err := meta.Container.Export(ctx, fmt.Sprintf("bin/container/%s/%s.tgz", meta.Platform, meta.Package))
        println(export)
        if err != nil {
            return "", err
        }
    }
    return "bin/container", nil
}

func (m *Harbor) buildAllImages(ctx context.Context) []*BuildMetadata {
jagged sphinx
#

you could use https://pkg.go.dev/dagger.io/dagger#Container.AsTarball instead of Container.Export to build up a Directory and export that.

Some psuedocode for example:

artifacts := dag.Directory()

for _, meta := range metadata {
  artifacts = artifacts.WithFile(fmt.Sprintf("bin/container/%s/%s.tgz", meta.Platform, meta.Package), meta.Container.AsTarball()
}
return artifacts
haughty depot
#

i see thank you, what is wrong with Container.Export? where would I use that if tarball is the only way why are there two?