mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #7608 from LK4D4/remove_internet_dep
Remove internet dependency from TestBuildCacheADD
This commit is contained in:
commit
d4c2d0c57f
4 changed files with 34 additions and 33 deletions
|
@ -1,2 +0,0 @@
|
||||||
FROM busybox
|
|
||||||
ADD https://index.docker.io/robots.txt /
|
|
|
@ -1,2 +0,0 @@
|
||||||
FROM busybox
|
|
||||||
ADD http://example.com/index.html /
|
|
|
@ -15,38 +15,34 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildCacheADD(t *testing.T) {
|
func TestBuildCacheADD(t *testing.T) {
|
||||||
var (
|
name := "testbuildtwoimageswithadd"
|
||||||
exitCode int
|
defer deleteImages(name)
|
||||||
out string
|
server, err := fakeStorage(map[string]string{
|
||||||
err error
|
"robots.txt": "hello",
|
||||||
)
|
"index.html": "world",
|
||||||
{
|
})
|
||||||
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1")
|
if err != nil {
|
||||||
out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd1", ".")
|
t.Fatal(err)
|
||||||
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
|
||||||
|
|
||||||
if err != nil || exitCode != 0 {
|
|
||||||
t.Fatal("failed to build the image")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
defer server.Close()
|
||||||
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2")
|
if _, err := buildImage(name,
|
||||||
out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd2", ".")
|
fmt.Sprintf(`FROM scratch
|
||||||
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
|
ADD %s/robots.txt /`, server.URL),
|
||||||
|
true); err != nil {
|
||||||
if err != nil || exitCode != 0 {
|
t.Fatal(err)
|
||||||
t.Fatal("failed to build the image")
|
}
|
||||||
}
|
out, _, err := buildImageWithOut(name,
|
||||||
|
fmt.Sprintf(`FROM scratch
|
||||||
|
ADD %s/index.html /`, server.URL),
|
||||||
|
true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(out, "Using cache") {
|
if strings.Contains(out, "Using cache") {
|
||||||
t.Fatal("2nd build used cache on ADD, it shouldn't")
|
t.Fatal("2nd build used cache on ADD, it shouldn't")
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteImages("testcacheadd1")
|
logDone("build - build two images with remote ADD")
|
||||||
deleteImages("testcacheadd2")
|
|
||||||
|
|
||||||
logDone("build - build two images with ADD")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildSixtySteps(t *testing.T) {
|
func TestBuildSixtySteps(t *testing.T) {
|
||||||
|
|
|
@ -240,7 +240,7 @@ func getIDByName(name string) (string, error) {
|
||||||
return inspectField(name, "Id")
|
return inspectField(name, "Id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildImage(name, dockerfile string, useCache bool) (string, error) {
|
func buildImageWithOut(name, dockerfile string, useCache bool) (string, string, error) {
|
||||||
args := []string{"build", "-t", name}
|
args := []string{"build", "-t", name}
|
||||||
if !useCache {
|
if !useCache {
|
||||||
args = append(args, "--no-cache")
|
args = append(args, "--no-cache")
|
||||||
|
@ -250,9 +250,18 @@ func buildImage(name, dockerfile string, useCache bool) (string, error) {
|
||||||
buildCmd.Stdin = strings.NewReader(dockerfile)
|
buildCmd.Stdin = strings.NewReader(dockerfile)
|
||||||
out, exitCode, err := runCommandWithOutput(buildCmd)
|
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||||
if err != nil || exitCode != 0 {
|
if err != nil || exitCode != 0 {
|
||||||
return "", fmt.Errorf("failed to build the image: %s", out)
|
return "", out, fmt.Errorf("failed to build the image: %s", out)
|
||||||
}
|
}
|
||||||
return getIDByName(name)
|
id, err := getIDByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return "", out, err
|
||||||
|
}
|
||||||
|
return id, out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildImage(name, dockerfile string, useCache bool) (string, error) {
|
||||||
|
id, _, err := buildImageWithOut(name, dockerfile, useCache)
|
||||||
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildImageFromContext(name string, ctx *FakeContext, useCache bool) (string, error) {
|
func buildImageFromContext(name string, ctx *FakeContext, useCache bool) (string, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue