зеркало из https://github.com/microsoft/docker.git
clean up context on build completion & add test
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
Родитель
5f6b420f91
Коммит
1858746978
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/docker/docker/builder/parser"
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/log"
|
||||
"github.com/docker/docker/pkg/tarsum"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
|
@ -163,6 +164,10 @@ func (b *Builder) Run(context io.Reader) (string, error) {
|
|||
return "", fmt.Errorf("No image was generated. Is your Dockerfile empty?\n")
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(b.contextPath); err != nil {
|
||||
log.Debugf("[BUILDER] failed to remove temporary context: %s", err)
|
||||
}
|
||||
|
||||
fmt.Fprintf(b.OutStream, "Successfully built %s\n", utils.TruncateID(b.image))
|
||||
return b.image, nil
|
||||
}
|
||||
|
|
|
@ -706,6 +706,31 @@ func TestBuildEnv(t *testing.T) {
|
|||
logDone("build - env")
|
||||
}
|
||||
|
||||
func TestBuildContextCleanup(t *testing.T) {
|
||||
name := "testbuildcontextcleanup"
|
||||
defer deleteImages(name)
|
||||
entries, err := ioutil.ReadDir("/var/lib/docker/tmp")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
_, err = buildImage(name,
|
||||
`FROM scratch
|
||||
ENTRYPOINT ["/bin/echo"]`,
|
||||
true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entriesFinal, err := ioutil.ReadDir("/var/lib/docker/tmp")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
if err = compareDirectoryEntries(entries, entriesFinal); err != nil {
|
||||
t.Fatalf("context should have been deleted, but wasn't")
|
||||
}
|
||||
|
||||
logDone("build - verify context cleanup works properly")
|
||||
}
|
||||
|
||||
func TestBuildCmd(t *testing.T) {
|
||||
name := "testbuildcmd"
|
||||
expected := "[/bin/echo Hello World]"
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -175,3 +176,20 @@ func waitRun(contId string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
|
||||
var (
|
||||
e1Entries = make(map[string]struct{})
|
||||
e2Entries = make(map[string]struct{})
|
||||
)
|
||||
for _, e := range e1 {
|
||||
e1Entries[e.Name()] = struct{}{}
|
||||
}
|
||||
for _, e := range e2 {
|
||||
e2Entries[e.Name()] = struct{}{}
|
||||
}
|
||||
if !reflect.DeepEqual(e1Entries, e2Entries) {
|
||||
return fmt.Errorf("entries differ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче