-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow S2I behavior to be overriden by caller #310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"path/filepath" | ||
"regexp" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/golang/glog" | ||
"github.com/openshift/source-to-image/pkg/api" | ||
|
@@ -66,7 +67,7 @@ type STI struct { | |
// 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) (*STI, error) { | ||
func New(req *api.Config, overrides build.Overrides) (*STI, error) { | ||
docker, err := dockerpkg.New(req.DockerConfig, req.PullAuthentication) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -99,13 +100,18 @@ func New(req *api.Config) (*STI, error) { | |
|
||
// The sources are downloaded using the GIT downloader. | ||
// TODO: Add more SCM in future. | ||
b.source, req.Source, err = scm.DownloaderForSource(req.Source) | ||
if err != nil { | ||
return nil, err | ||
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) | ||
b.layered, err = layered.New(req, b, overrides) | ||
|
||
// Set interfaces | ||
b.preparer = b | ||
|
@@ -168,8 +174,10 @@ func (b *STI) Build(config *api.Config) (*api.Result, error) { | |
// struct Build func leverages the STI struct Prepare func directly below | ||
func (b *STI) Prepare(config *api.Config) error { | ||
var err error | ||
if config.WorkingDir, err = b.fs.CreateWorkingDirectory(); err != nil { | ||
return err | ||
if len(config.WorkingDir) == 0 { | ||
if config.WorkingDir, err = b.fs.CreateWorkingDirectory(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
b.result = &api.Result{ | ||
|
@@ -374,18 +382,6 @@ func (b *STI) Execute(command string, config *api.Config) error { | |
|
||
buildEnv := append(scripts.ConvertEnvironment(env), b.generateConfigEnv()...) | ||
|
||
uploadDir := filepath.Join(config.WorkingDir, "upload") | ||
tarFileName, err := b.tar.CreateTarFile(config.WorkingDir, uploadDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tarFile, err := b.fs.Open(tarFileName) | ||
if err != nil { | ||
return err | ||
} | ||
defer tarFile.Close() | ||
|
||
errOutput := "" | ||
outReader, outWriter := io.Pipe() | ||
errReader, errWriter := io.Pipe() | ||
|
@@ -410,8 +406,28 @@ func (b *STI) Execute(command string, config *api.Config) error { | |
Env: buildEnv, | ||
PostExec: b.postExecutor, | ||
} | ||
|
||
if !config.LayeredBuild { | ||
opts.Stdin = tarFile | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
uploadDir := filepath.Join(config.WorkingDir, "upload") | ||
|
||
// TODO: be able to pass a stream directly to the Docker build to avoid the double temp hit | ||
r, w := io.Pipe() | ||
go func() { | ||
var err error | ||
defer func() { | ||
w.CloseWithError(err) | ||
if r := recover(); r != nil { | ||
glog.Errorf("recovered panic: %#v", r) | ||
} | ||
wg.Done() | ||
}() | ||
err = b.tar.CreateTarStream(uploadDir, false, w) | ||
}() | ||
|
||
opts.Stdin = r | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason you can't move all this logic (setting up the stdin stream) above the creation of the RunContainerOptions struct, and populate the opts.Stdin field as part of creating that struct, instead of doing it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess it's a scoping issue. meh. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason would be that stdin is not always set, so you'd need an empty |
||
defer wg.Wait() | ||
} | ||
|
||
go func(reader io.Reader) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,24 @@ import ( | |
) | ||
|
||
// GetStrategy decides what build strategy will be used for the STI build. | ||
// TODO: deprecated, use Strategy() instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason you can't just delete this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concern about other callers and trying to get this in before 3.1 |
||
func GetStrategy(config *api.Config) (build.Builder, error) { | ||
return Strategy(config, build.Overrides{}) | ||
} | ||
|
||
// Strategy creates the appropriate build strategy for the provided config, using | ||
// the overrides provided. Not all strategies support all overrides. | ||
func Strategy(config *api.Config, overrides build.Overrides) (build.Builder, error) { | ||
image, err := GetBuilderImage(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if image.OnBuild { | ||
return onbuild.New(config) | ||
return onbuild.New(config, overrides) | ||
} | ||
|
||
return sti.New(config) | ||
return sti.New(config, overrides) | ||
} | ||
|
||
// GetBuilderImage processes the config and performs operations necessary to make | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is dupe of line 61
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean - if no override is provided, we now create a default downloader and set it. b.source is only set once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you meant 61 in the old file. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i liked the old line 61 better than your new one. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it for you - including saving you from a govet error for anonymous
field declarations
On Mon, Oct 19, 2015 at 5:48 PM, Ben Parees notifications@github.com
wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, now yours is better :)