本文整理汇总了Golang中github.com/docker/docker/pkg/archive.TarWithOptions函数的典型用法代码示例。如果您正苦于以下问题:Golang TarWithOptions函数的具体用法?Golang TarWithOptions怎么用?Golang TarWithOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TarWithOptions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BuildImage
func (b *DockerBuilder) BuildImage(build *Build, stream *streams.Output) error {
repoPath := fmt.Sprintf("%s/%s", b.cachePath, build.RepositoryName)
repo, err := findOrClone(repoPath, build.CloneURL)
if err != nil {
return err
}
remote, err := repo.LookupRemote("origin")
if err != nil {
return err
}
refSpecs, err := remote.FetchRefspecs()
handleError(err)
err = remote.Fetch(refSpecs, nil, "")
if err != nil {
return err
}
oid, err := git.NewOid(build.CommitID)
if err != nil {
return err
}
commit, err := repo.LookupCommit(oid)
handleError(err)
tree, err := commit.Tree()
handleError(err)
err = repo.CheckoutTree(tree, &git.CheckoutOpts{Strategy: git.CheckoutForce})
handleError(err)
err = repo.SetHeadDetached(oid, nil, "")
handleError(err)
build.ImageTag = build.CommitID[:7]
options := &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{".git"},
IncludeFiles: []string{"."},
}
context, err := archive.TarWithOptions(repoPath, options)
name := fmt.Sprintf("%s/%s:%s", b.registryURL, build.RepositoryName, build.ImageTag)
err = b.dockerClient.BuildImage(docker.BuildImageOptions{
Dockerfile: "Dockerfile",
Name: name,
OutputStream: stream,
InputStream: context,
})
if err != nil {
return err
}
err = b.dockerClient.TagImage(name, docker.TagImageOptions{
Repo: fmt.Sprintf("%s/%s", b.registryURL, build.RepositoryName),
Tag: "latest",
Force: true,
})
return err
}
示例2: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{".wh..wh.*"},
})
}
示例3: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{archive.WhiteoutMetaPrefix + "*", "!" + archive.WhiteoutOpaqueDir},
})
}
示例4: Export
func (v *Volume) Export(resource, name string) (io.ReadCloser, error) {
if v.IsBindMount && filepath.Base(resource) == name {
name = ""
}
basePath, err := v.getResourcePath(resource)
if err != nil {
return nil, err
}
stat, err := os.Stat(basePath)
if err != nil {
return nil, err
}
var filter []string
if !stat.IsDir() {
d, f := path.Split(basePath)
basePath = d
filter = []string{f}
} else {
filter = []string{path.Base(basePath)}
basePath = path.Dir(basePath)
}
return archive.TarWithOptions(basePath, &archive.TarOptions{
Compression: archive.Uncompressed,
Name: name,
Includes: filter,
})
}
示例5: Copy
func (container *Container) Copy(resource string) (io.ReadCloser, error) {
container.Lock()
defer container.Unlock()
var err error
if err := container.Mount(); err != nil {
return nil, err
}
defer func() {
if err != nil {
// unmount any volumes
container.UnmountVolumes(true)
// unmount the container's rootfs
container.Unmount()
}
}()
mounts, err := container.setupMounts()
if err != nil {
return nil, err
}
for _, m := range mounts {
dest, err := container.GetResourcePath(m.Destination)
if err != nil {
return nil, err
}
if err := mount.Mount(m.Source, dest, "bind", "rbind,ro"); err != nil {
return nil, err
}
}
basePath, err := container.GetResourcePath(resource)
if err != nil {
return nil, err
}
stat, err := os.Stat(basePath)
if err != nil {
return nil, err
}
var filter []string
if !stat.IsDir() {
d, f := filepath.Split(basePath)
basePath = d
filter = []string{f}
} else {
filter = []string{filepath.Base(basePath)}
basePath = filepath.Dir(basePath)
}
archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{
Compression: archive.Uncompressed,
IncludeFiles: filter,
})
if err != nil {
return nil, err
}
return ioutils.NewReadCloserWrapper(archive, func() error {
err := archive.Close()
container.UnmountVolumes(true)
container.Unmount()
return err
}),
nil
}
示例6: Copy
func (container *Container) Copy(resource string) (io.ReadCloser, error) {
if err := container.Mount(); err != nil {
return nil, err
}
basePath, err := container.getResourcePath(resource)
if err != nil {
container.Unmount()
return nil, err
}
// Check if this is actually in a volume
for _, mnt := range container.VolumeMounts() {
if len(mnt.MountToPath) > 0 && strings.HasPrefix(resource, mnt.MountToPath[1:]) {
return mnt.Export(resource)
}
}
// Check if this is a special one (resolv.conf, hostname, ..)
if resource == "etc/resolv.conf" {
basePath = container.ResolvConfPath
}
if resource == "etc/hostname" {
basePath = container.HostnamePath
}
if resource == "etc/hosts" {
basePath = container.HostsPath
}
stat, err := os.Stat(basePath)
if err != nil {
container.Unmount()
return nil, err
}
var filter []string
if !stat.IsDir() {
d, f := path.Split(basePath)
basePath = d
filter = []string{f}
} else {
filter = []string{path.Base(basePath)}
basePath = path.Dir(basePath)
}
archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{
Compression: archive.Uncompressed,
IncludeFiles: filter,
})
if err != nil {
container.Unmount()
return nil, err
}
return ioutils.NewReadCloserWrapper(archive, func() error {
err := archive.Close()
container.Unmount()
return err
}),
nil
}
示例7: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (a *Driver) Diff(id, parent string, options *archive.ChangeOptions) (archive.Archive, error) {
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,
Includes: options.Includes,
Excludes: options.Excludes,
})
}
示例8: Copy
func (container *Container) Copy(resource string) (io.ReadCloser, error) {
container.Lock()
defer container.Unlock()
var err error
if err := container.Mount(); err != nil {
return nil, err
}
defer func() {
if err != nil {
container.Unmount()
}
}()
if err = container.mountVolumes(); err != nil {
container.unmountVolumes()
return nil, err
}
defer func() {
if err != nil {
container.unmountVolumes()
}
}()
basePath, err := container.GetResourcePath(resource)
if err != nil {
return nil, err
}
stat, err := os.Stat(basePath)
if err != nil {
return nil, err
}
var filter []string
if !stat.IsDir() {
d, f := path.Split(basePath)
basePath = d
filter = []string{f}
} else {
filter = []string{path.Base(basePath)}
basePath = path.Dir(basePath)
}
archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{
Compression: archive.Uncompressed,
IncludeFiles: filter,
})
if err != nil {
return nil, err
}
return ioutils.NewReadCloserWrapper(archive, func() error {
err := archive.Close()
container.unmountVolumes()
container.Unmount()
return err
}),
nil
}
示例9: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (d *Driver) Diff(id, parent string) (archive.Archive, error) {
diffPath := d.getDiffPath(id)
logrus.Debugf("Tar with options on %s", diffPath)
return archive.TarWithOptions(diffPath, &archive.TarOptions{
Compression: archive.Uncompressed,
UIDMaps: d.uidMaps,
GIDMaps: d.gidMaps,
WhiteoutFormat: archive.OverlayWhiteoutFormat,
})
}
示例10: TarStream
func (c *aufs) TarStream(id, parent string) (io.ReadCloser, error) {
path, _, err := c.Mount(id)
if err != nil {
return nil, err
}
return archive.TarWithOptions(path, &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{archive.WhiteoutMetaPrefix + "*", "!" + archive.WhiteoutOpaqueDir},
})
}
示例11: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (a *Driver) Diff(id, parent string) (io.ReadCloser, error) {
if !a.isParent(id, parent) {
return a.naiveDiff.Diff(id, parent)
}
// AUFS doesn't need the parent layer to produce a diff.
return archive.TarWithOptions(path.Join(a.rootPath(), "diff", id), &archive.TarOptions{
Compression: archive.Uncompressed,
ExcludePatterns: []string{archive.WhiteoutMetaPrefix + "*", "!" + archive.WhiteoutOpaqueDir},
UIDMaps: a.uidMaps,
GIDMaps: a.gidMaps,
})
}
示例12: do_export
func do_export(ctx *context, ctrl *ext.Controller) bool {
r := ctrl.Request
if r.MethodToLower() != "get" {
ctrl.JsonError(http.StatusMethodNotAllowed, errors.New("method not allowed"))
return true
}
directory := path.Join(ctx.app.Options.Root, r.TrimSuffixURI(".export"))
var tarOpt archive.TarOptions
tarOpt.ExcludePatterns = append(tarOpt.ExcludePatterns,
".tmp", ".h2object", "h2object.pid", "h2object.conf")
tarOpt.Compression = archive.Gzip
rd, err := archive.TarWithOptions(directory, &tarOpt)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
defer rd.Close()
_, fname := path.Split(r.TrimSuffixURI(".export"))
if fname == "" {
fname = "h2object"
}
fname = fname + ".tar.gz"
fn := path.Join(ctx.app.Options.TempRoot, fname)
fd, err := os.Create(fn)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
if _, err := io.Copy(fd, rd); err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
fd.Close()
fout, err := os.Open(fn)
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
fstat, err := fout.Stat()
if err != nil {
ctrl.JsonError(http.StatusInternalServerError, err)
return true
}
ctrl.Binary(fname, fout, fstat.Size())
return true
}
示例13: Diff
// Diff produces an archive of the changes between the specified
// layer and its parent layer which may be "".
func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) {
if !d.isParent(id, parent) {
return d.naiveDiff.Diff(id, parent)
}
diffPath := d.getDiffPath(id)
logrus.Debugf("Tar with options on %s", diffPath)
return archive.TarWithOptions(diffPath, &archive.TarOptions{
Compression: archive.Uncompressed,
UIDMaps: d.uidMaps,
GIDMaps: d.gidMaps,
WhiteoutFormat: archive.OverlayWhiteoutFormat,
})
}
示例14: Compress
func (c *tarArchiver) Compress(dirPath string) (io.ReadCloser, error) {
excludePatterns, err := parseExcludePatternsFiles(dirPath, c.opts.ExcludePatternsFiles)
if err != nil {
return nil, err
}
return archive.TarWithOptions(
dirPath,
&archive.TarOptions{
IncludeFiles: []string{"."},
ExcludePatterns: excludePatterns,
Compression: archive.Uncompressed,
NoLchown: true,
},
)
}
示例15: createTarStream
func createTarStream(srcPath string) (io.ReadCloser, error) {
excludes, err := parseDockerignore(srcPath)
if err != nil {
return nil, err
}
if err := validateContextDirectory(srcPath, excludes); err != nil {
return nil, err
}
tarOpts := &archive.TarOptions{
Excludes: excludes,
Compression: archive.Uncompressed,
NoLchown: true,
}
return archive.TarWithOptions(srcPath, tarOpts)
}