It works if you use an image that does not authenticate at the time of pull.
func main() (string, error) {
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
defer client.Close()
src := client.Host().Directory(".")
builder := client.Container().Build(src)
responses := make([]string, len(addresses))
container := client.Container().WithRegistryAuth("harbor.example.com", "my-username2", client.SetSecret("pushpwd", "bar"))
for _, address := range addresses {
response, err := container.Publish(ctx, strings.TrimSuffix(address, "\r"), dagger.ContainerPublishOpts{PlatformVariants: []*dagger.Container{builder}})
if err != nil {
panic(err)
}
fmt.Printf("Published image to :%s\n", response)
}
}
Also, the respective credentials will be correct, as the Build-only run will also succeed
func main() (string, error) {
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
defer client.Close()
src := client.Host().Directory(".")
builder := client.Container().
WithRegistryAuth("harbor.example.com", "my-username1", client.SetSecret("pullpwd", "foo")).
Build(src)
}