本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/scm/git.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
details, mods := git.ParseFile(s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new path from parse file %s", mods.Path)
s = mods.Path
}
if details.FileExists && details.UseCopy {
return &file.File{util.NewFileSystem()}, s, nil
}
// If the source is valid GIT protocol (file://, ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
示例3: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string, forceCopy bool) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
details, mods := git.ParseFile(s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new source from parse file %s", mods.Path)
if details.ProtoSpecified {
s = mods.Path
} else {
// prepending with file:// is a precautionary step which previous incarnations of this code did; we
// preserve that behavior (it is more explicit, if not absolutely necessary; but we do it here as was done before
// vs. down in our generic git layer (which is leveraged separately in origin)
s = "file://" + mods.Path
}
}
if details.FileExists && (details.UseCopy || forceCopy) {
return &file.File{util.NewFileSystem()}, s, nil
}
// If the source is valid GIT protocol (file://, ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
示例4: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
details, _ := git.ParseFile(s)
if details.FileExists && details.UseCopy {
if !details.ProtoSpecified {
// since not using git, any resulting URLs need to be explicit with file:// protocol specified
s = "file://" + s
}
return &file.File{util.NewFileSystem()}, s, nil
}
if details.ProtoSpecified && !details.FileExists {
return nil, s, fmt.Errorf("local location: %s does not exist", s)
}
if !details.ProtoSpecified && details.FileExists {
// if local file system, without file://, when using git, should not need file://, but we'll be safe;
// satisfies previous constructed test case in scm_test.go as well
s = "file://" + s
}
// If the source is valid GIT remote protocol (ssh://, git://, [email protected], etc..) use GIT
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}
示例5: 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
}
示例6: 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,
}
}
示例7: 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
}
示例8: IsRemoteRepository
// IsRemoteRepository checks whether the provided string is a remote repository or not
func IsRemoteRepository(s string) bool {
if !s2igit.New().ValidCloneSpecRemoteOnly(s) {
return false
}
gitRepo := git.NewRepository()
if err := gitRepo.ListRemote(s); err != nil {
return false
}
return true
}
示例9: checkSourceURI
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid.
func checkSourceURI(gitClient GitClient, rawurl string, timeout time.Duration) error {
ok, err := s2igit.New().ValidCloneSpec(rawurl)
if err != nil {
return fmt.Errorf("Invalid git source url %q: %v", rawurl, err)
}
if !ok {
return fmt.Errorf("Invalid git source url: %s", rawurl)
}
return checkRemoteGit(gitClient, rawurl, timeout)
}
示例10: newSTIBuilder
// newSTIBuilder is the internal factory function to create STIBuilder based on parameters. Used for testing.
func newSTIBuilder(client DockerClient, dockerSocket string, build *api.Build,
builder builderFactory, validator validator) *STIBuilder {
// just create instance
return &STIBuilder{
builder: builder,
validator: validator,
git: git.New(),
dockerClient: client,
dockerSocket: dockerSocket,
build: build,
}
}
示例11: newS2IBuilder
// newS2IBuilder is the internal factory function to create STIBuilder based on parameters. Used for testing.
func newS2IBuilder(dockerClient DockerClient, dockerSocket string, buildsClient client.BuildInterface, build *api.Build,
builder builderFactory, validator validator) *S2IBuilder {
// just create instance
return &S2IBuilder{
builder: builder,
validator: validator,
git: git.New(),
dockerClient: dockerClient,
dockerSocket: dockerSocket,
build: build,
client: buildsClient,
}
}
示例12: IsRemoteRepository
// IsRemoteRepository checks whether the provided string is a remote repository or not
func IsRemoteRepository(s string) bool {
if !s2igit.New(s2iutil.NewFileSystem()).ValidCloneSpecRemoteOnly(s) {
return false
}
url, err := url.Parse(s)
if err != nil {
return false
}
url.Fragment = ""
gitRepo := git.NewRepository()
if _, _, err := gitRepo.ListRemote(url.String()); err != nil {
return false
}
return true
}
示例13: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) build.Downloader {
// If the source starts with file:// and there is no GIT binary, use 'file'
// SCM plugin
if (strings.HasPrefix(s, "file://") || strings.HasPrefix(s, "/")) && !hasGitBinary() {
return &file.File{util.NewFileSystem()}
}
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}
}
glog.Errorf("No downloader defined for %q source URL", s)
return nil
}
示例14: ParseRepository
// ParseRepository parses a string that may be in the Git format ([email protected]) or URL format
// and extracts the appropriate value. Any fragment on the URL is preserved.
//
// Protocols returned:
// - http, https
// - file
// - git
// - ssh
func ParseRepository(s string) (*url.URL, error) {
uri, err := url.Parse(s)
if err != nil {
return nil, err
}
// There are some shortcomings with url.Parse when it comes to GIT, namely wrt
// the GIT local/file and ssh protocols - it does not handle implied schema (i.e. no <proto>:// prefix)well;
// We handle those caveats here
err = s2igit.New().MungeNoProtocolURL(s, uri)
if err != nil {
return nil, err
}
return uri, nil
}
示例15: DownloaderForSource
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(fs util.FileSystem, s string, forceCopy bool) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
if len(s) == 0 {
return &empty.Noop{}, s, nil
}
details, mods, err := git.ParseFile(fs, s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if err != nil {
if e, ok := err.(errors.Error); !forceCopy || !(ok && (e.ErrorCode == errors.EmptyGitRepositoryError)) {
return nil, s, err
}
}
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new source from parse file %s", mods.Path)
s = "file://" + mods.Path
}
if details.FileExists && (details.UseCopy || forceCopy) {
return &file.File{FileSystem: fs}, s, nil
}
// If the source is valid Git protocol (file://, ssh://, git://, [email protected], etc..) use Git
// binary to download the sources
g := git.New(fs)
ok, err := g.ValidCloneSpec(s)
if err != nil {
return nil, s, err
}
if ok {
return &git.Clone{Git: g, FileSystem: fs}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}