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

Rename relocated.bundle to AppImage #773

Merged
merged 1 commit into from
Dec 6, 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
12 changes: 6 additions & 6 deletions cmd/cnab-run/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ package main

import (
"github.com/deislabs/cnab-go/bundle"
"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"
"github.com/docker/cnab-to-oci/relocation"
)

const (
// bundlePath is where the CNAB runtime will put the actual Bundle definition
// bundlePath is where the CNAB runtime will put the actual AppImage definition
bundlePath = "/cnab/bundle.json"
// relocationMapPath is where the CNAB runtime will put the relocation map
// See https://github.com/cnabio/cnab-spec/blob/master/103-bundle-runtime.md#image-relocation
relocationMapPath = "/cnab/app/relocation-mapping.json"
)

func getBundle() (*bundle.Bundle, error) {
return relocated.BundleJSON(bundlePath)
return image.BundleJSON(bundlePath)
}

func getRelocationMap() (relocation.ImageRelocationMap, error) {
return relocated.RelocationMapJSON(relocationMapPath)
return image.RelocationMapJSON(relocationMapPath)
}

func getRelocatedBundle() (*relocated.Bundle, error) {
func getRelocatedBundle() (*image.AppImage, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: What about image.App ? image.AppImage sounds like repetition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better rename package then. "App" is highly confusing with "running app".

bndl, err := getBundle()
if err != nil {
return nil, err
Expand All @@ -33,7 +33,7 @@ func getRelocatedBundle() (*relocated.Bundle, error) {
return nil, err
}

return &relocated.Bundle{
return &image.AppImage{
Bundle: bndl,
RelocationMap: relocationMap,
}, nil
Expand Down
22 changes: 11 additions & 11 deletions e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"

"gotest.tools/fs"

Expand All @@ -32,8 +32,8 @@ func TestBuild(t *testing.T) {

cfg := getDockerConfigDir(t, cmd)

f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", "1.0.0", relocated.BundleFilename)
bndl, err := relocated.BundleFromFile(f)
f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", "1.0.0", image.BundleFilename)
bndl, err := image.FromFile(f)
assert.NilError(t, err)

built := []string{bndl.InvocationImages[0].Digest, bndl.Images["web"].Digest, bndl.Images["worker"].Digest}
Expand All @@ -52,7 +52,7 @@ func TestBuild(t *testing.T) {
bytes, err := ioutil.ReadFile(iidfile)
assert.NilError(t, err)
iid := string(bytes)
actualID, err := store.FromBundle(bndl)
actualID, err := store.FromAppImage(bndl)
assert.NilError(t, err)
assert.Equal(t, iid, fmt.Sprintf("sha256:%s", actualID.String()))
})
Expand All @@ -71,15 +71,15 @@ func TestBuildMultiTag(t *testing.T) {
cfg := getDockerConfigDir(t, cmd)

for _, tag := range tags {
f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", tag, relocated.BundleFilename)
bndl, err := relocated.BundleFromFile(f)
f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", tag, image.BundleFilename)
img, err := image.FromFile(f)
assert.NilError(t, err)
built := []string{bndl.InvocationImages[0].Digest, bndl.Images["web"].Digest, bndl.Images["worker"].Digest}
built := []string{img.InvocationImages[0].Digest, img.Images["web"].Digest, img.Images["worker"].Digest}
for _, ref := range built {
cmd.Command = dockerCli.Command("inspect", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}
for _, img := range bndl.Images {
for _, img := range img.Images {
// Check all image not being built locally get a fixed reference
assert.Assert(t, img.Image == "" || strings.Contains(img.Image, "@sha256:"))
}
Expand All @@ -88,7 +88,7 @@ func TestBuildMultiTag(t *testing.T) {
bytes, err := ioutil.ReadFile(iidfile)
assert.NilError(t, err)
iid := string(bytes)
actualID, err := store.FromBundle(bndl)
actualID, err := store.FromAppImage(img)
assert.NilError(t, err)
assert.Equal(t, iid, fmt.Sprintf("sha256:%s", actualID.String()))
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestBuildWithoutTag(t *testing.T) {
assert.Equal(t, len(infos), 1)
id := infos[0].Name()

f = path.Join(cfg, "app", "bundles", "_ids", id, relocated.BundleFilename)
f = path.Join(cfg, "app", "bundles", "_ids", id, image.BundleFilename)
data, err := ioutil.ReadFile(f)
assert.NilError(t, err)
var bndl bundle.Bundle
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestBuildWithArgs(t *testing.T) {
assert.Equal(t, len(infos), 1)
id := infos[0].Name()

f = path.Join(cfg, "app", "bundles", "_ids", id, relocated.BundleFilename)
f = path.Join(cfg, "app", "bundles", "_ids", id, image.BundleFilename)
data, err := ioutil.ReadFile(f)
assert.NilError(t, err)
var bndl bundle.Bundle
Expand Down
6 changes: 3 additions & 3 deletions e2e/cnab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path"
"testing"

"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/icmd"
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestCallCustomStatusAction(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// docker app install
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, relocated.BundleFilename), "--name", testCase.name)
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", testCase.name)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// docker app uninstall
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestCnabParameters(t *testing.T) {
}()

// docker app install
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, relocated.BundleFilename), "--name", "cnab-parameters",
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", path.Join(testDir, image.BundleFilename), "--name", "cnab-parameters",
"--set", "boolParam=true",
"--set", "stringParam=value",
"--set", "intParam=42")
Expand Down
8 changes: 4 additions & 4 deletions e2e/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/deislabs/cnab-go/credentials"
"github.com/docker/app/internal"
"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"
"github.com/docker/app/internal/yaml"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestRunOnlyOne(t *testing.T) {
Err: `"docker app run" requires exactly 1 argument.`,
})

cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", relocated.BundleFilename, "myapp")
cmd.Command = dockerCli.Command("app", "run", "--cnab-bundle-json", image.BundleFilename, "myapp")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `"docker app run" cannot run a bundle and an App image`,
Expand Down Expand Up @@ -454,14 +454,14 @@ func TestCredentials(t *testing.T) {
assert.NilError(t, err)
bundleJSON := golden.Get(t, "credential-install-bundle.json")
tmpDir := fs.NewDir(t, t.Name(),
fs.WithFile(relocated.BundleFilename, "", fs.WithBytes(bundleJSON)),
fs.WithFile(image.BundleFilename, "", fs.WithBytes(bundleJSON)),
fs.WithDir("local",
fs.WithFile("test-creds.yaml", "", fs.WithBytes(buf)),
),
)
defer tmpDir.Remove()

bundle := tmpDir.Join(relocated.BundleFilename)
bundle := tmpDir.Join(image.BundleFilename)

t.Run("missing", func(t *testing.T) {
cmd.Command = dockerCli.Command(
Expand Down
16 changes: 8 additions & 8 deletions e2e/relocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"testing"

"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"
"gotest.tools/assert/cmp"

"gotest.tools/assert"
Expand All @@ -28,15 +28,15 @@ func TestRelocationMapCreatedOnPull(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// And given application files are remove
assert.NilError(t, os.RemoveAll(bundlePath))
_, err := os.Stat(filepath.Join(bundlePath, relocated.BundleFilename))
_, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename))
assert.Assert(t, os.IsNotExist(err))

// When application is pulled
cmd.Command = dockerCli.Command("app", "pull", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// Then the relocation map should exist
_, err = os.Stat(filepath.Join(bundlePath, relocated.RelocationMapFilename))
_, err = os.Stat(filepath.Join(bundlePath, image.RelocationMapFilename))
assert.NilError(t, err)
})
}
Expand All @@ -56,7 +56,7 @@ func TestRelocationMapRun(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// And given application files are remove
assert.NilError(t, os.RemoveAll(bundlePath))
_, err := os.Stat(filepath.Join(bundlePath, relocated.BundleFilename))
_, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename))
assert.Assert(t, os.IsNotExist(err))
// And given local images are removed
cmd.Command = dockerCli.Command("rmi", "web", "local:1.1.0-beta1-invoc", "worker")
Expand All @@ -82,7 +82,7 @@ func TestRelocationMapRun(t *testing.T) {
t.Run("without-relocation-map", func(t *testing.T) {
name := "test-relocation-map-run-without-relocation-map"
// And given the relocation map is removed after the pull
assert.NilError(t, os.RemoveAll(filepath.Join(bundlePath, relocated.RelocationMapFilename)))
assert.NilError(t, os.RemoveAll(filepath.Join(bundlePath, image.RelocationMapFilename)))

// Then the application cannot be run
cmd.Command = dockerCli.Command("app", "run", "--name", name, ref)
Expand All @@ -109,7 +109,7 @@ func TestPushPulledApplication(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// And given application files are remove
assert.NilError(t, os.RemoveAll(bundlePath))
_, err := os.Stat(filepath.Join(bundlePath, relocated.BundleFilename))
_, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename))
assert.Assert(t, os.IsNotExist(err))

// And given application is pulled from the registry
Expand All @@ -121,7 +121,7 @@ func TestPushPulledApplication(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// If relocation map is removed
assert.NilError(t, os.RemoveAll(filepath.Join(bundlePath, relocated.RelocationMapFilename)))
assert.NilError(t, os.RemoveAll(filepath.Join(bundlePath, image.RelocationMapFilename)))

// Then the application cannot be pushed
cmd.Command = dockerCli.Command("app", "push", ref)
Expand All @@ -144,7 +144,7 @@ func TestRelocationMapOnInspect(t *testing.T) {
icmd.RunCmd(cmd).Assert(t, icmd.Success)
// And given application files are remove
assert.NilError(t, os.RemoveAll(bundlePath))
_, err := os.Stat(filepath.Join(bundlePath, relocated.BundleFilename))
_, err := os.Stat(filepath.Join(bundlePath, image.BundleFilename))
assert.Assert(t, os.IsNotExist(err))
// And given local images are removed
cmd.Command = dockerCli.Command("rmi", "web", "local:1.1.0-beta1-invoc", "worker")
Expand Down
12 changes: 6 additions & 6 deletions internal/bundle/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/image"

"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/bundle/definition"
Expand Down Expand Up @@ -115,8 +115,8 @@ func withParameterAndValues(name, typ string, allowedValues []interface{}) bundl
}
}

func prepareBundle(ops ...bundleOperator) *relocated.Bundle {
b := relocated.FromBundle(&bundle.Bundle{})
func prepareBundle(ops ...bundleOperator) *image.AppImage {
b := image.FromBundle(&bundle.Bundle{})
for _, op := range ops {
op(b.Bundle)
}
Expand All @@ -126,19 +126,19 @@ func prepareBundle(ops ...bundleOperator) *relocated.Bundle {
func TestWithOrchestratorParameters(t *testing.T) {
testCases := []struct {
name string
bundle *relocated.Bundle
bundle *image.AppImage
expected map[string]string
}{
{
name: "Bundle with orchestrator params",
name: "AppImage with orchestrator params",
bundle: prepareBundle(withParameter(internal.ParameterOrchestratorName, "string"), withParameter(internal.ParameterKubernetesNamespaceName, "string")),
expected: map[string]string{
internal.ParameterOrchestratorName: "kubernetes",
internal.ParameterKubernetesNamespaceName: "my-namespace",
},
},
{
name: "Bundle without orchestrator params",
name: "AppImage without orchestrator params",
bundle: prepareBundle(),
expected: map[string]string{},
},
Expand Down
30 changes: 15 additions & 15 deletions internal/cnab/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"

"github.com/docker/app/internal"
"github.com/docker/app/internal/image"
"github.com/docker/app/internal/log"
"github.com/docker/app/internal/packager"
"github.com/docker/app/internal/relocated"
"github.com/docker/app/internal/store"
appstore "github.com/docker/app/internal/store"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -47,20 +47,20 @@ func getAppNameKind(name string) (string, nameKind) {
return name, nameKindReference
}

func extractAndLoadAppBasedBundle(dockerCli command.Cli, name string) (*relocated.Bundle, string, error) {
func extractAndLoadAppBasedBundle(dockerCli command.Cli, name string) (*image.AppImage, string, error) {
app, err := packager.Extract(name)
if err != nil {
return nil, "", err
}
defer app.Cleanup()
bndl, err := packager.MakeBundleFromApp(dockerCli, app, nil)
return relocated.FromBundle(bndl), "", err
return image.FromBundle(bndl), "", err
}

// ResolveBundle looks for a CNAB bundle which can be in a Docker App Package format or
// a bundle stored locally or in the bundle store. It returns a built or found bundle,
// a reference to the bundle if it is found in the bundlestore, and an error.
func ResolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name string) (*relocated.Bundle, string, error) {
// a reference to the bundle if it is found in the imageStore, and an error.
func ResolveBundle(dockerCli command.Cli, imageStore appstore.ImageStore, name string) (*image.AppImage, string, error) {
// resolution logic:
// - if there is a docker-app package in working directory or if a directory is given use packager.Extract
// - pull the bundle from the registry and add it to the bundle store
Expand All @@ -69,7 +69,7 @@ func ResolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name
case nameKindDir:
return extractAndLoadAppBasedBundle(dockerCli, name)
case nameKindReference:
bndl, tagRef, err := GetBundle(dockerCli, bundleStore, name)
bndl, tagRef, err := GetBundle(dockerCli, imageStore, name)
if err != nil {
return nil, "", err
}
Expand All @@ -79,16 +79,16 @@ func ResolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name
}

// GetBundle searches for the bundle locally and tries to pull it if not found
func GetBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name string) (*relocated.Bundle, reference.Reference, error) {
bndl, ref, err := getBundleFromStore(bundleStore, name)
func GetBundle(dockerCli command.Cli, imageStore appstore.ImageStore, name string) (*image.AppImage, reference.Reference, error) {
bndl, ref, err := getBundleFromStore(imageStore, name)
if err != nil {
named, err := store.StringToNamedRef(name)
if err != nil {
return nil, nil, err
}
fmt.Fprintf(dockerCli.Err(), "Unable to find App image %q locally\n", reference.FamiliarString(named))
fmt.Fprintf(dockerCli.Out(), "Pulling from registry...\n")
bndl, err = PullBundle(dockerCli, bundleStore, named)
bndl, err = PullBundle(dockerCli, imageStore, named)
if err != nil {
return nil, nil, err
}
Expand All @@ -97,13 +97,13 @@ func GetBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name str
return bndl, ref, nil
}

func getBundleFromStore(bundleStore appstore.BundleStore, name string) (*relocated.Bundle, reference.Reference, error) {
ref, err := bundleStore.LookUp(name)
func getBundleFromStore(imageStore appstore.ImageStore, name string) (*image.AppImage, reference.Reference, error) {
ref, err := imageStore.LookUp(name)
if err != nil {
logrus.Debugf("Unable to find reference %q in the bundle store", name)
return nil, nil, err
}
bndl, err := bundleStore.Read(ref)
bndl, err := imageStore.Read(ref)
if err != nil {
logrus.Debugf("Unable to read bundle %q from store", reference.FamiliarString(ref))
return nil, nil, err
Expand All @@ -112,7 +112,7 @@ func getBundleFromStore(bundleStore appstore.BundleStore, name string) (*relocat
}

// PullBundle pulls the bundle and stores it into the bundle store
func PullBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, tagRef reference.Named) (*relocated.Bundle, error) {
func PullBundle(dockerCli command.Cli, imageStore appstore.ImageStore, tagRef reference.Named) (*image.AppImage, error) {
insecureRegistries, err := internal.InsecureRegistriesFromEngine(dockerCli)
if err != nil {
return nil, fmt.Errorf("could not retrieve insecure registries: %v", err)
Expand All @@ -122,8 +122,8 @@ func PullBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, tagRef
if err != nil {
return nil, err
}
relocatedBundle := &relocated.Bundle{Bundle: bndl, RelocationMap: relocationMap}
if _, err := bundleStore.Store(tagRef, relocatedBundle); err != nil {
relocatedBundle := &image.AppImage{Bundle: bndl, RelocationMap: relocationMap}
if _, err := imageStore.Store(tagRef, relocatedBundle); err != nil {
return nil, err
}
return relocatedBundle, nil
Expand Down