本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/tar.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UploadToContainerWithCallback
// UploadToContainerWithCallback uploads artifacts to the container.
// If the source is a directory, then all files and sub-folders are copied into
// the destination (which has to be directory as well).
// If the source is a single file, then the file copied into destination (which
// has to be full path to a file inside the container).
// If the destination path is empty or set to ".", then we will try to figure
// out the WORKDIR of the image that the container was created from and use that
// as a destination. If the WORKDIR is not set, then we copy files into "/"
// folder (docker upload default).
func (d *stiDocker) UploadToContainerWithCallback(src, dest, container string, walkFn filepath.WalkFunc, modifyInplace bool) error {
path := filepath.Dir(dest)
f, err := os.Open(src)
if err != nil {
return err
}
info, _ := f.Stat()
defer f.Close()
t := tar.New()
r, w := io.Pipe()
if info.IsDir() {
path = dest
go func() {
defer w.Close()
if err := t.StreamDirAsTarWithCallback(src, w, walkFn, modifyInplace); err != nil {
glog.V(0).Infof("error: Uploading directory to container failed: %v", err)
}
}()
} else {
go func() {
defer w.Close()
if err := t.StreamFileAsTarWithCallback(src, filepath.Base(dest), w, walkFn, modifyInplace); err != nil {
glog.V(0).Infof("error: Uploading files to container failed: %v", err)
}
}()
}
glog.V(3).Infof("Uploading %q to %q ...", src, path)
opts := docker.UploadToContainerOptions{Path: path, InputStream: r}
return d.client.UploadToContainer(container, opts)
}
开发者ID:ncdc,项目名称:origin,代码行数:39,代码来源:docker.go
示例2: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config) (*STI, error) {
docker, err := docker.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
b.source = &git.Clone{b.git, b.fs}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b)
// Set interfaces
b.preparer = b
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:pombredanne,项目名称:atomic-enterprise,代码行数:39,代码来源:sti.go
示例3: NewCmdRsync
// NewCmdRsync creates a new sync command
func NewCmdRsync(name, parent string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
tarHelper := tar.New()
tarHelper.SetExclusionPattern(nil)
o := RsyncOptions{
Out: out,
ErrOut: errOut,
LocalExecutor: &defaultLocalExecutor{},
Tar: tarHelper,
}
cmd := &cobra.Command{
Use: fmt.Sprintf("%s SOURCE_DIR POD:DESTINATION_DIR", name),
Short: "Copy local files to a pod",
Long: rsyncLong,
Example: fmt.Sprintf(rsyncExample, parent+" "+name),
Run: func(c *cobra.Command, args []string) {
kcmdutil.CheckErr(o.Complete(f, c, args))
kcmdutil.CheckErr(o.Validate())
kcmdutil.CheckErr(o.RunRsync())
},
}
cmd.Flags().StringVarP(&o.ContainerName, "container", "c", "", "Container within the pod")
cmd.Flags().BoolVarP(&o.Quiet, "quiet", "q", false, "Quiet copy")
cmd.Flags().BoolVar(&o.Delete, "delete", false, "Delete files not present in source")
cmd.Flags().BoolVar(&o.UseTar, "use-tar", false, "Use tar instead of rsync")
return cmd
}
开发者ID:ncantor,项目名称:origin,代码行数:28,代码来源:rsync.go
示例4: copyNetworkPodInfo
func (d *NetworkDiagnostic) copyNetworkPodInfo(pod *kapi.Pod) error {
tmp, err := ioutil.TempFile("", "network-diags")
if err != nil {
return fmt.Errorf("Can not create local temporary file for tar: %v", err)
}
defer os.Remove(tmp.Name())
// Tar logdir on the remote node and copy to a local temporary file
errBuf := &bytes.Buffer{}
nodeLogDir := filepath.Join(util.NetworkDiagDefaultLogDir, util.NetworkDiagNodeLogDirPrefix, pod.Spec.NodeName)
cmd := []string{"chroot", util.NetworkDiagContainerMountPath, "tar", "-C", nodeLogDir, "-c", "."}
if err = util.Execute(d.Factory, cmd, pod, nil, tmp, errBuf); err != nil {
return fmt.Errorf("Creating remote tar locally failed: %v, %s", err, errBuf.String())
}
if err := tmp.Close(); err != nil {
return fmt.Errorf("Closing temporary tar file %s failed: %v", tmp.Name(), err)
}
// Extract copied temporary file locally
tmp, err = os.Open(tmp.Name())
if err != nil {
return fmt.Errorf("Can not open temporary tar file %s: %v", tmp.Name(), err)
}
defer tmp.Close()
tarHelper := tar.New()
tarHelper.SetExclusionPattern(nil)
logdir := filepath.Join(d.LogDir, util.NetworkDiagNodeLogDirPrefix, pod.Spec.NodeName)
err = tarHelper.ExtractTarStream(logdir, tmp)
if err != nil {
return fmt.Errorf("Untar local directory failed: %v, %s", err, errBuf.String())
}
return nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:34,代码来源:results.go
示例5: New
// New returns a new instance of OnBuild builder
func New(config *api.Config, overrides build.Overrides) (*OnBuild, error) {
dockerHandler, err := docker.New(config.DockerConfig, config.PullAuthentication)
if err != nil {
return nil, err
}
b := &OnBuild{
docker: dockerHandler,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
}
// Use STI Prepare() and download the 'run' script optionally.
s, err := sti.New(config, overrides)
s.SetScripts([]string{}, []string{api.Assemble, api.Run})
downloader := overrides.Downloader
if downloader == nil {
d, sourceURL, err := scm.DownloaderForSource(config.Source)
if err != nil {
return nil, err
}
downloader = d
config.Source = sourceURL
}
b.source = onBuildSourceHandler{
Downloader: downloader,
Preparer: s,
Ignorer: &ignore.DockerIgnorer{},
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
return b, nil
}
开发者ID:johnmccawley,项目名称:origin,代码行数:35,代码来源:onbuild.go
示例6: UploadToContainerWithCallback
// UploadToContainerWithCallback uploads artifacts to the container.
// If the source is a directory, then all files and sub-folders are copied into
// the destination (which has to be directory as well).
// If the source is a single file, then the file copied into destination (which
// has to be full path to a file inside the container).
// If the destination path is empty or set to ".", then we will try to figure
// out the WORKDIR of the image that the container was created from and use that
// as a destination. If the WORKDIR is not set, then we copy files into "/"
// folder (docker upload default).
func (d *stiDocker) UploadToContainerWithCallback(src, dest, container string, walkFn filepath.WalkFunc, modifyInplace bool) error {
path := filepath.Dir(dest)
f, err := os.Open(src)
if err != nil {
return err
}
info, _ := f.Stat()
defer f.Close()
t := tar.New()
r, w := io.Pipe()
if info.IsDir() {
path = dest
go func() {
defer w.Close()
if err := t.StreamDirAsTarWithCallback(src, w, walkFn, modifyInplace); err != nil {
glog.V(0).Infof("error: Uploading directory to container failed: %v", err)
}
}()
} else {
go func() {
defer w.Close()
if err := t.StreamFileAsTarWithCallback(src, filepath.Base(dest), w, walkFn, modifyInplace); err != nil {
glog.V(0).Infof("error: Uploading files to container failed: %v", err)
}
}()
}
glog.V(3).Infof("Uploading %q to %q ...", src, path)
ctx, cancel := getDefaultContext(DefaultDockerTimeout)
defer cancel()
return d.client.CopyToContainer(ctx, container, path, r, dockertypes.CopyToContainerOptions{})
}
开发者ID:pweil-,项目名称:origin,代码行数:40,代码来源:docker.go
示例7: UploadToContainer
// UploadToContainer uploads artifacts to the container.
// If the source is a directory, then all files and sub-folders are copied into
// the destination (which has to be directory as well).
// If the source is a single file, then the file copied into destination (which
// has to be full path to a file inside the container).
// If the destination path is empty or set to ".", then we will try to figure
// out the WORKDIR of the image that the container was created from and use that
// as a destination. If the WORKDIR is not set, then we copy files into "/"
// folder (docker upload default).
func (d *stiDocker) UploadToContainer(src, dest, name string) error {
path := filepath.Dir(dest)
f, err := os.Open(src)
if err != nil {
return err
}
info, _ := f.Stat()
defer f.Close()
t := tar.New()
r, w := io.Pipe()
if info.IsDir() {
path = dest
go func() {
defer w.Close()
if err := t.StreamDirAsTar(src, dest, w); err != nil {
glog.Errorf("Uploading directory to container failed: %v", err)
}
}()
} else {
go func() {
defer w.Close()
if err := t.StreamFileAsTar(src, filepath.Base(dest), w); err != nil {
glog.Errorf("Uploading files to container failed: %v", err)
}
}()
}
glog.V(3).Infof("Uploading %q to %q ...", src, path)
opts := docker.UploadToContainerOptions{Path: path, InputStream: r}
return d.client.UploadToContainer(name, opts)
}
开发者ID:smacc364,项目名称:origin,代码行数:39,代码来源:docker.go
示例8: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config, overrides build.Overrides) (*STI, error) {
docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
var incrementalDocker dockerpkg.Docker
if req.Incremental {
incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication)
if err != nil {
return nil, err
}
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
incrementalDocker: incrementalDocker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
// TODO: explicit decision made to customize processing for usage specifically vs.
// leveraging overrides; also, we ultimately want to simplify s2i usage a good bit,
// which would lead to replacing this quick short circuit (so this change is tactical)
b.source = overrides.Downloader
if b.source == nil && !req.Usage {
downloader, sourceURL, err := scm.DownloaderForSource(req.Source, req.ForceCopy)
if err != nil {
return nil, err
}
b.source = downloader
req.Source = sourceURL
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b, overrides)
// Set interfaces
b.preparer = b
// later on, if we support say .gitignore func in addition to .dockerignore func, setting
// ignorer will be based on config setting
b.ignorer = &ignore.DockerIgnorer{}
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:carriercomm,项目名称:origin,代码行数:63,代码来源:sti.go
示例9: DownloadDirFromContainer
// DownloadDirFromContainer downloads an entire directory of files from a remote
// container.
func DownloadDirFromContainer(client *docker.Client, container, src, dst string) error {
downloader := newContainerDownloader(client, container, src)
defer downloader.Close()
tarReader := &removeLeadingDirectoryAdapter{Reader: tar.NewReader(downloader)}
t := stitar.New()
return t.ExtractTarStreamFromTarReader(dst, tarReader, nil)
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:10,代码来源:filetransfer.go
示例10: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, build *api.Build) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
build: build,
git: git.New(),
tar: tar.New(),
urlTimeout: urlCheckTimeout,
}
}
开发者ID:nikkomega,项目名称:origin,代码行数:10,代码来源:docker.go
示例11: New
// New returns the instance of STI builder strategy for the given config.
// If the layeredBuilder parameter is specified, then the builder provided will
// be used for the case that the base Docker image does not have 'tar' or 'bash'
// installed.
func New(req *api.Config, overrides build.Overrides) (*STI, error) {
docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication)
if err != nil {
return nil, err
}
var incrementalDocker dockerpkg.Docker
if req.Incremental {
incrementalDocker, err = dockerpkg.New(req.DockerConfig, req.IncrementalAuthentication)
if err != nil {
return nil, err
}
}
inst := scripts.NewInstaller(req.BuilderImage, req.ScriptsURL, docker, req.PullAuthentication)
b := &STI{
installer: inst,
config: req,
docker: docker,
incrementalDocker: incrementalDocker,
git: git.New(),
fs: util.NewFileSystem(),
tar: tar.New(),
callbackInvoker: util.NewCallbackInvoker(),
requiredScripts: []string{api.Assemble, api.Run},
optionalScripts: []string{api.SaveArtifacts},
externalScripts: map[string]bool{},
installedScripts: map[string]bool{},
scriptsURL: map[string]string{},
}
// The sources are downloaded using the GIT downloader.
// TODO: Add more SCM in future.
b.source = overrides.Downloader
if b.source == nil {
downloader, sourceURL, err := scm.DownloaderForSource(req.Source)
if err != nil {
return nil, err
}
b.source = downloader
req.Source = sourceURL
}
b.garbage = &build.DefaultCleaner{b.fs, b.docker}
b.layered, err = layered.New(req, b, overrides)
// Set interfaces
b.preparer = b
// later on, if we support say .gitignore func in addition to .dockerignore func, setting
// ignorer will be based on config setting
b.ignorer = &ignore.DockerIgnorer{}
b.artifacts = b
b.scripts = b
b.postExecutor = b
return b, err
}
开发者ID:4sp1r3,项目名称:source-to-image,代码行数:60,代码来源:sti.go
示例12: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterface, build *api.Build, gitClient GitClient) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: gitClient,
tar: tar.New(),
urlTimeout: urlCheckTimeout,
client: buildsClient,
}
}
开发者ID:johnmccawley,项目名称:origin,代码行数:11,代码来源:docker.go
示例13: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterface, build *api.Build, gitClient GitClient, cgLimits *s2iapi.CGroupLimits) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: gitClient,
tar: tar.New(s2iutil.NewFileSystem()),
client: buildsClient,
cgLimits: cgLimits,
}
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:11,代码来源:docker.go
示例14: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterface, build *api.Build, gitClient GitClient, cgLimits *s2iapi.CGroupLimits) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: gitClient,
tar: tar.New(),
urlTimeout: initialURLCheckTimeout,
client: buildsClient,
cgLimits: cgLimits,
}
}
开发者ID:abhgupta,项目名称:origin,代码行数:12,代码来源:docker.go
示例15: NewDockerBuilder
// NewDockerBuilder creates a new instance of DockerBuilder
func NewDockerBuilder(dockerClient DockerClient, authCfg docker.AuthConfiguration, authPresent bool, build *api.Build) *DockerBuilder {
return &DockerBuilder{
dockerClient: dockerClient,
authPresent: authPresent,
auth: authCfg,
build: build,
git: git.New(),
tar: tar.New(),
urlTimeout: urlCheckTimeout,
}
}
开发者ID:cjnygard,项目名称:origin,代码行数:12,代码来源:docker.go
示例16: New
func New(config *api.Config, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) {
d, err := docker.New(config.DockerConfig, config.PullAuthentication)
if err != nil {
return nil, err
}
return &Layered{
docker: d,
config: config,
fs: util.NewFileSystem(),
tar: tar.New(),
scripts: scripts,
}, nil
}
开发者ID:smacc364,项目名称:origin,代码行数:13,代码来源:layered.go
示例17: CopyFromHost
// CopyFromHost copies a set of files from the Docker host to the local file system
func (h *HostHelper) CopyFromHost(sourceDir, destDir string) error {
container, err := h.runner().
Image(h.image).
Bind(fmt.Sprintf("%[1]s:%[1]s:ro", sourceDir)).
Create()
if err != nil {
return err
}
defer func() {
errors.LogError(h.client.RemoveContainer(docker.RemoveContainerOptions{ID: container}))
}()
localTarFile, err := ioutil.TempFile("", "local-copy-tar-")
if err != nil {
return err
}
localTarClosed := false
defer func() {
if !localTarClosed {
errors.LogError(localTarFile.Close())
}
errors.LogError(os.Remove(localTarFile.Name()))
}()
glog.V(4).Infof("Downloading from host path %s to local tar file: %s", sourceDir, localTarFile.Name())
err = h.client.DownloadFromContainer(container, docker.DownloadFromContainerOptions{
Path: sourceDir,
OutputStream: localTarFile,
})
if err != nil {
return err
}
if err = localTarFile.Close(); err != nil {
return err
}
localTarClosed = true
inputTar, err := os.Open(localTarFile.Name())
if err != nil {
return err
}
defer func() {
errors.LogError(inputTar.Close())
}()
tarHelper := tarhelper.New()
tarHelper.SetExclusionPattern(nil)
glog.V(4).Infof("Extracting temporary tar %s to directory %s", inputTar.Name(), destDir)
var tarLog io.Writer
if glog.V(5) {
tarLog = os.Stderr
}
return tarHelper.ExtractTarStreamWithLogging(destDir, inputTar, tarLog)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:51,代码来源:host.go
示例18: UploadFileToContainer
// UploadFileToContainer uploads a file to a remote container.
func UploadFileToContainer(client *docker.Client, container, src, dest string) error {
uploader := newContainerUploader(client, container, filepath.Dir(dest))
nullWalkFunc := func(path string, info os.FileInfo, err error) error { return err }
t := stitar.New()
err := t.StreamFileAsTarWithCallback(src, filepath.Base(dest), uploader, nullWalkFunc, false)
if err != nil {
uploader.Close()
return err
}
return uploader.Close()
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:15,代码来源:filetransfer.go
示例19: New
// New creates a Layered builder.
func New(config *api.Config, fs util.FileSystem, scripts build.ScriptsHandler, overrides build.Overrides) (*Layered, error) {
d, err := docker.New(config.DockerConfig, config.PullAuthentication)
if err != nil {
return nil, err
}
tarHandler := tar.New(fs)
tarHandler.SetExclusionPattern(regexp.MustCompile(config.ExcludeRegExp))
return &Layered{
docker: d,
config: config,
fs: fs,
tar: tarHandler,
scripts: scripts,
}, nil
}
开发者ID:php-coder,项目名称:origin,代码行数:16,代码来源:layered.go
示例20: UploadFileToContainer
// UploadFileToContainer uploads a file to a remote container.
func UploadFileToContainer(client *docker.Client, container, src, dest string) error {
uploader, errch := newContainerUploader(client, container, filepath.Dir(dest))
t := s2itar.New(s2iutil.NewFileSystem())
tarWriter := s2itar.RenameAdapter{Writer: tar.NewWriter(uploader), Old: filepath.Base(src), New: filepath.Base(dest)}
err := t.CreateTarStreamToTarWriter(src, true, tarWriter, nil)
if err == nil {
err = tarWriter.Close()
}
uploader.Close()
if err != nil {
return err
}
return <-errch
}
开发者ID:php-coder,项目名称:origin,代码行数:18,代码来源:filetransfer.go
注:本文中的github.com/openshift/source-to-image/pkg/tar.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论