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

Commit 6688c3b

Browse files
author
Ulysses Souza
committed
Remove namespace & repo opts form push and bump v2
- As a result of removing namespace from push command, the repo was also suppressed. - Bump of the metadata schema do v0.2 accepting any formatting on `name` and removing `namespace` Signed-off-by: Ulysses Souza <[email protected]>
1 parent 245b591 commit 6688c3b

File tree

17 files changed

+186
-95
lines changed

17 files changed

+186
-95
lines changed

cmd/docker-app/bundle.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import (
2121
)
2222

2323
type bundleOptions struct {
24-
invocationImageName string
25-
out string
24+
out string
2625
}
2726

2827
func bundleCmd(dockerCli command.Cli) *cobra.Command {
@@ -36,13 +35,12 @@ func bundleCmd(dockerCli command.Cli) *cobra.Command {
3635
},
3736
}
3837

39-
cmd.Flags().StringVarP(&opts.invocationImageName, "invocation-image", "i", "", "specify the name of invocation image to build")
4038
cmd.Flags().StringVarP(&opts.out, "out", "o", "bundle.json", "path to the output bundle.json (- for stdout)")
4139
return cmd
4240
}
4341

4442
func runBundle(dockerCli command.Cli, appName string, opts bundleOptions) error {
45-
bundle, err := makeBundle(dockerCli, appName, opts.invocationImageName)
43+
bundle, err := makeBundle(dockerCli, appName)
4644
if err != nil {
4745
return err
4846
}
@@ -61,22 +59,22 @@ func runBundle(dockerCli command.Cli, appName string, opts bundleOptions) error
6159
return ioutil.WriteFile(opts.out, bundleBytes, 0644)
6260
}
6361

