当前位置: 首页>>代码示例>>Golang>>正文


Golang app.NewSourceRepositoryForDockerfile函数代码示例

本文整理汇总了Golang中github.com/openshift/origin/pkg/generate/app.NewSourceRepositoryForDockerfile函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSourceRepositoryForDockerfile函数的具体用法?Golang NewSourceRepositoryForDockerfile怎么用?Golang NewSourceRepositoryForDockerfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewSourceRepositoryForDockerfile函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addDockerfile

// addDockerfile adds a Dockerfile passed in the command line to the reference
// builder.
func (c *AppConfig) addDockerfile() error {
	if len(c.Strategy) != 0 && c.Strategy != "docker" {
		return fmt.Errorf("when directly referencing a Dockerfile, the strategy must must be 'docker'")
	}
	_, repos, errs := c.refBuilder.Result()
	if err := errors.NewAggregate(errs); err != nil {
		return err
	}
	switch len(repos) {
	case 0:
		// Create a new SourceRepository with the Dockerfile.
		repo, err := app.NewSourceRepositoryForDockerfile(c.Dockerfile)
		if err != nil {
			return fmt.Errorf("provided Dockerfile is not valid: %v", err)
		}
		c.refBuilder.AddExistingSourceRepository(repo)
	case 1:
		// Add the Dockerfile to the existing SourceRepository, so that
		// eventually we generate a single BuildConfig with multiple
		// sources.
		if err := repos[0].AddDockerfile(c.Dockerfile); err != nil {
			return fmt.Errorf("provided Dockerfile is not valid: %v", err)
		}
	default:
		// Invalid.
		return fmt.Errorf("--dockerfile cannot be used with multiple source repositories")
	}
	return nil
}
开发者ID:arielcarrera,项目名称:origin,代码行数:31,代码来源:newapp.go

示例2: AddDockerfileToSourceRepositories

// AddDockerfile adds a Dockerfile passed in the command line to the reference
// builder.
func AddDockerfileToSourceRepositories(b *app.ReferenceBuilder, dockerfile string) error {
	_, repos, errs := b.Result()
	if err := kutilerrors.NewAggregate(errs); err != nil {
		return err
	}
	switch len(repos) {
	case 0:
		// Create a new SourceRepository with the Dockerfile.
		repo, err := app.NewSourceRepositoryForDockerfile(dockerfile)
		if err != nil {
			return fmt.Errorf("provided Dockerfile is not valid: %v", err)
		}
		b.AddExistingSourceRepository(repo)
	case 1:
		// Add the Dockerfile to the existing SourceRepository, so that
		// eventually we generate a single BuildConfig with multiple
		// sources.
		if err := repos[0].AddDockerfile(dockerfile); err != nil {
			return fmt.Errorf("provided Dockerfile is not valid: %v", err)
		}
	default:
		// Invalid.
		return errors.New("--dockerfile cannot be used with multiple source repositories")
	}
	return nil
}
开发者ID:pweil-,项目名称:origin,代码行数:28,代码来源:resolve.go

示例3: TestDisallowedNonNumericExposedPorts

func TestDisallowedNonNumericExposedPorts(t *testing.T) {
	tests := []struct {
		strategy             generate.Strategy
		allowNonNumericPorts bool
	}{
		{
			strategy:             generate.StrategyUnspecified,
			allowNonNumericPorts: false,
		},
		{
			strategy:             generate.StrategyDocker,
			allowNonNumericPorts: false,
		},
	}

	for _, test := range tests {
		config := &AppConfig{}
		config.Strategy = test.strategy
		config.AllowNonNumericExposedPorts = test.allowNonNumericPorts

		repo, err := app.NewSourceRepositoryForDockerfile("FROM centos\nARG PORT=80\nEXPOSE 8080 $PORT")
		if err != nil {
			t.Fatalf("Unexpected error during setup: %v", err)
		}
		repos := app.SourceRepositories{repo}

		err = optionallyValidateExposedPorts(config, repos)
		if err == nil {
			t.Error("Expected error wasn't returned")

		} else if !strings.Contains(err.Error(), "invalid EXPOSE") || !strings.Contains(err.Error(), "must be numeric") {
			t.Errorf("Unexpected error: %v", err)
		}
	}
}
开发者ID:nak3,项目名称:origin,代码行数:35,代码来源:newapp_test.go

示例4: TestAllowedNonNumericExposedPorts

func TestAllowedNonNumericExposedPorts(t *testing.T) {
	tests := []struct {
		strategy             generate.Strategy
		allowNonNumericPorts bool
	}{
		{
			strategy:             generate.StrategyUnspecified,
			allowNonNumericPorts: true,
		},
		{
			strategy:             generate.StrategySource,
			allowNonNumericPorts: false,
		},
	}

	for _, test := range tests {
		config := &AppConfig{}
		config.Strategy = test.strategy
		config.AllowNonNumericExposedPorts = test.allowNonNumericPorts

		repo, err := app.NewSourceRepositoryForDockerfile("FROM centos\nARG PORT=80\nEXPOSE $PORT")
		if err != nil {
			t.Errorf("Unexpected error during setup: %v", err)
			continue
		}
		repos := app.SourceRepositories{repo}

		err = optionallyValidateExposedPorts(config, repos)
		if err != nil {
			t.Errorf("Unexpected error: %v", err)
		}
	}
}
开发者ID:nak3,项目名称:origin,代码行数:33,代码来源:newapp_test.go

示例5: TestDisallowedNonNumericExposedPorts

func TestDisallowedNonNumericExposedPorts(t *testing.T) {
	config := &AppConfig{}
	config.Strategy = "docker"
	config.AllowNonNumericExposedPorts = false

	repo, err := app.NewSourceRepositoryForDockerfile("FROM centos\nARG PORT=80\nEXPOSE 8080 $PORT")
	if err != nil {
		t.Fatalf("Unexpected error during setup: %v", err)
	}
	repos := app.SourceRepositories{repo}

	err = optionallyValidateExposedPorts(config, repos)
	if err == nil {
		t.Error("Expected error wasn't returned")

	} else if !strings.Contains(err.Error(), "invalid EXPOSE") || !strings.Contains(err.Error(), "must be numeric") {
		t.Errorf("Unexpected error: %v", err)
	}
}
开发者ID:thrasher-redhat,项目名称:origin,代码行数:19,代码来源:newapp_test.go

示例6: individualSourceRepositories

// individualSourceRepositories collects the list of SourceRepositories specified in the
// command line that are not associated with a builder using a '~'.
func (c *AppConfig) individualSourceRepositories() (app.SourceRepositories, error) {
	first := true
	for _, s := range c.SourceRepositories {
		if repo, ok := c.refBuilder.AddSourceRepository(s); ok && first {
			repo.SetContextDir(c.ContextDir)
			first = false
		}
	}
	if len(c.Dockerfile) > 0 {
		switch {
		case c.Strategy == "docker", len(c.Strategy) == 0:
		default:
			return nil, fmt.Errorf("when directly referencing a Dockerfile, the strategy must must be 'docker'")
		}
		repo, err := app.NewSourceRepositoryForDockerfile(c.Dockerfile)
		if err != nil {
			return nil, fmt.Errorf("provided Dockerfile is not valid: %v", err)
		}
		c.refBuilder.AddExistingSourceRepository(repo)
	}
	_, repos, errs := c.refBuilder.Result()
	return repos, errors.NewAggregate(errs)
}
开发者ID:rettori,项目名称:origin,代码行数:25,代码来源:newapp.go


注:本文中的github.com/openshift/origin/pkg/generate/app.NewSourceRepositoryForDockerfile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。