|
@@ -132,6 +132,23 @@ run [ "$(cat /e)" = "blah" ]
|
|
|
[][2]string{{"/x", "hello"}, {"/", "blah"}},
|
|
|
},
|
|
|
|
|
|
+ // Comments, shebangs, and executability, oh my!
|
|
|
+ {
|
|
|
+ `
|
|
|
+FROM {IMAGE}
|
|
|
+# This is an ordinary comment.
|
|
|
+RUN { echo '#!/bin/sh'; echo 'echo hello world'; } > /hello.sh
|
|
|
+RUN [ ! -x /hello.sh ]
|
|
|
+RUN chmod +x /hello.sh
|
|
|
+RUN [ -x /hello.sh ]
|
|
|
+RUN [ "$(cat /hello.sh)" = $'#!/bin/sh\necho hello world' ]
|
|
|
+RUN [ "$(/hello.sh)" = "hello world" ]
|
|
|
+`,
|
|
|
+ nil,
|
|
|
+ nil,
|
|
|
+ },
|
|
|
+
|
|
|
+ // Environment variable
|
|
|
{
|
|
|
`
|
|
|
from {IMAGE}
|
|
@@ -142,6 +159,19 @@ run [ "$FOO" = "BAR" ]
|
|
|
nil,
|
|
|
},
|
|
|
|
|
|
+ // Environment overwriting
|
|
|
+ {
|
|
|
+ `
|
|
|
+from {IMAGE}
|
|
|
+env FOO BAR
|
|
|
+run [ "$FOO" = "BAR" ]
|
|
|
+env FOO BAZ
|
|
|
+run [ "$FOO" = "BAZ" ]
|
|
|
+`,
|
|
|
+ nil,
|
|
|
+ nil,
|
|
|
+ },
|
|
|
+
|
|
|
{
|
|
|
`
|
|
|
from {IMAGE}
|
|
@@ -391,6 +421,8 @@ func TestBuildEntrypoint(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
if img.Config.Entrypoint[0] != "/bin/echo" {
|
|
|
+ t.Log(img.Config.Entrypoint[0])
|
|
|
+ t.Fail()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -425,7 +457,7 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func checkCacheBehavior(t *testing.T, template testContextTemplate, expectHit bool) {
|
|
|
+func checkCacheBehavior(t *testing.T, template testContextTemplate, expectHit bool) (imageId string) {
|
|
|
eng := NewTestEngine(t)
|
|
|
defer nuke(mkRuntimeFromEngine(eng, t))
|
|
|
|
|
@@ -434,20 +466,36 @@ func checkCacheBehavior(t *testing.T, template testContextTemplate, expectHit bo
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- imageId := img.ID
|
|
|
+ imageId = img.ID
|
|
|
|
|
|
- img = nil
|
|
|
img, err = buildImage(template, t, eng, expectHit)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
}
|
|
|
|
|
|
- hit := imageId == img.ID
|
|
|
- if hit != expectHit {
|
|
|
- t.Logf("Cache misbehavior, got hit=%t, expected hit=%t: (first: %s, second %s)",
|
|
|
- hit, expectHit, imageId, img.ID)
|
|
|
- t.Fail()
|
|
|
+ if hit := imageId == img.ID; hit != expectHit {
|
|
|
+ t.Fatalf("Cache misbehavior, got hit=%t, expected hit=%t: (first: %s, second %s)", hit, expectHit, imageId, img.ID)
|
|
|
}
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func checkCacheBehaviorFromEngime(t *testing.T, template testContextTemplate, expectHit bool, eng *engine.Engine) (imageId string) {
|
|
|
+ img, err := buildImage(template, t, eng, true)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ imageId = img.ID
|
|
|
+
|
|
|
+ img, err = buildImage(template, t, eng, expectHit)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if hit := imageId == img.ID; hit != expectHit {
|
|
|
+ t.Fatalf("Cache misbehavior, got hit=%t, expected hit=%t: (first: %s, second %s)", hit, expectHit, imageId, img.ID)
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func TestBuildImageWithCache(t *testing.T) {
|
|
@@ -474,11 +522,61 @@ func TestBuildADDLocalFileWithCache(t *testing.T) {
|
|
|
maintainer dockerio
|
|
|
run echo "first"
|
|
|
add foo /usr/lib/bla/bar
|
|
|
+ run [ "$(cat /usr/lib/bla/bar)" = "hello" ]
|
|
|
run echo "second"
|
|
|
+ add . /src/
|
|
|
+ run [ "$(cat /src/foo)" = "hello" ]
|
|
|
`,
|
|
|
- [][2]string{{"foo", "hello"}},
|
|
|
+ [][2]string{
|
|
|
+ {"foo", "hello"},
|
|
|
+ },
|
|
|
nil}
|
|
|
- checkCacheBehavior(t, template, true)
|
|
|
+ eng := NewTestEngine(t)
|
|
|
+ defer nuke(mkRuntimeFromEngine(eng, t))
|
|
|
+
|
|
|
+ id1 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ template.files = append(template.files, [2]string{"bar", "hello2"})
|
|
|
+ id2 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id1 == id2 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
+ id3 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id2 != id3 {
|
|
|
+ t.Fatal("The cache should have been used but hasn't.")
|
|
|
+ }
|
|
|
+ template.files[1][1] = "hello3"
|
|
|
+ id4 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id3 == id4 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
+ template.dockerfile += `
|
|
|
+ add ./bar /src2/
|
|
|
+ run ls /src2/bar
|
|
|
+ `
|
|
|
+ id5 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id4 == id5 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
+ template.files[1][1] = "hello4"
|
|
|
+ id6 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id5 == id6 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
+
|
|
|
+ template.dockerfile += `
|
|
|
+ add bar /src2/bar2
|
|
|
+ add /bar /src2/bar3
|
|
|
+ run ls /src2/bar2 /src2/bar3
|
|
|
+ `
|
|
|
+ id7 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id6 == id7 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
+ template.files[1][1] = "hello5"
|
|
|
+ id8 := checkCacheBehaviorFromEngime(t, template, true, eng)
|
|
|
+ if id7 == id8 {
|
|
|
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func TestBuildADDLocalFileWithoutCache(t *testing.T) {
|