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

Add the docker app version in the bundle #692

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const (
// DockerInspectFormatEnvVar is the environment variable set by the CNAB runtime to select
// the inspect output format.
DockerInspectFormatEnvVar = "DOCKER_INSPECT_FORMAT"

// CustomDockerAppName is the custom variable set by Docker App to
// save custom informations
CustomDockerAppName = "com.docker.app"
)

var (
Expand Down
12 changes: 12 additions & 0 deletions internal/packager/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const (
CNABVersion1_0_0 = "v1.0.0-WD"
)

// DockerAppCustom contains extension custom data that docker app injects
// in the bundle.
type DockerAppCustom struct {
Version string `json:"version,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
}

// ToCNAB creates a CNAB bundle from an app package
func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error) {
mapping := ExtractCNABParameterMapping(app.Parameters())
Expand Down Expand Up @@ -142,6 +149,11 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)

bndl := &bundle.Bundle{
SchemaVersion: CNABVersion1_0_0,
Custom: map[string]interface{}{
internal.CustomDockerAppName: DockerAppCustom{
Version: internal.Version,
},
},
Credentials: map[string]bundle.Credential{
internal.CredentialDockerContextName: {
Location: bundle.Location{
Expand Down
9 changes: 6 additions & 3 deletions internal/packager/cnab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package packager

import (
"encoding/json"
"fmt"
"testing"

"gotest.tools/golden"

"github.com/docker/app/internal"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import order is weird 🤔

"github.com/docker/app/types"
"gotest.tools/assert"
"gotest.tools/golden"
)

func TestToCNAB(t *testing.T) {
Expand All @@ -17,5 +18,7 @@ func TestToCNAB(t *testing.T) {
assert.NilError(t, err)
actualJSON, err := json.MarshalIndent(actual, "", " ")
assert.NilError(t, err)
golden.Assert(t, string(actualJSON), "bundle-json.golden")
s := golden.Get(t, "bundle-json.golden")
expected := fmt.Sprintf(string(s), internal.Version)
assert.Equal(t, string(actualJSON), expected)
}
5 changes: 5 additions & 0 deletions internal/packager/testdata/bundle-json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,10 @@
"default": "foo",
"type": "string"
}
},
"custom": {
"com.docker.app": {
"version": "%s"
}
}
}