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

Commit 248d5ab

Browse files
committed
Add e2e test for service container labels on run
Signed-off-by: Djordje Lukic <[email protected]>
1 parent e1cbea5 commit 248d5ab

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

cmd/cnab-run/install.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ func addLabels(rendered *composetypes.Config) error {
9696
if err != nil {
9797
return err
9898
}
99-
a := packager.DockerAppArgs{}
100-
err = json.Unmarshal(args, &a)
101-
if err != nil {
99+
var a packager.DockerAppArgs
100+
if err := json.Unmarshal(args, &a); err != nil {
102101
return err
103102
}
104103
for k, v := range a.Labels {

e2e/commands_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,31 @@ func TestRunOnlyOne(t *testing.T) {
193193
})
194194
}
195195

196+
func TestRunWithLabels(t *testing.T) {
197+
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
198+
cmd := info.configuredCmd
199+
200+
contextPath := filepath.Join("testdata", "simple")
201+
cmd.Command = dockerCli.Command("app", "build", "--tag", "myapp", contextPath)
202+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
203+
204+
cmd.Command = dockerCli.Command("app", "run", "myapp", "--name", "myapp", "--label", "label.key=labelValue")
205+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
206+
207+
services := []string{
208+
"myapp_db", "myapp_web", "myapp_api",
209+
}
210+
for _, service := range services {
211+
fmt.Printf("%q", service)
212+
cmd.Command = dockerCli.Command("inspect", service)
213+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
214+
ExitCode: 0,
215+
Out: `"label.key": "labelValue"`,
216+
})
217+
}
218+
})
219+
}
220+
196221
func TestDockerAppLifecycle(t *testing.T) {
197222
t.Run("withBindMounts", func(t *testing.T) {
198223
testDockerAppLifecycle(t, true)

internal/commands/parameters.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func withCommandLineParameters(overrides []string) mergeBundleOpt {
4949

5050
func withLabels(labels []string) mergeBundleOpt {
5151
return func(c *mergeBundleConfig) error {
52+
for _, l := range labels {
53+
if strings.HasPrefix(l, internal.Namespace) {
54+
return errors.Errorf("labels cannot start with %q", internal.Namespace)
55+
}
56+
}
5257
l := packager.DockerAppArgs{
5358
Labels: cliopts.ConvertKVStringsToMap(labels),
5459
}

internal/packager/cnab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
3838
internal.ParameterArgs: {
3939
Type: "string",
4040
Default: "",
41-
Title: "Labels",
42-
Description: "Labels to apply to service containers",
41+
Title: "Arguments",
42+
Description: "Arguments that are passed by file to the invocation image",
4343
},
4444
internal.ParameterOrchestratorName: {
4545
Type: "string",

internal/packager/testdata/bundle-json.golden

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
"io.cnab.status": {}
5252
},
5353
"parameters": {
54+
"com.docker.app.args": {
55+
"definition": "com.docker.app.args",
56+
"applyTo": [
57+
"install",
58+
"upgrade"
59+
],
60+
"destination": {
61+
"path": "/cnab/app/args.json"
62+
}
63+
},
5464
"com.docker.app.inspect-format": {
5565
"definition": "com.docker.app.inspect-format",
5666
"applyTo": [
@@ -115,6 +125,12 @@
115125
}
116126
},
117127
"definitions": {
128+
"com.docker.app.args": {
129+
"default": "",
130+
"description": "Arguments that are passed by file to the invocation image",
131+
"title": "Arguments",
132+
"type": "string"
133+
},
118134
"com.docker.app.inspect-format": {
119135
"default": "json",
120136
"description": "Output format for the inspect command",

0 commit comments

Comments
 (0)