#Is it possible to check if a container image exists?

1 messages · Page 1 of 1 (latest)

grizzled dagger
#

As far as I can tell, calling dag.Container().From("adsf") will throw an unrecoverable error. Is it possible to check that an image address exists using the Dagger SDK? And if not, recover from the error?

proud anchor
#

It looks like you could call Sync right after the From func and just recover() if you do get an error. Its not the most "dagger-esque" way to do it, but it does work:

func (m *Module) Tester(ctx context.Context) string {
    func() {
        _, err := dag.Container().From("asdf").Sync(ctx)
        if err != nil {
            println(err)
            recover()
        }
        _, err = dag.Container().From("ubuntu").Sync(ctx)
        if err != nil {
            println(err)
            recover()
        }
    }()
    return "hello world"
}

Output with --progress=plain shows both containers being tried, ubuntu loading, and the normal return happening.

oblique mist
grizzled dagger
#

@proud anchor @oblique mist Thanks for the suggestions! Staying in Dagger the recover() approach could work. I noticed the CLI output logs the error messages, which might not be desirable. I'll checkout the crane tool experiment with it some, thanks!