Skip to content
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

Merged

Conversation

chrisz100
Copy link
Contributor

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.

@chrisz100 chrisz100 force-pushed the feature/contextsources branch 3 times, most recently from dc063fe to d375cc6 Compare May 27, 2018 20:42
@AkihiroSuda
Copy link
Contributor

WDYT about using rclone?
It supports Amazon Drive, Amazon S3, Backblaze B2, Box, Ceph, DigitalOcean Spaces, Dreamhost, Dropbox, FTP, Google Cloud Storage, Google Drive, HTTP, Hubic, IBM COS S3, Memset Memstore, Microsoft Azure Blob Storage, Microsoft OneDrive, Minio, Nextloud, OVH, Openstack Swift, Oracle Cloud Storage, OwnCloud, pCloud, put.io, QingStor, Rackspace Cloud Files, SFTP, Wasabi, WebDAV, and Yandex Disk.

@chrisz100
Copy link
Contributor Author

chrisz100 commented May 28, 2018

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.

@chrisz100 chrisz100 force-pushed the feature/contextsources branch 4 times, most recently from 98e7415 to 51c4592 Compare May 28, 2018 12:09
if err != nil {
return err
}
ioutil.WriteFile(tarPath, body, 0600)
Copy link
Contributor Author

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.

@priyawadhwa
Copy link
Collaborator

It seems like using rclone would require the user to set up a special config rclone.conf, which I don't love the idea of.

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 --bucket flag and keep only the --context flag, since GCS buckets would be identified as --context=gcs://bucket-name

@chrisz100
Copy link
Contributor Author

chrisz100 commented May 29, 2018

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.

@dlorenc
Copy link
Collaborator

dlorenc commented Jun 4, 2018

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?

@chrisz100
Copy link
Contributor Author

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.

@chrisz100 chrisz100 force-pushed the feature/contextsources branch 2 times, most recently from b9de92e to 569d787 Compare June 11, 2018 10:20
@chrisz100
Copy link
Contributor Author

@priyawadhwa @dlorenc can you have a quick look onto interface and the GC draft?

@chrisz100 chrisz100 changed the title [WIP] Feature/contextsources Feature/contextsources Jun 11, 2018
@@ -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.

Copy link
Collaborator

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 :)

Copy link
Collaborator

@priyawadhwa priyawadhwa left a 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!

buildContextPath := constants.BuildContextDir
if err := util.UnpackTarFromGCSBucket(bucket, buildContextPath); err != nil {

// if no context is set, add default file context.tar.gz
Copy link
Collaborator

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{},
   ...
}

Copy link
Contributor Author

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.

Copy link
Collaborator

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")
}

Copy link
Contributor Author

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.

import "github.com/GoogleContainerTools/kaniko/pkg/util"

// BuildContext unifies calls to download and unpack the build context.
type GC struct {
Copy link
Collaborator

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

Copy link
Contributor Author

@chrisz100 chrisz100 Jun 12, 2018

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 == "" {
Copy link
Collaborator

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 :)

bucket += "/" + constants.ContextTar
}

if strings.HasPrefix(bucket, "file://") {
Copy link
Collaborator

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

@chrisz100 chrisz100 force-pushed the feature/contextsources branch 2 times, most recently from d762770 to 402f876 Compare June 12, 2018 16:19
@priyawadhwa
Copy link
Collaborator

Is this ready for review?

@chrisz100
Copy link
Contributor Author

Let's see!

@chrisz100
Copy link
Contributor Author

Almost forgot to add the s3 prefix for the s3 implementation again... That PR is getting way too big. Should be all stable now!

@priyawadhwa
Copy link
Collaborator

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?

@chrisz100
Copy link
Contributor Author

chrisz100 commented Jun 27, 2018

@priyawadhwa added you to the repository collaborators list. Feel free :-)

@priyawadhwa
Copy link
Collaborator

Thank you!

@chrisz100
Copy link
Contributor Author

lgtm

@chrisz100
Copy link
Contributor Author

Busy times as it seems. @priyawadhwa any update or outlook on getting this merged?

@priyawadhwa priyawadhwa merged commit 65d7b0a into GoogleContainerTools:master Jul 6, 2018
@priyawadhwa
Copy link
Collaborator

@chrisz100 thank you so much for your contribution! just merged :)

@chrisz100 chrisz100 deleted the feature/contextsources branch July 7, 2018 10:47
@priyawadhwa priyawadhwa mentioned this pull request Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants