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

Commit

Permalink
remove bundle download
Browse files Browse the repository at this point in the history
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
  • Loading branch information
aiordache committed Nov 21, 2019
1 parent f6e4aec commit bf747a1
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 32 deletions.
78 changes: 48 additions & 30 deletions e2e/compatibility_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package e2e

import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
"time"
Expand All @@ -14,56 +16,62 @@ import (
"gotest.tools/fs"
)

func importAndTagImage(info dindSwarmAndRegistryInfo, tmpDir *fs.Dir, tag string, url string) string {
info.localCmd("wget", "-q", "-O", tmpDir.Join("img.tar"), url)
combined := info.dockerCmd("load", "-i", tmpDir.Join("img.tar"))
func getAndTagImage(info dindSwarmAndRegistryInfo, tmpDir *fs.Dir, tag string, url string) (string, error) {

var digest string
err := downloadImageTarball(tmpDir.Join("image.tar"), url)
if err != nil {
return "", err
}
//info.localCmd("wget", "-q", "-O", tmpDir.Join("img.tar"), url)
combined := info.dockerCmd("load", "-i", tmpDir.Join("image.tar"))

digest := ""
for _, line := range strings.Split(combined, "\n") {
if strings.Contains(line, "sha256:") {
digest = strings.Split(line, "sha256:")[1]
}
}
if digest == "" {
return "", errors.New("Image digest not found in docker load's stdout")
}

digest = strings.Trim(digest, " \r\n")
info.dockerCmd("tag", digest, tag)

return "sha256:" + digest
return "sha256:" + digest, nil
}

func getBundle(t *testing.T, url string) []byte {
func downloadImageTarball(filepath string, url string) error {
client := http.Client{Timeout: time.Minute * 1}
res, err := client.Get(url)
assert.NilError(t, err)

body, err := ioutil.ReadAll(res.Body)
assert.NilError(t, err)

return body
}

func createBundle(path string, bundle []byte, invocDigest string, backendDigest string, frontendDigest string) error {
bundle = bytes.ReplaceAll(bundle, []byte("<digest-app-e2e-invoc>"), []byte(invocDigest))
bundle = bytes.ReplaceAll(bundle, []byte("<digest-backend>"), []byte(backendDigest))
bundle = bytes.ReplaceAll(bundle, []byte("<digest-frontend>"), []byte(frontendDigest))

return ioutil.WriteFile(path, bundle, 0644)
if err != nil {
return err
}
defer res.Body.Close()

// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, res.Body)
return err
}

func TestBackwardsCompatibilityV1(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
appName := "app-e2e"
tmpDir := fs.NewDir(t, appName)
defer tmpDir.Remove()

bundleTemplate := getBundle(t, "https://github.com/docker/app-e2e/raw/master/bundles/v0.9.0/bundle.json")
tmpDir := info.tmpDir

invocDigest := importAndTagImage(info, tmpDir, "app-e2e:0.1.0-invoc", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/app-e2e-invoc.tar")
backendDigest := importAndTagImage(info, tmpDir, "app-e2e/backend", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/backend.tar")
frontendDigest := importAndTagImage(info, tmpDir, "app-e2e/frontend", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/frontend.tar")

err := createBundle(tmpDir.Join("bundle.json"), bundleTemplate, invocDigest, backendDigest, frontendDigest)
data, err := ioutil.ReadFile("testdata/compatibility/bundle-v0.9.0.json")
assert.NilError(t, err)
ioutil.WriteFile(tmpDir.Join("bundle.json"), data, os.FileMode(0777))

getAndTagImage(info, tmpDir, "app-e2e:0.1.0-invoc", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/app-e2e-invoc.tar")
getAndTagImage(info, tmpDir, "app-e2e/backend", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/backend.tar")
getAndTagImage(info, tmpDir, "app-e2e/frontend", "https://github.com/docker/app-e2e/raw/master/images/v0.9.0/frontend.tar")

// Install a Docker App built with an older version
output := info.dockerCmd("app", "run", "--cnab-bundle-json", tmpDir.Join("bundle.json"), "--name", appName)
Expand All @@ -85,6 +93,16 @@ func TestBackwardsCompatibilityV1(t *testing.T) {
checkContains(t, output,
[]string{`Hi there, I love Docker!`})

// Inspect app
output = info.dockerCmd("app", "inspect", appName, "--pretty")
checkContains(t, output,
[]string{
"Running App:",
fmt.Sprintf("Name: %s", appName),
"Result: success",
`ports.frontend: "8080"`,
})

// Update the application, changing the port
output = info.dockerCmd("app", "update", appName, "--set", "ports.frontend=8081")
checkContains(t, output,
Expand Down
4 changes: 2 additions & 2 deletions e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type dindSwarmAndRegistryInfo struct {
swarmAddress string
registryAddress string
configuredCmd icmd.Cmd
tmpDir *fs.Dir
stopRegistry func()
registryLogs func() string
dockerCmd func(...string) string
Expand All @@ -44,15 +45,14 @@ func runWithDindSwarmAndRegistry(t *testing.T, todo func(dindSwarmAndRegistryInf
defer tmpDir.Remove()

// Initialize the info struct
runner := dindSwarmAndRegistryInfo{configuredCmd: cmd}
runner := dindSwarmAndRegistryInfo{configuredCmd: cmd, tmpDir: tmpDir}

// Func to execute command locally
runLocalCmd := func(params ...string) string {
if len(params) == 0 {
return ""
}
cmd := icmd.Command(params[0], params[1:]...)
//fmt.Println("Running: $", cmd.Command)
result := icmd.RunCmd(cmd)
result.Assert(t, icmd.Success)
return result.Combined()
Expand Down
183 changes: 183 additions & 0 deletions e2e/testdata/compatibility/bundle-v0.9.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"actions": {
"com.docker.app.inspect": {
"stateless": true
},
"com.docker.app.render": {
"stateless": true
},
"io.cnab.status": {},
"io.cnab.status+json": {}
},
"credentials": {
"com.docker.app.context": {
"path": "/cnab/app/context.dockercontext"
},
"com.docker.app.registry-creds": {
"path": "/cnab/app/registry-creds.json"
}
},
"custom": {
"com.docker.app": {
"payload": {
"created": "2019-11-18T08:22:31.570871111Z"
},
"version": "1.0.0"
}
},
"definitions": {
"com.docker.app.args": {
"default": "",
"description": "Arguments that are passed by file to the invocation image",
"title": "Arguments",
"type": "string"
},
"com.docker.app.inspect-format": {
"default": "json",
"description": "Output format for the inspect command",
"enum": [
"json",
"pretty"
],
"title": "Inspect format",
"type": "string"
},
"com.docker.app.kubernetes-namespace": {
"default": "",
"description": "Namespace in which to deploy",
"title": "Namespace",
"type": "string"
},
"com.docker.app.orchestrator": {
"default": "",
"description": "Orchestrator on which to deploy",
"enum": [
"",
"swarm",
"kubernetes"
],
"title": "Orchestrator",
"type": "string"
},
"com.docker.app.render-format": {
"default": "yaml",
"description": "Output format for the render command",
"enum": [
"yaml",
"json"
],
"title": "Render format",
"type": "string"
},
"com.docker.app.share-registry-creds": {
"default": false,
"description": "Share registry credentials with the invocation image",
"title": "Share registry credentials",
"type": "boolean"
},
"ports.frontend": {
"default": "8080",
"type": "string"
}
},
"description": "sample description",
"images": {
"backend": {
"contentDigest": "<digest-backend>",
"description": "app-e2e/backend",
"image": "app-e2e/backend",
"imageType": "docker",
"size": 7394886
},
"frontend": {
"contentDigest": "<digest-frontend>",
"description": "app-e2e/frontend",
"image": "app-e2e/frontend",
"imageType": "docker",
"size": 21365920
}
},
"invocationImages": [
{
"contentDigest": "<digest-app-e2e-invoc>",
"image": "app-e2e:0.1.0-invoc",
"imageType": "docker",
"size": 47261342
}
],
"maintainers": [
{
"email": "anca.iordache@docker.com",
"name": "Anca Iordache"
}
],
"name": "app-e2e",
"parameters": {
"com.docker.app.args": {
"applyTo": [
"install",
"upgrade"
],
"definition": "com.docker.app.args",
"destination": {
"path": "/cnab/app/args.json"
}
},
"com.docker.app.inspect-format": {
"applyTo": [
"com.docker.app.inspect"
],
"definition": "com.docker.app.inspect-format",
"destination": {
"env": "DOCKER_INSPECT_FORMAT"
}
},
"com.docker.app.kubernetes-namespace": {
"applyTo": [
"install",
"upgrade",
"uninstall",
"io.cnab.status"
],
"definition": "com.docker.app.kubernetes-namespace",
"destination": {
"env": "DOCKER_KUBERNETES_NAMESPACE"
}
},
"com.docker.app.orchestrator": {
"applyTo": [
"install",
"upgrade",
"uninstall",
"io.cnab.status"
],
"definition": "com.docker.app.orchestrator",
"destination": {
"env": "DOCKER_STACK_ORCHESTRATOR"
}
},
"com.docker.app.render-format": {
"applyTo": [
"com.docker.app.render"
],
"definition": "com.docker.app.render-format",
"destination": {
"env": "DOCKER_RENDER_FORMAT"
}
},
"com.docker.app.share-registry-creds": {
"definition": "com.docker.app.share-registry-creds",
"destination": {
"env": "DOCKER_SHARE_REGISTRY_CREDS"
}
},
"ports.frontend": {
"definition": "ports.frontend",
"destination": {
"env": "docker_param1"
}
}
},
"schemaVersion": "v1.0.0",
"version": "0.1.0"
}

0 comments on commit bf747a1

Please sign in to comment.