64-
func makeBundle(dockerCli command.Cli, appName, invocationImageName string) (*bundle.Bundle, error) {
62+
func makeBundle(dockerCli command.Cli, appName string) (*bundle.Bundle, error) {
6563
app, err := packager.Extract(appName)
6664
if err != nil {
6765
return nil, err
6866
}
6967
defer app.Cleanup()
70-
return makeBundleFromApp(dockerCli, app, invocationImageName)
68+
return makeBundleFromApp(dockerCli, app)
7169
}
7270

73-
func makeBundleFromApp(dockerCli command.Cli, app *types.App, invocationImageName string) (*bundle.Bundle, error) {
71+
func makeBundleFromApp(dockerCli command.Cli, app *types.App) (*bundle.Bundle, error) {
7472
meta := app.Metadata()
75-
invocationImageName, err := makeImageName(meta, invocationImageName, "-invoc")
73+
invocationImageName, err := makeImageName(meta)
7674
if err != nil {
7775
return nil, err
7876
}
79-
if _, err := makeImageName(app.Metadata(), "", ""); err != nil {
77+
if _, err := makeImageName(meta); err != nil {
8078
return nil, err
8179
}
8280

@@ -100,12 +98,10 @@ func makeBundleFromApp(dockerCli command.Cli, app *types.App, invocationImageNam
10098
return packager.ToCNAB(app, invocationImageName)
10199
}
102100

103-
func makeImageName(meta metadata.AppMetadata, name, suffix string) (string, error) {
104-
if name == "" {
105-
name = fmt.Sprintf("%s:%s%s", meta.Name, meta.Version, suffix)
106-
}
101+
func makeImageName(meta metadata.AppMetadata) (string, error) {
102+
name := fmt.Sprintf("%s:%s-invoc", meta.Name, meta.Version)
107103
if _, err := reference.ParseNormalizedNamed(name); err != nil {
108-
return "", errors.Wrapf(err, "image name %q is invalid, please check namespace, name and version fields", name)
104+
return "", errors.Wrapf(err, "image name %q is invalid, please check name and version fields", name)
109105
}
110106
return name, nil
111107
}

cmd/docker-app/bundle_test.go

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,16 @@ import (
99

1010
func TestMakeInvocationImage(t *testing.T) {
1111
testcases := []struct {
12-
name string
13-
imageName string
14-
meta metadata.AppMetadata
15-
expected string
16-
err string
12+
name string
13+
meta metadata.AppMetadata
14+
expected string
15+
err string
1716
}{
18-
{
19-
name: "specify-image-name",
20-
imageName: "my-invocation-image",
21-
expected: "my-invocation-image",
22-
},
23-
{
24-
name: "specify-image-name-and-namespace",
25-
imageName: "my-invocation-image",
26-
expected: "my-invocation-image",
27-
},
2817
{
2918
name: "simple-metadata",
3019
meta: metadata.AppMetadata{Name: "name", Version: "version"},
3120
expected: "name:version-invoc",
3221
},
33-
{
34-
name: "simple-metadata-with-overridden-namespace",
35-
meta: metadata.AppMetadata{Name: "name", Version: "version"},
36-
expected: "name:version-invoc",
37-
},
38-
{
39-
name: "metadata-with-namespace",
40-
meta: metadata.AppMetadata{Name: "name", Version: "version"},
41-
expected: "name:version-invoc",
42-
},
43-
{
44-
name: "metadata-with-namespace-and-overridden-namespace",
45-
meta: metadata.AppMetadata{Name: "name", Version: "version"},
46-
expected: "name:version-invoc",
47-
},
4822
{
4923
name: "simple-metadata",
5024
meta: metadata.AppMetadata{Name: "WrongName&%*", Version: "version"},
@@ -53,10 +27,10 @@ func TestMakeInvocationImage(t *testing.T) {
5327
}
5428
for _, c := range testcases {
5529
t.Run(c.name, func(t *testing.T) {
56-
actual, err := makeImageName(c.meta, c.imageName, "-invoc")
30+
actual, err := makeImageName(c.meta)
5731
if c.err != "" {
5832
assert.ErrorContains(t, err, c.err)
59-
assert.Equal(t, actual, "")
33+
assert.Equal(t, actual, "", "On "+c.meta.Name)
6034
} else {
6135
assert.NilError(t, err)
6236
assert.Equal(t, actual, c.expected)

cmd/docker-app/cnab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func extractAndLoadAppBasedBundle(dockerCli command.Cli, name string) (*bundle.B
123123
return nil, err
124124
}
125125
defer app.Cleanup()
126-
return makeBundleFromApp(dockerCli, app, "")
126+
return makeBundleFromApp(dockerCli, app)
127127
}
128128

129129
func resolveBundle(dockerCli command.Cli, name string) (*bundle.Bundle, error) {

cmd/docker-app/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command {
2727
if err != nil {
2828
return err
2929
}
30-
bundle, err := resolveBundle(dockerCli, "", appname)
30+
bundle, err := resolveBundle(dockerCli, appname)
3131
if err != nil {
3232
return err
3333
}

cmd/docker-app/push.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
)
1010

1111
type pushOptions struct {
12-
namespace string
13-
tag string
14-
repo string
12+
tag string
1513
}
1614

1715
func pushCmd() *cobra.Command {
@@ -26,15 +24,13 @@ func pushCmd() *cobra.Command {
2624
return err
2725
}
2826
defer app.Cleanup()
29-
dgst, err := packager.Push(app, opts.namespace, opts.tag, opts.repo)
27+
dgst, err := packager.Push(app, opts.tag)
3028
if err == nil {
3129
fmt.Println(dgst)
3230
}
3331
return err
3432
},
3533
}
36-
cmd.Flags().StringVar(&opts.namespace, "namespace", "", "Namespace to use")
37-
cmd.Flags().StringVarP(&opts.tag, "tag", "t", "", "Tag to use (default: version in metadata)")
38-
cmd.Flags().StringVar(&opts.repo, "repo", "", "Name of the remote repository (default: <app-name>.dockerapp)")
34+
cmd.Flags().StringVarP(&opts.tag, "tag", "t", "", "Target registry reference (default is : from metadata)")
3935
return cmd
4036
}

e2e/commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ func TestBundle(t *testing.T) {
241241

242242
// List the images on the build context daemon and checks the invocation image is there
243243
cmd.Command = []string{dockerCli, "image", "ls", "--format", "{{.Repository}}:{{.Tag}}"}
244-
icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 0, Out: "acmecorp/simple:1.1.0-beta1-invoc"})
244+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 0, Out: "simple:1.1.0-beta1-invoc"})
245245

246246
// Copy all the files from the invocation image and check them
247-
cmd.Command = []string{dockerCli, "create", "--name", "invocation", "acmecorp/simple:1.1.0-beta1-invoc"}
247+
cmd.Command = []string{dockerCli, "create", "--name", "invocation", "simple:1.1.0-beta1-invoc"}
248248
id := strings.TrimSpace(icmd.RunCmd(cmd).Assert(t, icmd.Success).Stdout())
249249
cmd.Command = []string{dockerCli, "cp", "invocation:/cnab/app/simple.dockerapp", tmpDir.Join("simple.dockerapp")}
250250
icmd.RunCmd(cmd).Assert(t, icmd.Success)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
version: 0.1.0
22
name: myapp
33
description: ""
4-
namespace: "alice"
54
maintainers:
65
- name: bearclaw
76

e2e/testdata/simple-bundle.json.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "acmecorp/simple",
2+
"name": "simple",
33
"version": "1.1.0-beta1",
44
"description": "new fancy webapp with microservices",
55
"maintainers": [
@@ -17,7 +17,7 @@
1717
"invocationImages": [
1818
{
1919
"imageType": "docker",
20-
"image": "acmecorp/simple:1.1.0-beta1-invoc"
20+
"image": "simple:1.1.0-beta1-invoc"
2121
}
2222
],
2323
"images": {

e2e/testdata/simple/simple.dockerapp/metadata.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
version: 1.1.0-beta1
22
name: simple
3-
namespace: acmecorp
43
description: "new fancy webapp with microservices"
54
maintainers:
65
- name: John Developer

examples/voting-app/voting-app.dockerapp/metadata.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ version: 0.1.0
44
name: voting-app
55
# A short description of the application
66
description: "Dogs or cats?"
7-
# Namespace to use when pushing to a registry. This is typically your Hub username.
8-
namespace: myhubusername
97
# List of application maintainers with name and email for each
108
maintainers:
119
- name: user

0 commit comments

Comments
 (0)