-
Notifications
You must be signed in to change notification settings - Fork 61
Enable blob caching and blobInfo caching #34
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
Changes from all commits
6a11dbe
027999d
bbab78b
fdc34e5
94e4ded
60fc859
1c03321
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ import ( | |
| "github.com/containers/buildah/imagebuildah" | ||
| "github.com/containers/buildah/util" | ||
| "github.com/containers/image/pkg/docker/config" | ||
| "github.com/containers/image/pkg/sysregistriesv2" | ||
| "github.com/containers/image/transports/alltransports" | ||
| "github.com/containers/image/types" | ||
| "github.com/containers/storage" | ||
|
|
@@ -29,7 +28,7 @@ import ( | |
| "github.com/openshift/library-go/pkg/image/reference" | ||
| ) | ||
|
|
||
| func pullDaemonlessImage(sc types.SystemContext, store storage.Store, imageName string, authConfig docker.AuthConfiguration) error { | ||
| func pullDaemonlessImage(sc types.SystemContext, store storage.Store, imageName string, authConfig docker.AuthConfiguration, blobCacheDirectory string) error { | ||
| glog.V(2).Infof("Asked to pull fresh copy of %q.", imageName) | ||
|
|
||
| if imageName == "" { | ||
|
|
@@ -47,11 +46,6 @@ func pullDaemonlessImage(sc types.SystemContext, store storage.Store, imageName | |
| // } | ||
| systemContext.AuthFilePath = "/tmp/config.json" | ||
|
|
||
| registries, err := sysregistriesv2.GetRegistries(&systemContext) | ||
| if err != nil { | ||
| return fmt.Errorf("error reading system registries configuration: %v", err) | ||
| } | ||
|
|
||
| ref, err := reference.Parse(imageName) | ||
| if err != nil { | ||
| return fmt.Errorf("error parsing image name %s: %v", ref, err) | ||
|
|
@@ -68,28 +62,17 @@ func pullDaemonlessImage(sc types.SystemContext, store storage.Store, imageName | |
| } | ||
| } | ||
|
|
||
| if registry := sysregistriesv2.FindRegistry(imageName, registries); registry != nil { | ||
| if registry.Insecure { | ||
| glog.V(2).Infof("Registry %q is marked as insecure in the registries configuration.", registry.URL) | ||
| systemContext.DockerInsecureSkipTLSVerify = true | ||
| systemContext.OCIInsecureSkipTLSVerify = true | ||
| } else { | ||
| glog.V(2).Infof("Registry %q is marked as secure in the registries configuration.", registry.URL) | ||
| } | ||
| } else { | ||
| glog.V(2).Infof("Registry for %q is not present in the registries configuration, assuming it is secure.", imageName) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the designation of secure/insecure registries will be taken care of by copying in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nalind did something get fixed in buildah that we don't need this any more?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, containers/image#468 was merged.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adambkaplan Yup, the way the builder expects the configuration to be provided to it hasn't changed, we just don't need to do this bit of work ourselves any more. |
||
| options := buildah.PullOptions{ | ||
| ReportWriter: os.Stderr, | ||
| Store: store, | ||
| SystemContext: &systemContext, | ||
| BlobDirectory: blobCacheDirectory, | ||
| } | ||
| _, err = buildah.Pull(context.TODO(), "docker://"+imageName, options) | ||
| return err | ||
| } | ||
|
|
||
| func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation buildah.Isolation, dir string, optimization buildapiv1.ImageOptimizationPolicy, opts *docker.BuildImageOptions) error { | ||
| func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation buildah.Isolation, contextDir string, optimization buildapiv1.ImageOptimizationPolicy, opts *docker.BuildImageOptions, blobCacheDirectory string) error { | ||
| glog.V(2).Infof("Building...") | ||
|
|
||
| args := make(map[string]string) | ||
|
|
@@ -144,7 +127,7 @@ func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation | |
| } | ||
|
|
||
| options := imagebuildah.BuildOptions{ | ||
| ContextDirectory: dir, | ||
| ContextDirectory: contextDir, | ||
| PullPolicy: pullPolicy, | ||
| Isolation: isolation, | ||
| TransientMounts: transientMounts, | ||
|
|
@@ -167,6 +150,7 @@ func buildDaemonlessImage(sc types.SystemContext, store storage.Store, isolation | |
| NoCache: opts.NoCache, | ||
| RemoveIntermediateCtrs: opts.RmTmpContainer, | ||
| ForceRmIntermediateCtrs: true, | ||
| BlobDirectory: blobCacheDirectory, | ||
| } | ||
|
|
||
| _, _, err := imagebuildah.BuildDockerfiles(opts.Context, store, options, opts.Dockerfile) | ||
|
|
@@ -229,7 +213,7 @@ func removeDaemonlessImage(sc types.SystemContext, store storage.Store, buildTag | |
| return nil | ||
| } | ||
|
|
||
| func pushDaemonlessImage(sc types.SystemContext, store storage.Store, imageName string, authConfig docker.AuthConfiguration) (string, error) { | ||
| func pushDaemonlessImage(sc types.SystemContext, store storage.Store, imageName string, authConfig docker.AuthConfiguration, blobCacheDirectory string) (string, error) { | ||
| glog.V(2).Infof("Pushing image %q from local storage.", imageName) | ||
|
|
||
| if imageName == "" { | ||
|
|
@@ -257,26 +241,12 @@ func pushDaemonlessImage(sc types.SystemContext, store storage.Store, imageName | |
| glog.V(2).Infof("No authentication secret provided for pushing to registry.") | ||
| } | ||
|
|
||
| registries, err := sysregistriesv2.GetRegistries(&systemContext) | ||
| if err != nil { | ||
| return "", fmt.Errorf("error reading system registries configuration: %v", err) | ||
| } | ||
| if registry := sysregistriesv2.FindRegistry(imageName, registries); registry != nil { | ||
| if registry.Insecure { | ||
| glog.V(2).Infof("Registry %q is marked as insecure in the registries configuration.", registry.URL) | ||
| systemContext.DockerInsecureSkipTLSVerify = true | ||
| systemContext.OCIInsecureSkipTLSVerify = true | ||
| } else { | ||
| glog.V(2).Infof("Registry %q is marked as secure in the registries configuration.", registry.URL) | ||
| } | ||
| } else { | ||
| glog.V(2).Infof("Registry for %q is not present in the registries configuration, assuming it is secure.", imageName) | ||
| } | ||
|
|
||
| options := buildah.PushOptions{ | ||
| Compression: archive.Gzip, | ||
| ReportWriter: os.Stdout, | ||
| Store: store, | ||
| SystemContext: &systemContext, | ||
| BlobDirectory: blobCacheDirectory, | ||
| } | ||
|
|
||
| // TODO - do something with the digest | ||
|
|
@@ -369,7 +339,7 @@ func inspectDaemonlessImage(sc types.SystemContext, store storage.Store, name st | |
|
|
||
| // daemonlessRun mimics the 'docker run --rm' CLI command well enough. It creates and | ||
| // starts a container and streams its logs. The container is removed after it terminates. | ||
| func daemonlessRun(ctx context.Context, store storage.Store, isolation buildah.Isolation, createOpts docker.CreateContainerOptions, attachOpts docker.AttachToContainerOptions) error { | ||
| func daemonlessRun(ctx context.Context, store storage.Store, isolation buildah.Isolation, createOpts docker.CreateContainerOptions, attachOpts docker.AttachToContainerOptions, blobCacheDirectory string) error { | ||
| if createOpts.Config == nil { | ||
| return fmt.Errorf("error calling daemonlessRun: expected a Config") | ||
| } | ||
|
|
@@ -385,6 +355,7 @@ func daemonlessRun(ctx context.Context, store storage.Store, isolation buildah.I | |
| MemorySwap: createOpts.HostConfig.MemorySwap, | ||
| CgroupParent: createOpts.HostConfig.CgroupParent, | ||
| }, | ||
| PullBlobDirectory: blobCacheDirectory, | ||
| } | ||
|
|
||
| builder, err := buildah.NewBuilder(ctx, store, builderOptions) | ||
|
|
@@ -454,15 +425,16 @@ func downloadFromDaemonlessContainer(builder *buildah.Builder, id string, path s | |
|
|
||
| // DaemonlessClient is a daemonless DockerClient-like implementation. | ||
| type DaemonlessClient struct { | ||
| SystemContext types.SystemContext | ||
| Store storage.Store | ||
| Isolation buildah.Isolation | ||
| builders map[string]*buildah.Builder | ||
| SystemContext types.SystemContext | ||
| Store storage.Store | ||
| Isolation buildah.Isolation | ||
| BlobCacheDirectory string | ||
| builders map[string]*buildah.Builder | ||
| } | ||
|
|
||
| // GetDaemonlessClient returns a valid implemenatation of the DockerClient | ||
| // interface, or an error if the implementation couldn't be created. | ||
| func GetDaemonlessClient(systemContext types.SystemContext, store storage.Store, isolationSpec string) (client DockerClient, err error) { | ||
| func GetDaemonlessClient(systemContext types.SystemContext, store storage.Store, isolationSpec, blobCacheDirectory string) (client DockerClient, err error) { | ||
| isolation := buildah.IsolationDefault | ||
| switch strings.ToLower(isolationSpec) { | ||
| case "chroot": | ||
|
|
@@ -476,24 +448,29 @@ func GetDaemonlessClient(systemContext types.SystemContext, store storage.Store, | |
| return nil, fmt.Errorf("unrecognized BUILD_ISOLATION setting %q", strings.ToLower(isolationSpec)) | ||
| } | ||
|
|
||
| if blobCacheDirectory != "" { | ||
| glog.V(0).Infof("Caching blobs under %q.", blobCacheDirectory) | ||
| } | ||
|
|
||
| return &DaemonlessClient{ | ||
| SystemContext: systemContext, | ||
| Store: store, | ||
| Isolation: isolation, | ||
| builders: make(map[string]*buildah.Builder), | ||
| SystemContext: systemContext, | ||
| Store: store, | ||
| Isolation: isolation, | ||
| BlobCacheDirectory: blobCacheDirectory, | ||
| builders: make(map[string]*buildah.Builder), | ||
| }, nil | ||
| } | ||
|
|
||
| func (d *DaemonlessClient) BuildImage(opts docker.BuildImageOptions) error { | ||
| return buildDaemonlessImage(d.SystemContext, d.Store, d.Isolation, opts.ContextDir, buildapiv1.ImageOptimizationNone, &opts) | ||
| return buildDaemonlessImage(d.SystemContext, d.Store, d.Isolation, opts.ContextDir, buildapiv1.ImageOptimizationNone, &opts, d.BlobCacheDirectory) | ||
| } | ||
|
|
||
| func (d *DaemonlessClient) PushImage(opts docker.PushImageOptions, auth docker.AuthConfiguration) (string, error) { | ||
| imageName := opts.Name | ||
| if opts.Tag != "" { | ||
| imageName = imageName + ":" + opts.Tag | ||
| } | ||
| return pushDaemonlessImage(d.SystemContext, d.Store, imageName, auth) | ||
| return pushDaemonlessImage(d.SystemContext, d.Store, imageName, auth, d.BlobCacheDirectory) | ||
| } | ||
|
|
||
| func (d *DaemonlessClient) RemoveImage(name string) error { | ||
|
|
@@ -502,8 +479,9 @@ func (d *DaemonlessClient) RemoveImage(name string) error { | |
|
|
||
| func (d *DaemonlessClient) CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error) { | ||
| options := buildah.BuilderOptions{ | ||
| FromImage: opts.Config.Image, | ||
| Container: opts.Name, | ||
| FromImage: opts.Config.Image, | ||
| Container: opts.Name, | ||
| PullBlobDirectory: d.BlobCacheDirectory, | ||
| } | ||
| builder, err := buildah.NewBuilder(opts.Context, d.Store, options) | ||
| if err != nil { | ||
|
|
@@ -556,7 +534,7 @@ func (d *DaemonlessClient) PullImage(opts docker.PullImageOptions, auth docker.A | |
| if opts.Tag != "" { | ||
| imageName = imageName + ":" + opts.Tag | ||
| } | ||
| return pullDaemonlessImage(d.SystemContext, d.Store, imageName, auth) | ||
| return pullDaemonlessImage(d.SystemContext, d.Store, imageName, auth, d.BlobCacheDirectory) | ||
| } | ||
|
|
||
| func (d *DaemonlessClient) TagImage(name string, opts docker.TagImageOptions) error { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.