From 6041bfb6d8ca7311d115a03c1cd4ce2a49853617 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 17 Jul 2024 13:08:00 +0000 Subject: [PATCH] chore: update kaniko fork for better cache probing --- go.mod | 2 +- go.sum | 4 +-- integration/integration_test.go | 58 ++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 5a56db96..fb9a0496 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.4 // There are a few options we need added to Kaniko! // See: https://github.com/GoogleContainerTools/kaniko/compare/main...coder:kaniko:main -replace github.com/GoogleContainerTools/kaniko => github.com/coder/kaniko v0.0.0-20240624091120-7208a49f5b15 +replace github.com/GoogleContainerTools/kaniko => github.com/coder/kaniko v0.0.0-20240717115058-0ba2908ca4d3 // Required to import codersdk due to gvisor dependency. replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20240702054557-aa558fbe5374 diff --git a/go.sum b/go.sum index 8a431485..3a91b326 100644 --- a/go.sum +++ b/go.sum @@ -171,8 +171,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352 h1:L/EjCuZxs5tOcqqCaASj/nu65TRYEFcTt8qRQfHZXX0= github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352/go.mod h1:P1KoQSgnKEAG6Mnd3YlGzAophty+yKA9VV48LpfNRvo= -github.com/coder/kaniko v0.0.0-20240624091120-7208a49f5b15 h1:Rne2frxrqtLEQ/v4f/wS550Yp/WXLCRFzDuxg8b9woM= -github.com/coder/kaniko v0.0.0-20240624091120-7208a49f5b15/go.mod h1:YMK7BlxerzLlMwihGxNWUaFoN9LXCij4P+w/8/fNlcM= +github.com/coder/kaniko v0.0.0-20240717115058-0ba2908ca4d3 h1:Q7L6cjKfw3DIyhKIcgCJEmgxnUTBajmMDrHxXvxgBZs= +github.com/coder/kaniko v0.0.0-20240717115058-0ba2908ca4d3/go.mod h1:YMK7BlxerzLlMwihGxNWUaFoN9LXCij4P+w/8/fNlcM= github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs= github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc= github.com/coder/quartz v0.1.0 h1:cLL+0g5l7xTf6ordRnUMMiZtRE8Sq5LxpghS63vEXrQ= diff --git a/integration/integration_test.go b/integration/integration_test.go index ae7047c0..29723573 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -1065,7 +1065,13 @@ func TestPushImage(t *testing.T) { srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": { @@ -1089,7 +1095,7 @@ func TestPushImage(t *testing.T) { envbuilderEnv("CACHE_REPO", testRepo), envbuilderEnv("GET_CACHED_IMAGE", "1"), }}) - require.ErrorContains(t, err, "error probing build cache: uncached command") + require.ErrorContains(t, err, "error probing build cache: uncached RUN command") // Then: it should fail to build the image and nothing should be pushed _, err = remote.Image(ref) require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") @@ -1119,7 +1125,13 @@ func TestPushImage(t *testing.T) { srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": { @@ -1143,7 +1155,7 @@ func TestPushImage(t *testing.T) { envbuilderEnv("CACHE_REPO", testRepo), envbuilderEnv("GET_CACHED_IMAGE", "1"), }}) - require.ErrorContains(t, err, "error probing build cache: uncached command") + require.ErrorContains(t, err, "error probing build cache: uncached RUN command") // Then: it should fail to build the image and nothing should be pushed _, err = remote.Image(ref) require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") @@ -1232,7 +1244,13 @@ func TestPushImage(t *testing.T) { srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": { @@ -1270,7 +1288,7 @@ func TestPushImage(t *testing.T) { envbuilderEnv("CACHE_REPO", testRepo), envbuilderEnv("GET_CACHED_IMAGE", "1"), }}) - require.ErrorContains(t, err, "error probing build cache: uncached command") + require.ErrorContains(t, err, "error probing build cache: uncached RUN command") // Then: it should fail to build the image and nothing should be pushed _, err = remote.Image(ref, remoteAuthOpt) require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") @@ -1303,7 +1321,13 @@ func TestPushImage(t *testing.T) { srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": { @@ -1332,7 +1356,7 @@ func TestPushImage(t *testing.T) { envbuilderEnv("CACHE_REPO", testRepo), envbuilderEnv("GET_CACHED_IMAGE", "1"), }}) - require.ErrorContains(t, err, "error probing build cache: uncached command") + require.ErrorContains(t, err, "error probing build cache: uncached RUN command") // Then: it should fail to build the image and nothing should be pushed _, err = remote.Image(ref, remoteAuthOpt) require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") @@ -1386,7 +1410,7 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine), envbuilderEnv("GET_CACHED_IMAGE", "1"), envbuilderEnv("DOCKERFILE_PATH", "Dockerfile"), }}) - require.ErrorContains(t, err, "error probing build cache: uncached command") + require.ErrorContains(t, err, "error probing build cache: uncached RUN command") // Then: it should fail to build the image and nothing should be pushed _, err = remote.Image(ref) require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") @@ -1422,7 +1446,13 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine), srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": { @@ -1448,7 +1478,13 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine), srv := createGitServer(t, gitServerOptions{ files: map[string]string{ - ".devcontainer/Dockerfile": fmt.Sprintf("FROM %s\nRUN date --utc > /root/date.txt", testImageAlpine), + ".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s +USER root +ARG WORKDIR=/ +WORKDIR $WORKDIR +ENV FOO=bar +RUN echo $FOO > /root/foo.txt +RUN date --utc > /root/date.txt`, testImageAlpine), ".devcontainer/devcontainer.json": `{ "name": "Test", "build": {