Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: push final image to cache repo
This commit enables pushing the final image to the given cache repo.a As
part of #185, the goal is to allow for faster startup when the image has
already been built.
  • Loading branch information
mafredri committed May 17, 2024
commit d53e46af9b45b3eda49665b04b0aa5ceaa8fdb0c
15 changes: 12 additions & 3 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,18 @@ func Run(ctx context.Context, options Options) error {
if val, ok := os.LookupEnv("KANIKO_REGISTRY_MIRROR"); ok {
registryMirror = strings.Split(val, ";")
}
image, err := executor.DoBuild(&config.KanikoOptions{
var destinations []string
if options.CacheRepo != "" {
destinations = append(destinations, options.CacheRepo)
}
opts := &config.KanikoOptions{
// Boilerplate!
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
SnapshotMode: "redo",
RunV2: true,
RunStdout: stdoutWriter,
RunStderr: stderrWriter,
Destinations: []string{"local"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes problems when DoPush is called. I'm not sure what the original intent was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on what the problems are? Are you referring to #185 (comment)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this was simply a bug that was present because DoPush wasn't being used previously. Kaniko expects you to either set it or use --no-push.

error: failed to push to destination local: HEAD https://index.docker.io/v2/library/local/manifests/latest: unexpected status code 401 Unauthorized (HEAD responses have no body, use GET for details)
error: running command "envbuilder": HEAD https://index.docker.io/v2/library/local/manifests/latest: unexpected status code 401 Unauthorized (HEAD responses have no body, use GET for details)
failed to push to destination local

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it optional too? If platform engineers are concerned about envbuilder speed, they can --enable-do-push

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends, do we want to expose multiple knobs, one for caching and one for pushing final image/build optimization, or do we want these to be behind one knob? I'm open to splitting it up but could use some thought. Just because it's two different moments in Kaniko, doesn't mean we have to follow that here.

Destinations: destinations,
CacheRunLayers: true,
CacheCopyLayers: true,
CompressedCaching: true,
Expand Down Expand Up @@ -518,11 +522,16 @@ func Run(ctx context.Context, options Options) error {
RegistryMirrors: registryMirror,
},
SrcContext: buildParams.BuildContext,
})
}
image, err := executor.DoBuild(opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see more debugging/trace logging around this step and DoPush.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the ask is here, I didn't change any of this code so seems out of scope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you add image, err := executor.DoBuild(opts)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just moved opts to a variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed L483. Anyway, I wanted to improve logging around this, but if you think this is useless here, I'm cool with leaving it as is.

if err != nil {
return nil, err
}
if err := executor.DoPush(image, opts); err != nil {
return nil, err
}
endStage("πŸ—οΈ Built image!")

return image, err
}

Expand Down