Skip to content

Commit

Permalink
Merge pull request #15242 from bparees/binary
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Jul 19, 2017
2 parents a5f7000 + 516d521 commit 66d9125
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
14 changes: 12 additions & 2 deletions pkg/generate/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ type BuildRef struct {
DockerStrategyOptions *buildapi.DockerStrategyOptions
Output *ImageRef
Env Environment
Binary bool
}

// BuildConfig creates a buildConfig resource from the build configuration reference
Expand All @@ -266,14 +267,23 @@ func (r *BuildRef) BuildConfig() (*buildapi.BuildConfig, error) {
return nil, err
}

if source.Binary == nil {
if !r.Binary {
configChangeTrigger := buildapi.BuildTriggerPolicy{
Type: buildapi.ConfigChangeBuildTriggerType,
}
triggers = append(triggers, configChangeTrigger)
triggers = append(triggers, strategyTriggers...)
} else {
// remove imagechangetriggers from binary buildconfigs because
// triggered builds will fail (no binary input available)
filteredTriggers := []buildapi.BuildTriggerPolicy{}
for _, trigger := range triggers {
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
filteredTriggers = append(filteredTriggers, trigger)
}
}
triggers = filteredTriggers
}

return &buildapi.BuildConfig{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
59 changes: 59 additions & 0 deletions pkg/generate/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,65 @@ func TestBuildConfigWithSecrets(t *testing.T) {
}
}

func TestBuildConfigBinaryWithImageSource(t *testing.T) {
source := &SourceRef{
Name: "binarybuild",
SourceImage: &ImageRef{
Reference: imageapi.DockerImageReference{
Name: "foo",
Registry: "bar",
},
},
}
build := &BuildRef{Source: source, Binary: true}
config, err := build.BuildConfig()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, trigger := range config.Spec.Triggers {
if trigger.Type == buildapi.ImageChangeBuildTriggerType {
t.Fatalf("binary build should not have any imagechangetriggers")
}
if trigger.Type == buildapi.ConfigChangeBuildTriggerType {
t.Fatalf("binary build should not have a buildconfig change trigger")
}

}
}

func TestBuildConfigWithImageSource(t *testing.T) {
source := &SourceRef{
Name: "binarybuild",
SourceImage: &ImageRef{
Reference: imageapi.DockerImageReference{
Name: "foo",
Registry: "bar",
},
},
}
build := &BuildRef{Source: source, Binary: false}
config, err := build.BuildConfig()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
foundICT := false
foundCCT := false
for _, trigger := range config.Spec.Triggers {
if trigger.Type == buildapi.ImageChangeBuildTriggerType {
foundICT = true
}
if trigger.Type == buildapi.ConfigChangeBuildTriggerType {
foundCCT = true
}
}
if !foundICT {
t.Fatalf("expected to find an imagechangetrigger on the build")
}
if !foundCCT {
t.Fatalf("expected to find a configchangetrigger on the build")
}
}

func TestSourceRefBuildSourceURI(t *testing.T) {
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/generate/app/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (c *AppConfig) buildPipelines(components app.ComponentReferences, environme
}

glog.V(4).Infof("will use %q as the base image for a source build of %q", ref, refInput.Uses)
if pipeline, err = pipelineBuilder.NewBuildPipeline(from, image, refInput.Uses); err != nil {
if pipeline, err = pipelineBuilder.NewBuildPipeline(from, image, refInput.Uses, c.BinaryBuild); err != nil {
return nil, fmt.Errorf("can't build %q: %v", refInput.Uses, err)
}
default:
Expand Down
5 changes: 3 additions & 2 deletions pkg/generate/app/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
type PipelineBuilder interface {
To(string) PipelineBuilder

NewBuildPipeline(string, *ImageRef, *SourceRepository) (*Pipeline, error)
NewBuildPipeline(string, *ImageRef, *SourceRepository, bool) (*Pipeline, error)
NewImagePipeline(string, *ImageRef) (*Pipeline, error)
}

Expand Down Expand Up @@ -61,7 +61,7 @@ func (pb *pipelineBuilder) To(name string) PipelineBuilder {

// NewBuildPipeline creates a new pipeline with components that are expected to
// be built.
func (pb *pipelineBuilder) NewBuildPipeline(from string, input *ImageRef, sourceRepository *SourceRepository) (*Pipeline, error) {
func (pb *pipelineBuilder) NewBuildPipeline(from string, input *ImageRef, sourceRepository *SourceRepository, binary bool) (*Pipeline, error) {
strategy, source, err := StrategyAndSourceForRepository(sourceRepository, input)
if err != nil {
return nil, fmt.Errorf("can't build %q: %v", from, err)
Expand Down Expand Up @@ -124,6 +124,7 @@ func (pb *pipelineBuilder) NewBuildPipeline(from string, input *ImageRef, source
Output: output,
Env: pb.environment,
DockerStrategyOptions: pb.dockerStrategyOptions,
Binary: binary,
}

return &Pipeline{
Expand Down
2 changes: 1 addition & 1 deletion pkg/generate/appjson/appjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (g *Generator) Generate(body []byte) (*templateapi.Template, error) {
image.ObjectName = name
image.Tag = "from"

pipeline, err := app.NewPipelineBuilder(name, nil, nil, false).To(name).NewBuildPipeline(name, image, repo)
pipeline, err := app.NewPipelineBuilder(name, nil, nil, false).To(name).NewBuildPipeline(name, image, repo, false)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 66d9125

Please sign in to comment.