-
Notifications
You must be signed in to change notification settings - Fork 43
extract RunCacheProbe function #284
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
Conversation
4d002c7
to
a75b84c
Compare
a75b84c
to
3c8066f
Compare
@@ -1137,3 +1407,111 @@ func copyFile(src, dst string) error { | |||
} | |||
return nil | |||
} | |||
|
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: below functions are extracted
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.
curious if we can move them to another unit/file
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.
Yeah we probably should; I'd like to simplify the envbuilder.Run
/ RunCacheProbe
functions as much as possible for future maintenance.
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.
LGTM, mostly small nits and suggestions
Quite a lot of complexity in the RunCacheProbe
function which would be good to decompose later on.
envbuilder.go
Outdated
// Logger is the logf to use for all operations. | ||
// Filesystem is the filesystem to use for all operations. | ||
// Defaults to the host filesystem. |
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.
Were these arguments previous, but you later moved them to options.Options by any chance?
This comment feels potentially stale.
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.
Yep, this is stale 👍
stageNumber := 0 | ||
startStage := func(format string, args ...any) func(format string, args ...any) { | ||
now := time.Now() | ||
stageNumber++ |
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.
Nit: pass in an int pointer instead perhaps?
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.
This is a pre-existing non-pointer integer; I want to refactor this whole stage builder business later on. A little copying for now.
data := make([]byte, 4096) | ||
for { | ||
read, err := reader.Read(data) |
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.
Nit: consider using https://pkg.go.dev/bufio#NewReaderSize with ReadBytes(delim byte)
where delim
is '\r'?
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.
pre-existing; will address in follow-up
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.
+1
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.
Please ignore comments that refer to the original code.
return nil, fmt.Errorf("--cache-repo must be set when using --get-cached-image") | ||
} | ||
|
||
stageNumber := 0 |
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.
nit: stageIndex?
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.
will rename in a follow-up
data := make([]byte, 4096) | ||
for { | ||
read, err := reader.Read(data) |
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.
+1
Insecure: opts.Insecure, | ||
InsecurePull: opts.Insecure, | ||
SkipTLSVerify: opts.Insecure, |
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.
Is it on purpose or is it something we should address in the future?
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.
What is the issue here?
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.
ignoring TLS issues
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.
I think it's intentional here.
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.
synced offline: I assumed incorrectly that it is SkipTLSVerify = true
endStage("🏗️ Found cached image!") | ||
|
||
// Sanitize the environment of any opts! | ||
options.UnsetEnv() |
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.
nit: should run UnsetEnv
in defer?
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.
added at beginning of func
@@ -1137,3 +1407,111 @@ func copyFile(src, dst string) error { | |||
} | |||
return nil | |||
} | |||
|
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.
curious if we can move them to another unit/file
|
||
func initDockerConfigJSON(dockerConfigBase64 string) (func() error, error) { | ||
var cleanupOnce sync.Once | ||
noop := func() error { return nil } |
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.
wouldn't it be more natural to just return nil
and check it before execution?
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.
Returning a noop
function removes the need for the caller to care whether it's nil or not. I much prefer this pattern personally.
return noop, fmt.Errorf("decode docker config: %w", err) | ||
} | ||
var configFile DockerConfig | ||
decoded, err = hujson.Standardize(decoded) |
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.
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.
:D
// Spawn an in-memory registry to cache built layers... | ||
registry := handlers.NewApp(ctx, cfg) | ||
|
||
listener, err := net.Listen("tcp", "127.0.0.1:0") |
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.
nit: no need to expose it outside? I mean, 0.0.0.0:0
for debugging purposes?
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.
I don't recall ever needing to do this; you can always inspect the local dir contents
if opts.CacheRepo != "" { | ||
destinations = append(destinations, opts.CacheRepo) | ||
} | ||
kOpts := &config.KanikoOptions{ |
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.
At some point it would be great to treat Kaniko as strategy pattern, so we can replace it in the future.
Part of coder/internal#11
Builds on top of #282 and #283
Extracts the logic for
--get-cached-image
to a separate functionAlso pulls out some other common logic shared between
Run
andRunCacheProbe
. There is more that could be DRYed up, but leaving this for later.