-
Notifications
You must be signed in to change notification settings - Fork 1
chore: executor: DoCacheProbe: remove fake verbiage #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,16 @@ package executor | |
|
||
import ( | ||
"fmt" | ||
"net/http/httptest" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-containerregistry/pkg/registry" | ||
|
||
"github.com/GoogleContainerTools/kaniko/pkg/config" | ||
"github.com/GoogleContainerTools/kaniko/pkg/constants" | ||
"github.com/GoogleContainerTools/kaniko/testutil" | ||
|
@@ -37,8 +41,7 @@ func TestDoCacheProbe(t *testing.T) { | |
COPY foo/bar.txt copied/ | ||
` | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
// Populate the cache by doing an initial build | ||
cacheDir := t.TempDir() | ||
regCache := setupCacheRegistry(t) | ||
opts := &config.KanikoOptions{ | ||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"), | ||
SrcContext: filepath.Join(testDir, "workspace"), | ||
|
@@ -49,10 +52,10 @@ COPY foo/bar.txt copied/ | |
}, | ||
CacheCopyLayers: true, | ||
CacheRunLayers: true, | ||
CacheRepo: "oci:/" + cacheDir, | ||
CacheRepo: regCache + "/test", | ||
} | ||
_, err := DoCacheProbe(opts) | ||
if err == nil || !strings.Contains(err.Error(), "not supported in fake build") { | ||
if err == nil || !strings.Contains(err.Error(), "uncached command") { | ||
t.Errorf("unexpected error, got %v", err) | ||
} | ||
}) | ||
|
@@ -64,7 +67,7 @@ COPY foo/bar.txt copied/ | |
COPY foo/bar.txt copied/ | ||
` | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
cacheDir := t.TempDir() | ||
regCache := setupCacheRegistry(t) | ||
opts := &config.KanikoOptions{ | ||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"), | ||
SrcContext: filepath.Join(testDir, "workspace"), | ||
|
@@ -75,8 +78,9 @@ COPY foo/bar.txt copied/ | |
}, | ||
CacheCopyLayers: true, | ||
CacheRunLayers: true, | ||
CacheRepo: "oci:/" + cacheDir, | ||
CacheRepo: regCache + "/test", | ||
} | ||
// Populate the cache by doing an initial build | ||
_, err := DoBuild(opts) | ||
testutil.CheckNoError(t, err) | ||
opts.Reproducible = true | ||
|
@@ -91,18 +95,18 @@ COPY foo/bar.txt copied/ | |
COPY foo/bar.txt copied/ | ||
` | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
cacheDir := t.TempDir() | ||
regCache := setupCacheRegistry(t) | ||
opts := &config.KanikoOptions{ | ||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"), | ||
SrcContext: filepath.Join(testDir, "workspace"), | ||
SnapshotMode: constants.SnapshotModeFull, | ||
SnapshotMode: constants.SnapshotModeRedo, | ||
Cache: true, | ||
CacheOptions: config.CacheOptions{ | ||
CacheTTL: time.Hour, | ||
}, | ||
CacheCopyLayers: true, | ||
CacheRunLayers: true, | ||
CacheRepo: "oci:/" + cacheDir, | ||
CacheRepo: regCache + "/test", | ||
} | ||
_, err := DoBuild(opts) | ||
testutil.CheckNoError(t, err) | ||
|
@@ -115,10 +119,61 @@ COPY foo/baz.txt copied/ | |
` | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
_, err = DoCacheProbe(opts) | ||
if err == nil || !strings.Contains(err.Error(), "not supported in fake build") { | ||
if err == nil || !strings.Contains(err.Error(), "uncached command") { | ||
t.Errorf("unexpected error, got %v", err) | ||
} | ||
}) | ||
|
||
t.Run("MultiStage", func(t *testing.T) { | ||
t.Skip("TODO: https://github.com/coder/envbuilder/issues/230") | ||
testDir, fn := setupMultistageTests(t) | ||
defer fn() | ||
dockerFile := ` | ||
FROM scratch as first | ||
COPY foo/bam.txt copied/ | ||
ENV test test | ||
|
||
From scratch as second | ||
COPY --from=first copied/bam.txt output/bam.txt` | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
regCache := setupCacheRegistry(t) | ||
opts := &config.KanikoOptions{ | ||
DockerfilePath: filepath.Join(testDir, "workspace", "Dockerfile"), | ||
SrcContext: filepath.Join(testDir, "workspace"), | ||
SnapshotMode: constants.SnapshotModeRedo, | ||
Cache: true, | ||
CacheOptions: config.CacheOptions{ | ||
CacheTTL: time.Hour, | ||
}, | ||
CacheCopyLayers: true, | ||
CacheRunLayers: true, | ||
CacheRepo: regCache + "/test", | ||
} | ||
_, err := DoBuild(opts) | ||
testutil.CheckNoError(t, err) | ||
os.WriteFile(filepath.Join(testDir, "workspace", "Dockerfile"), []byte(dockerFile), 0755) | ||
opts.Reproducible = true | ||
_, err = DoCacheProbe(opts) | ||
testutil.CheckNoError(t, err) | ||
// Check Image has one layer bam.txt | ||
files, err := readDirectory(filepath.Join(testDir, "output")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
testutil.CheckDeepEqual(t, 1, len(files)) | ||
testutil.CheckDeepEqual(t, files[0].Name(), "bam.txt") | ||
Comment on lines
+127
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this germane to this set of changes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's just a drive-by. I figured I may as well add the test for later since I had it hanging around unstaged. |
||
}) | ||
} | ||
|
||
func setupCacheRegistry(t *testing.T) string { | ||
t.Helper() | ||
tempDir := t.TempDir() | ||
testReg := registry.New(registry.WithBlobHandler(registry.NewDiskBlobHandler(tempDir))) | ||
regSrv := httptest.NewServer(testReg) | ||
t.Cleanup(func() { regSrv.Close() }) | ||
regSrvURL, err := url.Parse(regSrv.URL) | ||
testutil.CheckNoError(t, err) | ||
return fmt.Sprintf("localhost:%s", regSrvURL.Port()) | ||
} | ||
|
||
func setupCacheProbeTests(t *testing.T) (string, func()) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review: I noticed the
oci:/
repo was not actually pushing tocacheDir
so I elected to stand up a temporary registry instad.