Created
March 10, 2023 18:37
-
-
Save gmlewis/9fd12016fa750ac07e86452e659606c0 to your computer and use it in GitHub Desktop.
Work-in-progress building container and publishing to Azure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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