Skip to content

Commit e64f857

Browse files
authored
fix: update kaniko fork to fix BLOB_UNKNOWN errors (#410)
1 parent 5ded028 commit e64f857

File tree

6 files changed

+63
-7
lines changed

6 files changed

+63
-7
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test-registry-container: .registry-cache
6767

6868
# Pulls images referenced in integration tests and pushes them to the local cache.
6969
.PHONY: test-images-push
70-
test-images-push: .registry-cache/docker/registry/v2/repositories/envbuilder-test-alpine .registry-cache/docker/registry/v2/repositories/envbuilder-test-ubuntu .registry-cache/docker/registry/v2/repositories/envbuilder-test-codercom-code-server
70+
test-images-push: .registry-cache/docker/registry/v2/repositories/envbuilder-test-alpine .registry-cache/docker/registry/v2/repositories/envbuilder-test-ubuntu .registry-cache/docker/registry/v2/repositories/envbuilder-test-codercom-code-server .registry-cache/docker/registry/v2/repositories/envbuilder-test-blob-unknown
7171

7272
.PHONY: test-images-pull
7373
test-images-pull:
@@ -77,6 +77,7 @@ test-images-pull:
7777
docker tag ubuntu:latest localhost:5000/envbuilder-test-ubuntu:latest
7878
docker pull codercom/code-server:latest
7979
docker tag codercom/code-server:latest localhost:5000/envbuilder-test-codercom-code-server:latest
80+
docker build -t localhost:5000/envbuilder-test-blob-unknown:latest -f integration/testdata/blob-unknown/Dockerfile integration/testdata/blob-unknown
8081

8182
.registry-cache:
8283
mkdir -p .registry-cache && chmod -R ag+w .registry-cache
@@ -89,3 +90,6 @@ test-images-pull:
8990

9091
.registry-cache/docker/registry/v2/repositories/envbuilder-test-codercom-code-server:
9192
docker push localhost:5000/envbuilder-test-codercom-code-server:latest
93+
94+
.registry-cache/docker/registry/v2/repositories/envbuilder-test-blob-unknown:
95+
docker push localhost:5000/envbuilder-test-blob-unknown:latest

envbuilder.go

+10
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
583583
endStage("🏗️ Built image!")
584584
if opts.PushImage {
585585
endStage = startStage("🏗️ Pushing image...")
586+
587+
// To debug registry issues, enable logging:
588+
//
589+
// import (
590+
// stdlog "log"
591+
// reglogs "github.com/google/go-containerregistry/pkg/logs"
592+
// )
593+
// reglogs.Debug = stdlog.New(os.Stderr, "", 0)
594+
// reglogs.Warn = stdlog.New(os.Stderr, "", 0)
595+
// reglogs.Progress = stdlog.New(os.Stderr, "", 0)
586596
if err := executor.DoPush(image, kOpts); err == nil {
587597
endStage("🏗️ Pushed image!")
588598
} else if !opts.ExitOnPushFailure {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22.4
44

55
// There are a few options we need added to Kaniko!
66
// See: https://github.com/GoogleContainerTools/kaniko/compare/main...coder:kaniko:main
7-
replace github.com/GoogleContainerTools/kaniko => github.com/coder/kaniko v0.0.0-20241028054616-350cbb820e05
7+
replace github.com/GoogleContainerTools/kaniko => github.com/coder/kaniko v0.0.0-20241120132148-131d6094d781
88

99
// Required to import codersdk due to gvisor dependency.
1010
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20240702054557-aa558fbe5374

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC
171171
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
172172
github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352 h1:L/EjCuZxs5tOcqqCaASj/nu65TRYEFcTt8qRQfHZXX0=
173173
github.com/coder/coder/v2 v2.10.1-0.20240704130443-c2d44d16a352/go.mod h1:P1KoQSgnKEAG6Mnd3YlGzAophty+yKA9VV48LpfNRvo=
174-
github.com/coder/kaniko v0.0.0-20241028054616-350cbb820e05 h1:KZc6vG/WnSWG8RtUevGrCdZbF7XJaaZ32ocig6sZLQk=
175-
github.com/coder/kaniko v0.0.0-20241028054616-350cbb820e05/go.mod h1:3rM/KOQ4LgF8mE+O1P6pLDa/E57mzxIxNdUOMKi1qpg=
174+
github.com/coder/kaniko v0.0.0-20241120132148-131d6094d781 h1:/4SMdrjLQL1BseLSnMd9nYQSI+E63CXcyFGC7ZHHj8I=
175+
github.com/coder/kaniko v0.0.0-20241120132148-131d6094d781/go.mod h1:3rM/KOQ4LgF8mE+O1P6pLDa/E57mzxIxNdUOMKi1qpg=
176176
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
177177
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
178178
github.com/coder/quartz v0.1.0 h1:cLL+0g5l7xTf6ordRnUMMiZtRE8Sq5LxpghS63vEXrQ=

integration/integration_test.go

+38-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ import (
5757
)
5858

5959
const (
60-
testContainerLabel = "envbox-integration-test"
61-
testImageAlpine = "localhost:5000/envbuilder-test-alpine:latest"
62-
testImageUbuntu = "localhost:5000/envbuilder-test-ubuntu:latest"
60+
testContainerLabel = "envbox-integration-test"
61+
testImageAlpine = "localhost:5000/envbuilder-test-alpine:latest"
62+
testImageUbuntu = "localhost:5000/envbuilder-test-ubuntu:latest"
63+
testImageBlobUnknown = "localhost:5000/envbuilder-test-blob-unknown:latest"
6364

6465
// nolint:gosec // Throw-away key for testing. DO NOT REUSE.
6566
testSSHKey = `-----BEGIN OPENSSH PRIVATE KEY-----
@@ -2354,6 +2355,38 @@ USER devalot
23542355
}
23552356
require.Fail(t, "expected pid 1 to be running as devalot")
23562357
})
2358+
2359+
t.Run("PushDuplicateLayersNoBlobUnknown", func(t *testing.T) {
2360+
t.Parallel()
2361+
2362+
srv := gittest.CreateGitServer(t, gittest.Options{
2363+
Files: map[string]string{
2364+
".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s
2365+
USER root
2366+
RUN echo "hi i r empty"
2367+
RUN echo "who u"
2368+
`, testImageBlobUnknown),
2369+
".devcontainer/devcontainer.json": `{
2370+
"name": "Test",
2371+
"build": {
2372+
"dockerfile": "Dockerfile"
2373+
},
2374+
}`,
2375+
},
2376+
})
2377+
2378+
// NOTE(mafredri): The in-memory registry doesn't catch this error so we
2379+
// have to use registry:2.
2380+
ref, err := name.ParseReference(fmt.Sprintf("localhost:5000/test-blob-unknown-%s", uuid.NewString()))
2381+
require.NoError(t, err)
2382+
opts := []string{
2383+
envbuilderEnv("GIT_URL", srv.URL),
2384+
envbuilderEnv("CACHE_REPO", ref.String()),
2385+
envbuilderEnv("VERBOSE", "1"),
2386+
}
2387+
2388+
_ = pushImage(t, ref, nil, opts...)
2389+
})
23572390
}
23582391

23592392
func TestChownHomedir(t *testing.T) {
@@ -2532,6 +2565,8 @@ func getCachedImage(ctx context.Context, t *testing.T, cli *client.Client, env .
25322565
}
25332566

25342567
func startContainerFromRef(ctx context.Context, t *testing.T, cli *client.Client, ref name.Reference) container.CreateResponse {
2568+
t.Helper()
2569+
25352570
// Ensure that we can pull the image.
25362571
rc, err := cli.ImagePull(ctx, ref.String(), image.PullOptions{})
25372572
require.NoError(t, err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:latest
2+
3+
# This will produce an empty layer via Docker. It will allow us to test for a
4+
# conflicting empty layer produced by Kaniko. This is to check against the
5+
# BLOB_UNKNOWN error when trying to upload the built image to a registry and
6+
# Kaniko having overwritten this blob with its own.
7+
WORKDIR /home

0 commit comments

Comments
 (0)