Skip to content

Instantly share code, notes, and snippets.

@gmlewis
Last active February 3, 2023 01:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmlewis/536345ad27c6986e41ae8ff7f5c0f7ff to your computer and use it in GitHub Desktop.
Save gmlewis/536345ad27c6986e41ae8ff7f5c0f7ff to your computer and use it in GitHub Desktop.
Work in progress - pushing image to Azure Container Registry using Dagger.io
package common
import (
"context"
"log"
"dagger.io/dagger"
)
// PublishToAzure performs a Dockerfile build on the provided repo and pushes to the
// Azure Container Registry.
func (c *Client) PublishToAzure(ctx context.Context, prodDir *dagger.Directory, azureAddress string, buildOpts ...dagger.ContainerBuildOpts) error {
dockerfile := "Dockerfile"
for _, opt := range buildOpts {
dockerfile = opt.Dockerfile // Possible Dockerfile override
}
log.Printf("PublishToAzure using %q: %v", dockerfile, azureAddress)
prodImage := c.Client.Container().Build(prodDir, buildOpts...)
out, err := prodImage.Stdout(ctx)
if err != nil {
return err
}
log.Printf("Build %q: %v", dockerfile, out)
ref, err := prodImage.Publish(ctx, azureAddress)
if err != nil {
return err
}
log.Printf("Successfully published %q image to %v - ref: %v", dockerfile, azureAddress, ref)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment