Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 3016e0d

Browse files
committed
Confusion between content digest and registry digest
+ Code cleanup and a few tests fixed Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 67f946e commit 3016e0d

8 files changed

Lines changed: 59 additions & 22 deletions

File tree

e2e/testdata/bundle-with-tag.json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"invocationImages": [
1717
{
1818
"imageType": "docker",
19-
"image": "myimage:mytag-invoc"
19+
"image": "myimage:mytag-invoc",
20+
"contentDigest": "sha256:***"
2021
}
2122
],
2223
"images": {

e2e/testdata/plugin-usage-experimental.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Management Commands:
1010
image Manage application images
1111

1212
Commands:
13+
build Build service images for the application
1314
bundle Create a CNAB invocation image and `bundle.json` for the application
1415
init Initialize Docker Application definition
1516
inspect Shows metadata, parameters and a summary of the Compose file for a given application

e2e/testdata/plugin-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Management Commands:
1010
image Manage application images
1111

1212
Commands:
13+
build Build service images for the application
1314
bundle Create a CNAB invocation image and `bundle.json` for the application
1415
init Initialize Docker Application definition
1516
inspect Shows metadata, parameters and a summary of the Compose file for a given application

e2e/testdata/simple-bundle.json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"invocationImages": [
1717
{
1818
"imageType": "docker",
19-
"image": "simple:1.1.0-beta1-invoc"
19+
"image": "simple:1.1.0-beta1-invoc",
20+
"contentDigest": "sha256:***"
2021
}
2122
],
2223
"images": {

internal/commands/build.go

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/docker/app/internal/packager"
8+
"github.com/sirupsen/logrus"
79
"os"
810
"path/filepath"
911
"strings"
@@ -13,15 +15,13 @@ import (
1315
"github.com/docker/buildx/util/progress"
1416

1517
cnab "github.com/deislabs/cnab-go/driver"
16-
"github.com/docker/app/internal"
1718
"github.com/docker/buildx/bake"
1819
"github.com/docker/buildx/build"
1920
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered, see driver/docker/factory.go:14
2021
"github.com/docker/cli/cli"
2122
"github.com/docker/cli/cli/command"
2223
dockerclient "github.com/docker/docker/client"
2324
"github.com/moby/buildkit/util/appcontext"
24-
"github.com/pkg/errors"
2525
"github.com/spf13/cobra"
2626
)
2727

@@ -54,25 +54,35 @@ func buildCmd(dockerCli command.Cli) *cobra.Command {
5454
}
5555

5656
func runBuild(dockerCli command.Cli, application string, opt buildOptions) error {
57-
appname := internal.DirNameFromAppName(application)
58-
f := "./" + appname + "/" + internal.ComposeFileName
59-
if _, err := os.Stat(f); err != nil {
60-
if os.IsNotExist(errors.Cause(err)) {
61-
return fmt.Errorf("no compose file at %s, did you selected the right docker app folder ?", f)
62-
}
57+
app, err := packager.Extract(application)
58+
if err != nil {
59+
return err
6360
}
61+
defer app.Cleanup()
62+
appname := app.Name
6463

65-
bundle, err := makeBundle(dockerCli, application, nil)
64+
bundle, err := makeBundleFromApp(dockerCli, app, nil)
6665
if err != nil {
6766
return err
6867
}
6968

7069
ctx := appcontext.Context()
71-
targets, err := bake.ReadTargets(ctx, []string{f}, []string{"default"}, nil)
70+
compose, err := bake.ParseCompose(app.Composes()[0]) // Fixme can have > 1 composes ?
7271
if err != nil {
7372
return err
7473
}
7574

75+
targets := map[string]bake.Target{}
76+
for _, n := range compose.ResolveGroup("default") {
77+
t, err := compose.ResolveTarget(n)
78+
if err != nil {
79+
return nil
80+
}
81+
if t != nil {
82+
targets[n] = *t
83+
}
84+
}
85+
7686
for service, t := range targets {
7787
if strings.HasPrefix(*t.Context, ".") {
7888
// Relative path in compose file under x.dockerapp refers to parent folder
@@ -87,19 +97,35 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) error
8797
}
8898
}
8999

90-
// -- debug
91-
dt, err := json.MarshalIndent(map[string]map[string]bake.Target{"target": targets}, "", " ")
92-
if err != nil {
93-
return err
100+
if logrus.IsLevelEnabled(logrus.DebugLevel) {
101+
dt, err := json.MarshalIndent(map[string]map[string]bake.Target{"target": targets}, "", " ")
102+
if err != nil {
103+
return err
104+
}
105+
fmt.Fprintln(dockerCli.Out(), string(dt))
94106
}
95-
fmt.Fprintln(dockerCli.Out(), string(dt))
96-
// -- debug
97107

98108
buildopts, err := bake.TargetsToBuildOpt(targets, opt.noCache, opt.pull)
99109
if err != nil {
100110
return err
101111
}
102112

113+
/**
114+
// FIXME it seems there's no way to setup a build.Options without a plain DockerContext path
115+
buildContext := bytes.NewBuffer(nil)
116+
if err := packager.PackInvocationImageContext(dockerCli, app, buildContext); err != nil {
117+
return err
118+
}
119+
120+
buildopts["invocation-image"] = build.Options{
121+
Inputs: build.Inputs{
122+
InStream: buildContext,
123+
},
124+
Tags: []string{ fmt.Sprintf("%s:%s-%s", bundle.Name, bundle.Version, "-invoc") },
125+
Session: []session.Attachable{authprovider.NewDockerAuthProvider(os.Stderr)},
126+
}
127+
*/
128+
103129
d, err := driver.GetDriver(ctx, "buildx_buildkit_default", nil, dockerCli.Client(), nil, "", nil)
104130
if err != nil {
105131
return err
@@ -151,7 +177,7 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) error
151177
image := bundle.Images[service]
152178
image.ImageType = cnab.ImageTypeDocker
153179
image.Image = fmt.Sprintf("%s:%s-%s", bundle.Name, bundle.Version, service)
154-
image.Digest = inspect.ID
180+
image.Digest = inspect.ID // Content Digest
155181
bundle.Images[service] = image
156182
fmt.Printf(" - %s : %s:%s-%s (%s)\n", service, bundle.Name, bundle.Version, service, inspect.ID)
157183
}

internal/commands/bundle.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ func makeBundleFromApp(dockerCli command.Cli, app *types.App, refOverride refere
120120
}
121121
return nil, err
122122
}
123-
return packager.ToCNAB(app, invocationImageName)
123+
124+
inspect, _, err := dockerCli.Client().ImageInspectWithRaw(context.TODO(), invocationImageName)
125+
if err != nil {
126+
return nil, err
127+
}
128+
129+
return packager.ToCNAB(app, invocationImageName, inspect.ID)
124130
}
125131

126132
func makeInvocationImageName(meta metadata.AppMetadata, refOverride reference.NamedTagged) (string, error) {

internal/packager/cnab.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
)
1818

1919
// ToCNAB creates a CNAB bundle from an app package
20-
func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error) {
20+
func ToCNAB(app *types.App, invocationImageName string, digest string) (*bundle.Bundle, error) {
2121
mapping := ExtractCNABParameterMapping(app.Parameters())
2222
flatParameters := app.Parameters().Flatten()
2323
definitions := definition.Definitions{
@@ -160,6 +160,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
160160
BaseImage: bundle.BaseImage{
161161
Image: invocationImageName,
162162
ImageType: "docker",
163+
Digest: digest,
163164
},
164165
},
165166
},

internal/packager/cnab_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestToCNAB(t *testing.T) {
1414
app, err := types.NewAppFromDefaultFiles("testdata/packages/packing.dockerapp")
1515
assert.NilError(t, err)
16-
actual, err := ToCNAB(app, "test-image")
16+
actual, err := ToCNAB(app, "test-image", "")
1717
assert.NilError(t, err)
1818
actualJSON, err := json.MarshalIndent(actual, "", " ")
1919
assert.NilError(t, err)

0 commit comments

Comments
 (0)