Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions pkg/build/builder/cmd/builder.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cmd

import (
"log"
"os"

"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/build/api"
bld "github.com/openshift/origin/pkg/build/builder"
Expand All @@ -29,34 +29,40 @@ type factoryFunc func(
func run(builderFactory factoryFunc) {
client, endpoint, err := dockerutil.NewHelper().GetClient()
if err != nil {
log.Fatalf("Error obtaining docker client: %v", err)
glog.Fatalf("Error obtaining docker client: %v", err)
}
buildStr := os.Getenv("BUILD")
build := api.Build{}
if err := latest.Codec.DecodeInto([]byte(buildStr), &build); err != nil {
log.Fatalf("Unable to parse build: %v", err)
glog.Fatalf("Unable to parse build: %v", err)
}

var (
authcfg docker.AuthConfiguration
authPresent bool
)
output := true
if len(build.Parameters.Output.DockerImageReference) == 0 {
if build.Parameters.Output.To != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this condition you'll still end build when To is not defined and if I understood @smarterclayton correctly he wanted to have no output defined at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if Output.To==nil we'll fall through to "output=false" but still run the build, which is as desired.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K

log.Fatalf("Cannot determine an output image reference. Make sure a registry service is running.")
glog.Fatalf("Cannot determine an output image reference. Make sure a registry service is running.")
}
log.Fatal("Build output has an empty Docker image reference.")
output = false
}
registry, _, _, _, err := image.SplitDockerPullSpec(build.Parameters.Output.DockerImageReference)
if err != nil {
log.Fatalf("Build output does not have a valid Docker image reference: %v", err)
if output {
registry, _, _, _, err := image.SplitDockerPullSpec(build.Parameters.Output.DockerImageReference)
if err != nil {
glog.Fatalf("Build output does not have a valid Docker image reference: %v", err)
}
authcfg, authPresent = dockercfg.NewHelper().GetDockerAuth(registry)
}
authcfg, authPresent = dockercfg.NewHelper().GetDockerAuth(registry)

b := builderFactory(client, endpoint, authcfg, authPresent, &build)
if err = b.Build(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STI build will fail here, since not passing the name of the output image which is required (see sti.go#34).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the tests results does not show this, I guess this is related to a problem we don't validate Request object upon Build in STI. That validation is done only in here - created issue sti/#144.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we pass the name, so we're missing a TC for this one, please 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you better make the output optional when that loophole gets fixed. what sort of a test case are you asking for? an origin test case that runs sti-type builds w/ no output defined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the issue openshift/source-to-image#146, I'll be working on PR for that, so you can assign me to that bug.
And yes, I've meant some kind of origin TC to stress test that situation.

log.Fatalf("Build error: %v", err)
glog.Fatalf("Build error: %v", err)
}
if !output {
glog.Warning("Build does not have an Output defined, no output image was pushed to a registry.")
}

}

// RunDockerBuild creates a docker builder and runs its build
Expand Down