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

Commit

Permalink
Support using bundles both by Named reference and raw ID
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 11, 2019
1 parent 6a9e04b commit 9a97b79
Show file tree
Hide file tree
Showing 45 changed files with 296 additions and 828 deletions.
56 changes: 46 additions & 10 deletions e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,43 @@ func TestBuild(t *testing.T) {
cmd := info.configuredCmd

testDir := path.Join("testdata", "build")
cmd.Command = dockerCli.Command("app", "build", path.Join(testDir, "single"), "single:1.0.0")
cmd.Command = dockerCli.Command("app", "build", path.Join(testDir, "single"), "--tag", "single:1.0.0")
icmd.RunCmd(cmd).Assert(t, icmd.Success)

var cfg string
for _, s := range cmd.Env {
if strings.HasPrefix(s, "DOCKER_CONFIG=") {
cfg = s[14:]
}
}
if cfg == "" {
t.Fatalf("Failed to retrieve docker config folder")
cfg := getDockerConfigDir(t, cmd)

f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", "1.0.0", "bundle.json")
data, err := ioutil.ReadFile(f)
assert.NilError(t, err)
var bndl bundle.Bundle
err = json.Unmarshal(data, &bndl)
assert.NilError(t, err)

built := []string{bndl.InvocationImages[0].Digest, bndl.Images["web"].Digest, bndl.Images["worker"].Digest}
for _, ref := range built {
cmd.Command = dockerCli.Command("inspect", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}
})
}

func TestBuildWithoutTag(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
cmd := info.configuredCmd

testDir := path.Join("testdata", "build")
cmd.Command = dockerCli.Command("app", "build", path.Join(testDir, "single"))
icmd.RunCmd(cmd).Assert(t, icmd.Success)

f := path.Join(cfg, "app", "bundles", "docker.io", "library", "single", "_tags", "1.0.0.json")
cfg := getDockerConfigDir(t, cmd)

f := path.Join(cfg, "app", "bundles", "_ids")
infos, err := ioutil.ReadDir(f)
assert.NilError(t, err)
assert.Equal(t, len(infos), 1)
id := infos[0].Name()

f = path.Join(cfg, "app", "bundles", "_ids", id, "bundle.json")
data, err := ioutil.ReadFile(f)
assert.NilError(t, err)
var bndl bundle.Bundle
Expand All @@ -44,3 +67,16 @@ func TestBuild(t *testing.T) {
}
})
}

func getDockerConfigDir(t *testing.T, cmd icmd.Cmd) string {
var cfg string
for _, s := range cmd.Env {
if strings.HasPrefix(s, "DOCKER_CONFIG=") {
cfg = s[14:]
}
}
if cfg == "" {
t.Fatalf("Failed to retrieve docker config folder")
}
return cfg
}
6 changes: 3 additions & 3 deletions e2e/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestRenderFormatters(t *testing.T) {
cmd := info.configuredCmd

appPath := filepath.Join("testdata", "simple", "simple.dockerapp")
cmd.Command = dockerCli.Command("app", "build", appPath, "a-simple-tag")
cmd.Command = dockerCli.Command("app", "build", appPath, "--tag", "a-simple-tag")
icmd.RunCmd(cmd).Assert(t, icmd.Success)

cmd.Command = dockerCli.Command("app", "render", "--formatter", "json", appPath)
Expand Down Expand Up @@ -161,10 +161,10 @@ func TestInspectApp(t *testing.T) {
cmd.Dir = dir.Path()
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: "invalid reference format",
Err: "could not parse '' as a valid reference",
})

cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "simple-app:1.0.0")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "--tag", "simple-app:1.0.0")
cmd.Dir = ""
icmd.RunCmd(cmd).Assert(t, icmd.Success)

Expand Down
14 changes: 7 additions & 7 deletions e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

func insertBundles(t *testing.T, cmd icmd.Cmd, info dindSwarmAndRegistryInfo) {
// Push an application so that we can later pull it by digest
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), info.registryAddress+"/c-myapp")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "--tag", info.registryAddress+"/c-myapp")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "b-simple-app")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "--tag", "b-simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "a-simple-app")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "--tag", "a-simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestImageTag(t *testing.T) {
}

// given a first available image
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "a-simple-app")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "simple", "simple.dockerapp"), "--tag", "a-simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Success)

singleImageExpectation := `APP IMAGE APP NAME
Expand All @@ -112,14 +112,14 @@ a-simple-app:latest simple
dockerAppImageTag("a-simple-app$2", "b-simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `could not parse 'a-simple-app$2' as a valid reference: invalid reference format`,
Err: `could not parse 'a-simple-app$2' as a valid reference`,
})

// with invalid target reference
dockerAppImageTag("a-simple-app", "b@simple-app")
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
ExitCode: 1,
Err: `could not parse 'b@simple-app' as a valid reference: invalid reference format`,
Err: `could not parse 'b@simple-app' as a valid reference`,
})

// with unexisting source image
Expand Down Expand Up @@ -175,7 +175,7 @@ c-simple-app:latest simple
`)

// given a new application
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "push-pull")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "--tag", "push-pull")
icmd.RunCmd(cmd).Assert(t, icmd.Success)
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
a-simple-app:0.1 simple
Expand Down
4 changes: 2 additions & 2 deletions e2e/pushpull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func TestPushInstallBundle(t *testing.T) {
ref := info.registryAddress + "/test/push-bundle"

// render the app to a bundle, we use the app from the push pull test above.
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "a-simple-app:1.0.0")
cmd.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "--tag", "a-simple-app:1.0.0")
icmd.RunCmd(cmd).Assert(t, icmd.Success)

// push it and install to check it is available
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestPushInstallBundle(t *testing.T) {
cmdIsolatedStore.Env = append(cmdIsolatedStore.Env, "DOCKER_CONTEXT=swarm-context")

// bundle the app again but this time with a tag to store it into the bundle store
cmdIsolatedStore.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), ref2)
cmdIsolatedStore.Command = dockerCli.Command("app", "build", filepath.Join("testdata", "push-pull", "push-pull.dockerapp"), "--tag", ref2)
icmd.RunCmd(cmdIsolatedStore).Assert(t, icmd.Success)
// Push the app without tagging it explicitly
cmdIsolatedStore.Command = dockerCli.Command("app", "push", ref2)
Expand Down
24 changes: 0 additions & 24 deletions examples/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions examples/cnab-helm/LICENSE

This file was deleted.

47 changes: 0 additions & 47 deletions examples/cnab-helm/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions examples/cnab-helm/bundle.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/cnab-helm/cnab/Dockerfile

This file was deleted.

27 changes: 0 additions & 27 deletions examples/cnab-helm/cnab/app/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions examples/cnab-helm/cnab/app/charts/alpine/Chart.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/cnab-helm/cnab/app/charts/alpine/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions examples/cnab-helm/cnab/app/charts/alpine/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions examples/cnab-helm/cnab/app/charts/alpine/templates/_helpers.tpl

This file was deleted.

0 comments on commit 9a97b79

Please sign in to comment.