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

Commit 8539c06

Browse files
authored
Merge pull request #692 from rumpl/feat-docker-app-version-custom
Add the docker app version in the bundle
2 parents 3e97bfd + 37b6193 commit 8539c06

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

internal/names.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const (
6969
// DockerInspectFormatEnvVar is the environment variable set by the CNAB runtime to select
7070
// the inspect output format.
7171
DockerInspectFormatEnvVar = "DOCKER_INSPECT_FORMAT"
72+
73+
// CustomDockerAppName is the custom variable set by Docker App to
74+
// save custom informations
75+
CustomDockerAppName = "com.docker.app"
7276
)
7377

7478
var (

internal/packager/cnab.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const (
1616
CNABVersion1_0_0 = "v1.0.0-WD"
1717
)
1818

19+
// DockerAppCustom contains extension custom data that docker app injects
20+
// in the bundle.
21+
type DockerAppCustom struct {
22+
Version string `json:"version,omitempty"`
23+
Payload json.RawMessage `json:"payload,omitempty"`
24+
}
25+
1926
// ToCNAB creates a CNAB bundle from an app package
2027
func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error) {
2128
mapping := ExtractCNABParameterMapping(app.Parameters())
@@ -142,6 +149,11 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
142149

143150
bndl := &bundle.Bundle{
144151
SchemaVersion: CNABVersion1_0_0,
152+
Custom: map[string]interface{}{
153+
internal.CustomDockerAppName: DockerAppCustom{
154+
Version: internal.Version,
155+
},
156+
},
145157
Credentials: map[string]bundle.Credential{
146158
internal.CredentialDockerContextName: {
147159
Location: bundle.Location{

internal/packager/cnab_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package packager
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"testing"
67

7-
"gotest.tools/golden"
8-
8+
"github.com/docker/app/internal"
99
"github.com/docker/app/types"
1010
"gotest.tools/assert"
11+
"gotest.tools/golden"
1112
)
1213

1314
func TestToCNAB(t *testing.T) {
@@ -17,5 +18,7 @@ func TestToCNAB(t *testing.T) {
1718
assert.NilError(t, err)
1819
actualJSON, err := json.MarshalIndent(actual, "", " ")
1920
assert.NilError(t, err)
20-
golden.Assert(t, string(actualJSON), "bundle-json.golden")
21+
s := golden.Get(t, "bundle-json.golden")
22+
expected := fmt.Sprintf(string(s), internal.Version)
23+
assert.Equal(t, string(actualJSON), expected)
2124
}

internal/packager/testdata/bundle-json.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,10 @@
162162
"default": "foo",
163163
"type": "string"
164164
}
165+
},
166+
"custom": {
167+
"com.docker.app": {
168+
"version": "%s"
169+
}
165170
}
166171
}

0 commit comments

Comments
 (0)