Skip to content

Instantly share code, notes, and snippets.

@gmlewis
Created March 10, 2023 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmlewis/9fd12016fa750ac07e86452e659606c0 to your computer and use it in GitHub Desktop.
Save gmlewis/9fd12016fa750ac07e86452e659606c0 to your computer and use it in GitHub Desktop.
Work-in-progress building container and publishing to Azure
package common
import (
"context"
"log"
"dagger.io/dagger"
)
// PublishToAzure performs a Dockerfile build on the provided repo and pushes to the
// Azure Container Registry using the provided imageName.
func (c *Client) PublishToAzure(ctx context.Context, prodDir *dagger.Directory, imageNames []string, buildOpts ...dagger.ContainerBuildOpts) error {
dockerfile := "Dockerfile"
for _, opt := range buildOpts {
dockerfile = opt.Dockerfile // Possible Dockerfile override
}
prodImage := c.Client.Container().Build(prodDir, buildOpts...)
log.Printf("PublishToAzure: Building container from %q", dockerfile)
out, err := prodImage.Stdout(ctx)
if err != nil {
log.Printf("PublishToAzure: Build FAILED: %v\n%v", err, out)
return err
}
log.Printf("PublishToAzure: Build SUCCESS for %q: %v", dockerfile, out)
for _, imageName := range imageNames {
ref, err := prodImage.Publish(ctx, imageName)
if err != nil {
return err
}
log.Printf("Successfully published %q to %v - ref: %v", dockerfile, imageName, ref)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment