本文整理汇总了Golang中github.com/openshift/origin/pkg/generate/git.NewRepository函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRepository函数的具体用法?Golang NewRepository怎么用?Golang NewRepository使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRepository函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: LocalPath
// LocalPath returns the local path of the source repository
func (r *SourceRepository) LocalPath() (string, error) {
if len(r.localDir) > 0 {
return r.localDir, nil
}
switch {
case r.url.Scheme == "file":
r.localDir = filepath.Join(r.url.Path, r.contextDir)
default:
gitRepo := git.NewRepository()
var err error
if r.localDir, err = ioutil.TempDir("", "gen"); err != nil {
return "", err
}
localURL := r.url
ref := localURL.Fragment
localURL.Fragment = ""
if err = gitRepo.Clone(r.localDir, localURL.String()); err != nil {
return "", fmt.Errorf("cannot clone repository %s: %v", localURL.String(), err)
}
if len(ref) > 0 {
if err = gitRepo.Checkout(r.localDir, ref); err != nil {
return "", fmt.Errorf("cannot checkout ref %s of repository %s: %v", ref, localURL.String(), err)
}
}
r.localDir = filepath.Join(r.localDir, r.contextDir)
}
return r.localDir, nil
}
开发者ID:hloganathan,项目名称:origin,代码行数:29,代码来源:sourcelookup.go
示例2: RemoteURL
// RemoteURL returns the remote URL of the source repository
func (r *SourceRepository) RemoteURL() (*url.URL, bool, error) {
if r.remoteURL != nil {
return r.remoteURL, true, nil
}
switch r.url.Scheme {
case "file":
gitRepo := git.NewRepository()
remote, ok, err := gitRepo.GetOriginURL(r.url.Path)
if err != nil && err != git.ErrGitNotAvailable {
return nil, false, err
}
if !ok {
return nil, ok, nil
}
ref := gitRepo.GetRef(r.url.Path)
if len(ref) > 0 {
remote = fmt.Sprintf("%s#%s", remote, ref)
}
if r.remoteURL, err = git.ParseRepository(remote); err != nil {
return nil, false, err
}
default:
r.remoteURL = &r.url
}
return r.remoteURL, true, nil
}
开发者ID:php-coder,项目名称:origin,代码行数:28,代码来源:sourcelookup.go
示例3: NewBuildStrategyRefGenerator
// NewBuildStrategyRefGenerator creates a BuildStrategyRefGenerator
func NewBuildStrategyRefGenerator(sourceDetectors source.Detectors) *BuildStrategyRefGenerator {
return &BuildStrategyRefGenerator{
gitRepository: git.NewRepository(),
dockerfileFinder: dockerfile.NewFinder(),
sourceDetectors: sourceDetectors,
imageRefGenerator: NewImageRefGenerator(),
}
}
开发者ID:johnmccawley,项目名称:origin,代码行数:9,代码来源:strategyref.go
示例4: 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
}
开发者ID:urashidmalik,项目名称:origin,代码行数:11,代码来源:sourcelookup.go
示例5: 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
}
开发者ID:php-coder,项目名称:origin,代码行数:16,代码来源:sourcelookup.go
示例6: newTestS2IBuilder
// newTestS2IBuilder creates a mock implementation of S2IBuilder, instrumenting
// different parts to return specific errors according to config.
func newTestS2IBuilder(config testS2IBuilderConfig) *S2IBuilder {
return newS2IBuilder(
&FakeDocker{
errPushImage: config.errPushImage,
},
"/docker.socket",
testclient.NewSimpleFake().Builds(""),
makeBuild(),
git.NewRepository(),
testStiBuilderFactory{
getStrategyErr: config.getStrategyErr,
buildError: config.buildError,
},
runtimeConfigValidator{},
)
}
开发者ID:smacc364,项目名称:origin,代码行数:18,代码来源:sti_test.go
示例7: makeStiBuilder
// creates mock implemenation of STI builder, instrumenting different parts of a process to return errors
func makeStiBuilder(
errPushImage error,
getStrategyErr error,
buildError error,
validationErrors []validation.ValidationError) S2IBuilder {
return *newS2IBuilder(
testDockerClient{
errPushImage: errPushImage,
},
"/docker.socket",
testclient.NewSimpleFake().Builds(""),
makeBuild(),
git.NewRepository(),
testStiBuilderFactory{getStrategyErr: getStrategyErr, buildError: buildError},
testStiConfigValidator{errors: validationErrors},
)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:18,代码来源:sti_test.go
示例8: LocalPath
// LocalPath returns the local path of the source repository
func (r *SourceRepository) LocalPath() (string, error) {
if len(r.localDir) > 0 {
return r.localDir, nil
}
switch {
case r.url.Scheme == "file":
r.localDir = filepath.Join(r.url.Path, r.contextDir)
default:
gitRepo := git.NewRepository()
var err error
if r.localDir, err = ioutil.TempDir("", "gen"); err != nil {
return "", err
}
localURL, ref := cloneURLAndRef(&r.url)
r.localDir, err = CloneAndCheckoutSources(gitRepo, localURL.String(), ref, r.localDir, r.contextDir)
if err != nil {
return "", err
}
}
return r.localDir, nil
}
开发者ID:php-coder,项目名称:origin,代码行数:22,代码来源:sourcelookup.go
示例9: RemoteURL
// RemoteURL returns the remote URL of the source repository
func (r *SourceRepository) RemoteURL() (*url.URL, error) {
if r.remoteURL != nil {
return r.remoteURL, nil
}
switch r.url.Scheme {
case "file":
gitRepo := git.NewRepository()
remote, _, err := gitRepo.GetOriginURL(r.url.Path)
if err != nil {
return nil, err
}
ref := gitRepo.GetRef(r.url.Path)
if len(ref) > 0 {
remote = fmt.Sprintf("%s#%s", remote, ref)
}
if r.remoteURL, err = url.Parse(remote); err != nil {
return nil, err
}
default:
r.remoteURL = &r.url
}
return r.remoteURL, nil
}
开发者ID:hloganathan,项目名称:origin,代码行数:24,代码来源:sourcelookup.go
示例10: RunStartBuild
// RunStartBuild contains all the necessary functionality for the OpenShift cli start-build command
func RunStartBuild(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, args []string, webhooks util.StringFlag) error {
webhook := cmdutil.GetFlagString(cmd, "from-webhook")
buildName := cmdutil.GetFlagString(cmd, "from-build")
follow := cmdutil.GetFlagBool(cmd, "follow")
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 {
return cmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments or '--from-build'")
}
path := cmdutil.GetFlagString(cmd, "git-repository")
postReceivePath := cmdutil.GetFlagString(cmd, "git-post-receive")
repo := git.NewRepository()
return RunStartBuildWebHook(f, out, webhook, path, postReceivePath, repo)
case len(args) != 1 && len(buildName) == 0:
return cmdutil.UsageError(cmd, "Must pass a name of a BuildConfig or specify build name with '--from-build' flag")
}
name := buildName
isBuild := true
if len(name) == 0 {
name = args[0]
isBuild = false
}
if webhooks.Provided() {
return RunListBuildWebHooks(f, out, cmd.Out(), name, isBuild, webhooks.String())
}
client, _, err := f.Clients()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{Name: name},
}
var newBuild *buildapi.Build
if isBuild {
if newBuild, err = client.Builds(namespace).Clone(request); err != nil {
return err
}
} else {
if newBuild, err = client.BuildConfigs(namespace).Instantiate(request); err != nil {
return err
}
}
fmt.Fprintf(out, "%s\n", newBuild.Name)
if follow {
opts := buildapi.BuildLogOptions{
Follow: true,
NoWait: false,
}
rd, err := client.BuildLogs(namespace).Get(newBuild.Name, opts).Stream()
if err != nil {
return fmt.Errorf("error getting logs: %v", err)
}
defer rd.Close()
_, err = io.Copy(out, rd)
if err != nil {
return fmt.Errorf("error streaming logs: %v", err)
}
}
return nil
}
开发者ID:Tlacenka,项目名称:origin,代码行数:72,代码来源:startbuild.go
示例11: RunStartBuild
// RunStartBuild contains all the necessary functionality for the OpenShift cli start-build command
func RunStartBuild(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, args []string, webhooks util.StringFlag) error {
webhook := cmdutil.GetFlagString(cmd, "from-webhook")
buildName := cmdutil.GetFlagString(cmd, "from-build")
follow := cmdutil.GetFlagBool(cmd, "follow")
commit := cmdutil.GetFlagString(cmd, "commit")
waitForComplete := cmdutil.GetFlagBool(cmd, "wait")
fromFile := cmdutil.GetFlagString(cmd, "from-file")
fromDir := cmdutil.GetFlagString(cmd, "from-dir")
fromRepo := cmdutil.GetFlagString(cmd, "from-repo")
//shortOutput := false
//mapper, _ := f.Object()
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 || len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0 {
return cmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments and all '--from-*' flags")
}
path := cmdutil.GetFlagString(cmd, "git-repository")
postReceivePath := cmdutil.GetFlagString(cmd, "git-post-receive")
repo := git.NewRepository()
return RunStartBuildWebHook(f, out, webhook, path, postReceivePath, repo)
case len(args) != 1 && len(buildName) == 0:
return cmdutil.UsageError(cmd, "Must pass a name of a build config or specify build name with '--from-build' flag")
}
name := buildName
isBuild := true
if len(name) == 0 {
name = args[0]
isBuild = false
}
if webhooks.Provided() {
return RunListBuildWebHooks(f, out, cmd.Out(), name, isBuild, webhooks.String())
}
client, _, err := f.Clients()
if err != nil {
return err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{Name: name},
}
if len(commit) > 0 {
request.Revision = &buildapi.SourceRevision{
Type: buildapi.BuildSourceGit,
Git: &buildapi.GitSourceRevision{
Commit: commit,
},
}
}
git := git.NewRepository()
var newBuild *buildapi.Build
switch {
case !isBuild && (len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0):
request := &buildapi.BinaryBuildRequestOptions{
ObjectMeta: kapi.ObjectMeta{
Name: name,
Namespace: namespace,
},
Commit: commit,
}
if newBuild, err = streamPathToBuild(git, in, cmd.Out(), client.BuildConfigs(namespace), fromDir, fromFile, fromRepo, request); err != nil {
return err
}
case isBuild:
if newBuild, err = client.Builds(namespace).Clone(request); err != nil {
return err
}
default:
if newBuild, err = client.BuildConfigs(namespace).Instantiate(request); err != nil {
return err
}
}
//cmdutil.PrintSuccess(mapper, shortOutput, out, "Build", newBuild.Name, "started")
fmt.Fprintln(out, newBuild.Name)
var (
wg sync.WaitGroup
exitErr error
)
// Wait for the build to complete
if waitForComplete {
wg.Add(1)
go func() {
defer wg.Done()
//.........这里部分代码省略.........
开发者ID:kcbabo,项目名称:origin,代码行数:101,代码来源:startbuild.go
示例12: TestDockerfilePath
// TestDockerfilePath validates that we can use a Dockefile with a custom name, and in a sub-directory
func TestDockerfilePath(t *testing.T) {
tests := []struct {
contextDir string
dockerfilePath string
dockerStrategy *api.DockerBuildStrategy
}{
// default Dockerfile path
{
dockerfilePath: "Dockerfile",
dockerStrategy: &api.DockerBuildStrategy{},
},
// custom Dockerfile path in the root context
{
dockerfilePath: "mydockerfile",
dockerStrategy: &api.DockerBuildStrategy{
DockerfilePath: "mydockerfile",
},
},
// custom Dockerfile path in a sub directory
{
dockerfilePath: "dockerfiles/mydockerfile",
dockerStrategy: &api.DockerBuildStrategy{
DockerfilePath: "dockerfiles/mydockerfile",
},
},
// custom Dockerfile path in a sub directory
// with a contextDir
{
contextDir: "somedir",
dockerfilePath: "dockerfiles/mydockerfile",
dockerStrategy: &api.DockerBuildStrategy{
DockerfilePath: "dockerfiles/mydockerfile",
},
},
}
for _, test := range tests {
buildDir, err := ioutil.TempDir("", "dockerfile-path")
if err != nil {
t.Errorf("failed to create tmpdir: %v", err)
continue
}
absoluteDockerfilePath := filepath.Join(buildDir, test.contextDir, test.dockerfilePath)
dockerfileContent := "FROM openshift/origin-base"
if err = os.MkdirAll(filepath.Dir(absoluteDockerfilePath), os.FileMode(0750)); err != nil {
t.Errorf("failed to create directory %s: %v", filepath.Dir(absoluteDockerfilePath), err)
continue
}
if err = ioutil.WriteFile(absoluteDockerfilePath, []byte(dockerfileContent), os.FileMode(0644)); err != nil {
t.Errorf("failed to write dockerfile to %s: %v", absoluteDockerfilePath, err)
continue
}
build := &api.Build{
Spec: api.BuildSpec{
Source: api.BuildSource{
Git: &api.GitBuildSource{
URI: "http://github.com/openshift/origin.git",
},
ContextDir: test.contextDir,
},
Strategy: api.BuildStrategy{
DockerStrategy: test.dockerStrategy,
},
Output: api.BuildOutput{
To: &kapi.ObjectReference{
Kind: "DockerImage",
Name: "test/test-result:latest",
},
},
},
}
dockerClient := &FakeDocker{
buildImageFunc: func(opts docker.BuildImageOptions) error {
if opts.Dockerfile != test.dockerfilePath {
t.Errorf("Unexpected dockerfile path: %s (expected: %s)", opts.Dockerfile, test.dockerfilePath)
}
return nil
},
}
dockerBuilder := &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: git.NewRepository(),
tar: tar.New(),
}
// this will validate that the Dockerfile is readable
// and append some labels to the Dockerfile
if err = dockerBuilder.addBuildParameters(buildDir); err != nil {
t.Errorf("failed to add build parameters: %v", err)
continue
}
// check that our Dockerfile has been modified
dockerfileData, err := ioutil.ReadFile(absoluteDockerfilePath)
if err != nil {
//.........这里部分代码省略.........
开发者ID:johnmccawley,项目名称:origin,代码行数:101,代码来源:docker_test.go
示例13: Generate
//.........这里部分代码省略.........
aliases[parts[0]] = set
}
set.Insert(parts[1])
}
}
// find and define build pipelines
for _, k := range serviceOrder.List() {
v := p.Configs[k]
if len(v.Build) == 0 {
continue
}
if _, ok := builds[v.Build]; ok {
continue
}
var base, relative string
for _, s := range bases {
if !strings.HasPrefix(v.Build, s) {
continue
}
base = s
path, err := filepath.Rel(base, v.Build)
if err != nil {
return nil, fmt.Errorf("path is not relative to base: %v", err)
}
relative = path
break
}
if len(base) == 0 {
return nil, fmt.Errorf("build path outside of the compose file: %s", v.Build)
}
// if this is a Git repository, make the path relative
if root, err := git.NewRepository().GetRootDir(base); err == nil {
if relative, err = filepath.Rel(root, filepath.Join(base, relative)); err != nil {
return nil, fmt.Errorf("unable to find relative path for Git repository: %v", err)
}
base = root
}
buildPath := filepath.Join(base, relative)
// TODO: what if there is no origin for this repo?
glog.V(4).Infof("compose service: %#v", v)
repo, err := app.NewSourceRepositoryWithDockerfile(buildPath, "")
if err != nil {
errs = append(errs, err)
continue
}
repo.BuildWithDocker()
info := repo.Info()
if info == nil || info.Dockerfile == nil {
errs = append(errs, fmt.Errorf("unable to locate a Dockerfile in %s", v.Build))
continue
}
node := info.Dockerfile.AST()
baseImage := dockerfileutil.LastBaseImage(node)
if len(baseImage) == 0 {
errs = append(errs, fmt.Errorf("the Dockerfile in the repository %q has no FROM instruction", info.Path))
continue
}
var ports []string
for _, s := range v.Ports {
container, _ := extractFirstPorts(s)
开发者ID:RomainVabre,项目名称:origin,代码行数:67,代码来源:generate.go
示例14: NewSourceRefGenerator
// NewSourceRefGenerator creates a new SourceRefGenerator
func NewSourceRefGenerator() *SourceRefGenerator {
return &SourceRefGenerator{
repository: git.NewRepository(),
}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:6,代码来源:sourceref.go
示例15: Complete
func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, args []string) error {
o.In = in
o.Out = out
o.ErrOut = cmd.Out()
o.Git = git.NewRepository()
o.ClientConfig = f.OpenShiftClientConfig
webhook := o.FromWebhook
buildName := o.FromBuild
fromFile := o.FromFile
fromDir := o.FromDir
fromRepo := o.FromRepo
buildLogLevel := o.LogLevel
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 || len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0 {
return kcmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments and all '--from-*' flags")
}
return nil
case len(args) != 1 && len(buildName) == 0:
return kcmdutil.UsageError(cmd, "Must pass a name of a build config or specify build name with '--from-build' flag")
}
o.AsBinary = len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
client, _, err := f.Clients()
if err != nil {
return err
}
o.Client = client
var (
name = buildName
resource = buildapi.Resource("builds")
)
if len(name) == 0 && len(args) > 0 && len(args[0]) > 0 {
mapper, _ := f.Object(false)
resource, name, err = cmdutil.ResolveResource(buildapi.Resource("buildconfigs"), args[0], mapper)
if err != nil {
return err
}
switch resource {
case buildapi.Resource("buildconfigs"):
// no special handling required
case buildapi.Resource("builds"):
if len(o.ListWebhooks) == 0 {
return fmt.Errorf("use --from-build to rerun your builds")
}
default:
return fmt.Errorf("invalid resource provided: %v", resource)
}
}
// when listing webhooks, allow --from-build to lookup a build config
if resource == buildapi.Resource("builds") && len(o.ListWebhooks) > 0 {
build, err := client.Builds(namespace).Get(name)
if err != nil {
return err
}
ref := build.Status.Config
if ref == nil {
return fmt.Errorf("the provided Build %q was not created from a BuildConfig and cannot have webhooks", name)
}
if len(ref.Namespace) > 0 {
namespace = ref.Namespace
}
name = ref.Name
}
if len(name) == 0 {
return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
}
o.Namespace = namespace
o.Name = name
env, _, err := cmdutil.ParseEnv(o.Env, in)
if err != nil {
return err
}
if len(buildLogLevel) > 0 {
env = append(env, kapi.EnvVar{Name: "BUILD_LOGLEVEL", Value: buildLogLevel})
}
o.EnvVar = env
return nil
}
开发者ID:sgallagher,项目名称:origin,代码行数:94,代码来源:startbuild.go
示例16: RunStartBuild
// RunStartBuild contains all the necessary functionality for the OpenShift cli start-build command
func RunStartBuild(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, envParams []string, args []string, webhooks util.StringFlag) error {
webhook := cmdutil.GetFlagString(cmd, "from-webhook")
buildName := cmdutil.GetFlagString(cmd, "from-build")
follow := cmdutil.GetFlagBool(cmd, "follow")
commit := cmdutil.GetFlagString(cmd, "commit")
waitForComplete := cmdutil.GetFlagBool(cmd, "wait")
fromFile := cmdutil.GetFlagString(cmd, "from-file")
fromDir := cmdutil.GetFlagString(cmd, "from-dir")
fromRepo := cmdutil.GetFlagString(cmd, "from-repo")
buildLogLevel := cmdutil.GetFlagString(cmd, "build-loglevel")
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 || len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0 {
return cmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments and all '--from-*' flags")
}
path := cmdutil.GetFlagString(cmd, "git-repository")
postReceivePath := cmdutil.GetFlagString(cmd, "git-post-receive")
repo := git.NewRepository()
return RunStartBuildWebHook(f, out, webhook, path, postReceivePath, repo)
case len(args) != 1 && len(buildName) == 0:
return cmdutil.UsageError(cmd, "Must pass a name of a build config or specify build name with '--from-build' flag")
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
var (
name = buildName
resource = "builds"
)
if len(name) == 0 && len(args) > 0 && len(args[0]) > 0 {
mapper, _ := f.Object()
resource, name, err = osutil.ResolveResource("buildconfigs", args[0], mapper)
if err != nil {
return err
}
switch resource {
case "buildconfigs":
// no special handling required
case "builds":
return fmt.Errorf("use --from-build to rerun your builds")
default:
return fmt.Errorf("invalid resource provided: %s", resource)
}
}
if len(name) == 0 {
return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
}
if webhooks.Provided() {
return RunListBuildWebHooks(f, out, cmd.Out(), name, resource, webhooks.String())
}
client, _, err := f.Clients()
if err != nil {
return err
}
env, _, err := ParseEnv(envParams, in)
if err != nil {
return err
}
if len(buildLogLevel) > 0 {
env = append(env, kapi.EnvVar{Name: "BUILD_LOGLEVEL", Value: buildLogLevel})
}
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{Name: name},
}
if len(env) > 0 {
request.Env = env
}
if len(commit) > 0 {
request.Revision = &buildapi.SourceRevision{
Type: buildapi.BuildSourceGit,
Git: &buildapi.GitSourceRevision{
Commit: commit,
},
}
}
git := git.NewRepository()
var newBuild *buildapi.Build
switch {
case len(args) > 0 && (len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0):
request := &buildapi.BinaryBuildRequestOptions{
ObjectMeta: kapi.ObjectMeta{
Name: name,
Namespace: namespace,
},
Commit: commit,
}
if newBuild, err = streamPathToBuild(git, in, cmd.Out(), client.BuildConfigs(namespace), fromDir, fromFile, fromRepo, request); err != nil {
//.........这里部分代码省略.........
开发者ID:Waxolunist,项目名称:origin,代码行数:101,代码来源:startbuild.go
示例17: Complete
func (o *StartBuildOptions) Complete(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, cmdFullName string, args []string) error {
o.In = in
o.Out = out
o.ErrOut = cmd.OutOrStderr()
o.Git = git.NewRepository()
o.ClientConfig = f.OpenShiftClientConfig
o.Mapper, _ = f.Object(false)
webhook := o.FromWebhook
buildName := o.FromBuild
fromFile := o.FromFile
fromDir := o.FromDir
fromRepo := o.FromRepo
buildLogLevel := o.LogLevel
outputFormat := kcmdutil.GetFlagString(cmd, "output")
if outputFormat != "name" && outputFormat != "" {
return kcmdutil.UsageError(cmd, "Unsupported output format: %s", outputFormat)
}
o.ShortOutput = outputFormat == "name"
switch {
case len(webhook) > 0:
if len(args) > 0 || len(buildName) > 0 || len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0 {
return kcmdutil.UsageError(cmd, "The '--from-webhook' flag is incompatible with arguments and all '--from-*' flags")
}
return nil
case len(args) != 1 && len(buildName) == 0:
return kcmdutil.UsageError(cmd, "Must pass a name of a build config or specify build name with '--from-build' flag.\nUse \"%s get bc\" to list all available build configs.", cmdFullName)
}
if len(buildName) != 0 && (len(fromFile) != 0 || len(fromDir) != 0 || len(fromRepo) != 0) {
// TODO: we should support this, it should be possible to clone a build to run again with new uploaded artifacts.
// Doing so requires introducing a new clonebinary endpoint.
return kcmdutil.UsageError(cmd, "Cannot use '--from-build' flag with binary builds")
}
o.AsBinary = len(fromFile) > 0 || len(fromDir) > 0 || len(fromRepo) > 0
namespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
client, _, err := f.Clients()
if err != nil {
return err
}
o.Client = client
var (
name = buildName
resource = buildapi.Resource("builds")
)
if len(name) == 0 && len(args) > 0 && len(args[0]) > 0 {
mapper, _ := f.Object(false)
resource, name, err = cmdutil.ResolveResource(buildapi.Resource("buildconfigs"), args[0], mapper)
if err != nil {
return err
}
switch resource {
case buildapi.Resource("buildconfigs"):
// no special handling required
case buildapi.Resource("builds"):
if len(o.ListWebhooks) == 0 {
return fmt.Errorf("use --from-build to rerun your builds")
}
default:
return fmt.Errorf("invalid resource provided: %v", resource)
}
}
// when listing webhooks, allow --from-build to lookup a build config
if resource == buildapi.Resource("builds") && len(o.ListWebhooks) > 0 {
build, err := client.Builds(namespace).Get(name)
if err != nil {
return err
}
ref := build.Status.Config
if ref == nil {
return fmt.Errorf("the provided Build %q was not created from a BuildConfig and cannot have webhooks", name)
}
if len(ref.Namespace) > 0 {
namespace = ref.Namespace
}
name = ref.Name
}
if len(name) == 0 {
return fmt.Errorf("a resource name is required either as an argument or by using --from-build")
}
o.Namespace = namespace
o.Name = name
env, _, err := cmdutil.ParseEnv(o.Env, in)
if err != nil {
return err
}
if len(buildLogLevel) > 0 {
//.........这里部分代码省略.........
开发者ID:pweil-,项目名称:origin,代码行数:101,代码来源:startbuild.go
示例18: TestDockerfilePath
//.........这里部分代码省略.........
"\"OPENSHIFT_BUILD_COMMIT\"=\"commitid\"",
// expected labels
"\"io.openshift.build.commit.author\"=\"test user \\[email protected]\\u003e\"",
"\"io.openshift.build.commit.date\"=\"date\"",
"\"io.openshift.build.commit.id\"=\"commitid\"",
"\"io.openshift.build.commit.ref\"=\"ref\"",
"\"io.openshift.build.commit.message\"=\"message\"",
}
for _, test := range tests {
buildDir, err := ioutil.TempDir(util.GetBaseDir(), "dockerfile-path")
if err != nil {
t.Errorf("failed to create tmpdir: %v", err)
continue
}
absoluteDockerfilePath := filepath.Join(buildDir, test.contextDir, test.dockerfilePath)
if err = os.MkdirAll(filepath.Dir(absoluteDockerfilePath), os.FileMode(0750)); err != nil {
t.Errorf("failed to create directory %s: %v", filepath.Dir(absoluteDockerfilePath), err)
continue
}
if err = ioutil.WriteFile(absoluteDockerfilePath, []byte(from), os.FileMode(0644)); err != nil {
t.Errorf("failed to write dockerfile to %s: %v", absoluteDockerfilePath, err)
continue
}
build := &api.Build{
Spec: api.BuildSpec{
CommonSpec: api.CommonSpec{
Source: api.BuildSource{
Git: &api.GitBuildSource{
URI: "http://github.com/openshift/origin.git",
},
ContextDir: test.contextDir,
},
Strategy: api.BuildStrategy{
DockerStrategy: test.dockerStrategy,
},
Output: api.BuildOutput{
To: &kapi.ObjectReference{
Kind: "DockerImage",
Name: "test/test-result:latest",
},
},
},
},
}
build.Name = "name"
build.Namespace = "namespace"
sourceInfo := &git.SourceInfo{}
sourceInfo.AuthorName = "test user"
sourceInfo.AuthorEmail = "[email protected]"
sourceInfo.Date = "date"
sourceInfo.CommitID = "commitid"
sourceInfo.Ref = "ref"
sourceInfo.Message = "message"
dockerClient := &FakeDocker{
buildImageFunc: func(opts docker.BuildImageOptions) error {
if opts.Dockerfile != test.dockerfilePath {
t.Errorf("Unexpected dockerfile path: %s (expected: %s)", opts.Dockerfile, test.dockerfilePath)
}
return nil
},
}
dockerBuilder := &DockerBuilder{
dockerClient: dockerClient,
build: build,
gitClient: git.NewRepository(),
tar: tar.New(s2iutil.NewFileSystem()),
}
// this will validate that the Dockerfile is readable
// and append some labels to the Dockerfile
if err = dockerBuilder.addBuildParameters(buildDir, sourceInfo); err != nil {
t.Errorf("failed to add build parameters: %v", err)
continue
}
// check that our Dockerfile has been modified
dockerfileData, err := ioutil.ReadFile(absoluteDockerfilePath)
if err != nil {
t.Errorf("failed to read dockerfile %s: %v", absoluteDockerfilePath, err)
continue
}
for _, value := range expected {
if !strings.Contains(string(dockerfileData), value) {
t.Errorf("Updated Dockerfile content does not contain expected value:\n%s\n\nUpdated content:\n%s\n", value, string(dockerfileData))
}
}
// check that the docker client is called with the right Dockerfile parameter
if err = dockerBuilder.dockerBuild(buildDir, "", []api.SecretBuildSource{}); err != nil {
t.Errorf("failed to build: %v", err)
continue
}
os.RemoveAll(buildDir)
}
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:101,代码来源:docker_test.go
注:本文中的github.com/openshift/origin/pkg/generate/git.NewRepository函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论