Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Inspect image we've built to get Size
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 7, 2019
1 parent 79d9faa commit 0d24edd
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions internal/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type buildOptions struct {
func Cmd(dockerCli command.Cli) *cobra.Command {
var opts buildOptions
cmd := &cobra.Command{
Use: "build [APPLICATION] [TAG]",
Use: "build [APP_NAME] [APP_IMAGE]",
Short: "Build service images for the application",
Example: `$ docker app build myapp.dockerapp`,
Example: `$ docker app build myapp.dockerapp my/app:1.0.0`,
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
opts.tag = args[1]
Expand Down Expand Up @@ -123,7 +123,10 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
if err != nil {
return nil, err
}
updateBundle(bundle, resp)
err = updateBundle(dockerCli, bundle, resp)
if err != nil {
return nil, err
}

if ref == nil {
if ref, err = computeDigest(bundle); err != nil {
Expand Down Expand Up @@ -152,20 +155,28 @@ func checkMinimalEngineVersion(dockerCli command.Cli) error {
return nil
}

func updateBundle(bundle *bundle.Bundle, resp map[string]*client.SolveResponse) {
func updateBundle(dockerCli command.Cli, bundle *bundle.Bundle, resp map[string]*client.SolveResponse) error {
debugSolveResponses(resp)
for service, r := range resp {
digest := r.ExporterResponse["containerimage.digest"]
inspect, _, err := dockerCli.Client().ImageInspectWithRaw(context.TODO(), digest)
if err != nil {
return err
}
size := uint64(inspect.Size)
if service == "com.docker.app.invocation-image" {
bundle.InvocationImages[0].Digest = digest
bundle.InvocationImages[0].Size = size
} else {
image := bundle.Images[service]
image.ImageType = cnab.ImageTypeDocker
image.Digest = digest
image.Size = size
bundle.Images[service] = image
}
}
debugBundle(bundle)
return nil
}

func createInvocationImageBuildOptions(dockerCli command.Cli, app *types.App) (build.Options, error) {
Expand Down

0 comments on commit 0d24edd

Please sign in to comment.