Protect images in the integration/ suite
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
4308e881cc
commit
5fa134b906
|
@ -1,22 +1,19 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if ! docker inspect -t image emptyfs &> /dev/null; then
|
if ! docker image inspect emptyfs > /dev/null; then
|
||||||
# let's build a "docker save" tarball for "emptyfs"
|
# build a "docker save" tarball for "emptyfs"
|
||||||
# see https://github.com/docker/docker/pull/5262
|
# see https://github.com/docker/docker/pull/5262
|
||||||
# and also https://github.com/docker/docker/issues/4242
|
# and also https://github.com/docker/docker/issues/4242
|
||||||
dir="$DEST/emptyfs"
|
dir="$DEST/emptyfs"
|
||||||
mkdir -p "$dir"
|
uuid=511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
|
||||||
|
mkdir -p "$dir/$uuid"
|
||||||
(
|
(
|
||||||
cd "$dir"
|
echo '{"emptyfs":{"latest":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"}}' > "$dir/repositories"
|
||||||
echo '{"emptyfs":{"latest":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"}}' > repositories
|
cd "$dir/$uuid"
|
||||||
mkdir -p 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
|
echo '{"id":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158","comment":"Imported from -","created":"2013-06-13T14:03:50.821769-07:00","container_config":{"Hostname":"","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":null},"docker_version":"0.4.0","architecture":"x86_64","Size":0}' > json
|
||||||
(
|
echo '1.0' > VERSION
|
||||||
cd 511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158
|
tar -cf layer.tar --files-from /dev/null
|
||||||
echo '{"id":"511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158","comment":"Imported from -","created":"2013-06-13T14:03:50.821769-07:00","container_config":{"Hostname":"","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":null,"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"OnBuild":null},"docker_version":"0.4.0","architecture":"x86_64","Size":0}' > json
|
|
||||||
echo '1.0' > VERSION
|
|
||||||
tar -cf layer.tar --files-from /dev/null
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
[ -n "$TESTDEBUG" ] && set -x
|
[ -n "$TESTDEBUG" ] && set -x
|
||||||
|
|
|
@ -5,3 +5,5 @@ bundle .integration-daemon-setup
|
||||||
|
|
||||||
export ABS_DEST
|
export ABS_DEST
|
||||||
bash +e
|
bash +e
|
||||||
|
|
||||||
|
bundle .integration-daemon-stop
|
||||||
|
|
|
@ -4,10 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -72,17 +70,7 @@ func TestMain(m *testing.M) {
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
cli.EnsureTestEnvIsLoaded(t)
|
cli.EnsureTestEnvIsLoaded(t)
|
||||||
fakestorage.EnsureTestEnvIsLoaded(t)
|
fakestorage.EnsureTestEnvIsLoaded(t)
|
||||||
cmd := exec.Command(dockerBinary, "images", "-f", "dangling=false", "--format", "{{.Repository}}:{{.Tag}}")
|
environment.ProtectImages(t, testEnv)
|
||||||
cmd.Env = appendBaseEnv(true)
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("err=%v\nout=%s\n", err, out))
|
|
||||||
}
|
|
||||||
images := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
||||||
testEnv.ProtectImage(t, images...)
|
|
||||||
if testEnv.DaemonPlatform() == "linux" {
|
|
||||||
ensureFrozenImagesLinux(t)
|
|
||||||
}
|
|
||||||
check.TestingT(t)
|
check.TestingT(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
package environment
|
package environment
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/integration-cli/fixtures/load"
|
||||||
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
||||||
|
)
|
||||||
|
|
||||||
|
type protectedElements struct {
|
||||||
|
images map[string]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
// ProtectImage adds the specified image(s) to be protected in case of clean
|
// ProtectImage adds the specified image(s) to be protected in case of clean
|
||||||
func (e *Execution) ProtectImage(t testingT, images ...string) {
|
func (e *Execution) ProtectImage(t testingT, images ...string) {
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
|
@ -7,6 +18,31 @@ func (e *Execution) ProtectImage(t testingT, images ...string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type protectedElements struct {
|
// ProtectImages protects existing images and on linux frozen images from being
|
||||||
images map[string]struct{}
|
// cleaned up at the end of test runs
|
||||||
|
func ProtectImages(t testingT, testEnv *Execution) {
|
||||||
|
images := getExistingImages(t, testEnv)
|
||||||
|
|
||||||
|
if testEnv.DaemonPlatform() == "linux" {
|
||||||
|
images = append(images, ensureFrozenImagesLinux(t, testEnv)...)
|
||||||
|
}
|
||||||
|
testEnv.ProtectImage(t, images...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getExistingImages(t testingT, testEnv *Execution) []string {
|
||||||
|
// TODO: use API instead of cli
|
||||||
|
result := icmd.RunCommand(testEnv.dockerBinary, "images", "-f", "dangling=false", "--format", "{{.Repository}}:{{.Tag}}")
|
||||||
|
result.Assert(t, icmd.Success)
|
||||||
|
return strings.Split(strings.TrimSpace(result.Stdout()), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ensureFrozenImagesLinux(t testingT, testEnv *Execution) []string {
|
||||||
|
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
||||||
|
err := load.FrozenImagesLinux(testEnv.DockerBinary(), images...)
|
||||||
|
if err != nil {
|
||||||
|
result := icmd.RunCommand(testEnv.DockerBinary(), "image", "ls")
|
||||||
|
t.Logf(result.String())
|
||||||
|
t.Fatalf("%+v", err)
|
||||||
|
}
|
||||||
|
return images
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,6 @@ type logT interface {
|
||||||
Logf(string, ...interface{})
|
Logf(string, ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureFrozenImagesLinux(t testingT) {
|
|
||||||
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
|
||||||
err := load.FrozenImagesLinux(dockerBinary, images...)
|
|
||||||
if err != nil {
|
|
||||||
t.Logf(dockerCmdWithError("images"))
|
|
||||||
t.Fatalf("%+v", err)
|
|
||||||
}
|
|
||||||
defer testEnv.ProtectImage(t, images...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ensureSyscallTestOnce sync.Once
|
var ensureSyscallTestOnce sync.Once
|
||||||
|
|
||||||
func ensureSyscallTest(c *check.C) {
|
func ensureSyscallTest(c *check.C) {
|
||||||
|
|
|
@ -2,43 +2,14 @@ package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/docker/docker/integration-cli/environment"
|
|
||||||
"github.com/docker/docker/integration-cli/fixtures/load"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
testEnv *environment.Execution
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
var err error
|
|
||||||
testEnv, err = environment.New()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if testEnv.LocalDaemon() {
|
|
||||||
fmt.Println("INFO: Testing against a local daemon")
|
|
||||||
} else {
|
|
||||||
fmt.Println("INFO: Testing against a remote daemon")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: ensure and protect images
|
|
||||||
res := m.Run()
|
|
||||||
os.Exit(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAPICreateWithNotExistImage(t *testing.T) {
|
func TestAPICreateWithNotExistImage(t *testing.T) {
|
||||||
defer setupTest(t)()
|
defer setupTest(t)()
|
||||||
clt := createClient(t)
|
clt := createClient(t)
|
||||||
|
@ -119,23 +90,3 @@ func TestAPICreateEmptyEnv(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createClient(t *testing.T) client.APIClient {
|
|
||||||
clt, err := client.NewEnvClient()
|
|
||||||
require.NoError(t, err)
|
|
||||||
return clt
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupTest(t *testing.T) func() {
|
|
||||||
if testEnv.DaemonPlatform() == "linux" {
|
|
||||||
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
|
||||||
err := load.FrozenImagesLinux(testEnv.DockerBinary(), images...)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%+v", err)
|
|
||||||
}
|
|
||||||
defer testEnv.ProtectImage(t, images...)
|
|
||||||
}
|
|
||||||
return func() {
|
|
||||||
testEnv.Clean(t, testEnv.DockerBinary())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/integration-cli/environment"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
testEnv *environment.Execution
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
var err error
|
||||||
|
testEnv, err = environment.New()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: replace this with `testEnv.Print()` to print the full env
|
||||||
|
if testEnv.LocalDaemon() {
|
||||||
|
fmt.Println("INFO: Testing against a local daemon")
|
||||||
|
} else {
|
||||||
|
fmt.Println("INFO: Testing against a remote daemon")
|
||||||
|
}
|
||||||
|
|
||||||
|
res := m.Run()
|
||||||
|
os.Exit(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createClient(t *testing.T) client.APIClient {
|
||||||
|
clt, err := client.NewEnvClient()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return clt
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupTest(t *testing.T) func() {
|
||||||
|
environment.ProtectImages(t, testEnv)
|
||||||
|
return func() { testEnv.Clean(t, testEnv.DockerBinary()) }
|
||||||
|
}
|
Loading…
Reference in New Issue