-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Feature/contextsources #195
Feature/contextsources #195
Conversation
dc063fe
to
d375cc6
Compare
WDYT about using rclone? |
rclone seems to support a lot but wouldn’t that be a little much stuff to „just“ download and untar a file? In any case we’d probably try to compile it into the executor as kaniko tries to operate on a almost scratch-like container. Edit: If they allow it and MIT license is fine: I think importing the backends and using them for retrieving files would be a working solution. Plus they'd take care of keeping it compatible with the backends. |
98e7415
to
51c4592
Compare
cmd/executor/cmd/root.go
Outdated
if err != nil { | ||
return err | ||
} | ||
ioutil.WriteFile(tarPath, body, 0600) |
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.
As we have a reader and can use this to process the unTar, when moving this to util replace the local storing with direct decompression.
It seems like using rclone would require the user to set up a special config I think it might make sense to create a buildcontext package with a BuildContext interface, which could look like this: type BuildContext interface {
// Gets context.tar.gz from the build context and unpacks to the directory
UnpackTarFromBuildContext(buildContext string, directory string) error
} This would make it easier to add build contexts in the future, similar to how we implemented the Docker commands. Then we could move stuff like this into that package. We could also then get rid of the |
Sounds good, I’ll put the interface into the changes. I just put it all to root to get started so I planned to move the extract anyhow. I’d also propose to move the part figuring out what build module to use to that package as this prefix parser is a little out of context there if we have a buildcontext package. |
Is this ready for another look? |
Feel free to give your input! I’ve been blocked with other things so no changes there from my side I’m afraid. Will continue working on this this week. |
b9de92e
to
569d787
Compare
@priyawadhwa @dlorenc can you have a quick look onto interface and the GC draft? |
31c566c
to
79baa62
Compare
92eed2d
to
58d6bdc
Compare
@@ -110,21 +112,45 @@ func checkDockerfilePath() error { | |||
return errors.New("please provide a valid path to a Dockerfile within the build context") | |||
} | |||
|
|||
// resolveSourceContext unpacks the source context if it is a tar in a GCS bucket | |||
// resolveSourceContext unpacks the source context if it is a tar in a bucket | |||
// it resets srcContext to be the path to the unpacked build context within the image | |||
func resolveSourceContext() error { | |||
if srcContext == "" && bucket == "" { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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 we should keep both flags so that this change is backwards compatible. Let's make sure that either
--context
or --bucket
is specified (and return an error if both or neither are), and pass whichever one is specified into GetBuildContext()
(mentioned below)
Also, if we pass in --bucket
with no prefix, assume a GCS bucket so that it's still backwards compatible :)
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.
Thanks for the updates, I left some comments!
cmd/executor/cmd/root.go
Outdated
buildContextPath := constants.BuildContextDir | ||
if err := util.UnpackTarFromGCSBucket(bucket, buildContextPath); err != nil { | ||
|
||
// if no context is set, add default file context.tar.gz |
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.
Could we move all of this logic into buildcontext.go
? maybe a function like
func GetBuildContext(bucket string) (BuildContext, error)
It could also be nice to create a map in buildcontext.go
to keep track of what prefixes correspond to which BuildContext, and go through the map to figure out which BuildContext to return.
var buildContextMap = map[string]*BuildContext {
"gcs://" : &buildcontext.GCS{},
...
}
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.
Moving it to a function is good. Just unsure what string function to use with a map for prefixes. Will look into that tomorrow.
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 was thinking something like this:
func GetBuildContext(srcContext string) (*BuildContext, error) {
for prefix, bc := range buildContextMap {
if strings.HasPrefix(srcContext, prefix) {
return bc, nil
}
}
return nil, fmt.Error("invalid prefix")
}
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.
When you look for a super fancy solution and it really is as simple as this.
pkg/buildcontext/gc.go
Outdated
import "github.com/GoogleContainerTools/kaniko/pkg/util" | ||
|
||
// BuildContext unifies calls to download and unpack the build context. | ||
type GC struct { |
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: this should probably be GCS instead of GC
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 kops is using gc but I’ll check with the docs and such to make it match
@@ -110,21 +112,45 @@ func checkDockerfilePath() error { | |||
return errors.New("please provide a valid path to a Dockerfile within the build context") | |||
} | |||
|
|||
// resolveSourceContext unpacks the source context if it is a tar in a GCS bucket | |||
// resolveSourceContext unpacks the source context if it is a tar in a bucket | |||
// it resets srcContext to be the path to the unpacked build context within the image | |||
func resolveSourceContext() error { | |||
if srcContext == "" && bucket == "" { |
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 we should keep both flags so that this change is backwards compatible. Let's make sure that either
--context
or --bucket
is specified (and return an error if both or neither are), and pass whichever one is specified into GetBuildContext()
(mentioned below)
Also, if we pass in --bucket
with no prefix, assume a GCS bucket so that it's still backwards compatible :)
cmd/executor/cmd/root.go
Outdated
bucket += "/" + constants.ContextTar | ||
} | ||
|
||
if strings.HasPrefix(bucket, "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.
nit: could we make this dir:// since there may be multiple files in a directory being used as the build context
d762770
to
402f876
Compare
Is this ready for review? |
added fallback if prefix in bucket specifier is present
6c62f2f
to
4931de3
Compare
Let's see! |
Almost forgot to add the s3 prefix for the s3 implementation again... That PR is getting way too big. Should be all stable now! |
Hey @chrisz100, I wanted to refactor this a bit before merging and update the integration tests -- would you mind if I pushed a couple commits? |
@priyawadhwa added you to the repository collaborators list. Feel free :-) |
Thank you! |
d35df1c
to
be5ad45
Compare
lgtm |
Busy times as it seems. @priyawadhwa any update or outlook on getting this merged? |
@chrisz100 thank you so much for your contribution! just merged :) |
Implementing a modular build context retrieval.
This will allow to define various sources, be it file, gs, s3 or any other.
Feel free to review on a commit-basis as this might be a bigger thing and correcting it all at once would be double the effort in the end.