Skip to content

Commit

Permalink
Merge pull request #111 from jeremyrickard/fix-outputs
Browse files Browse the repository at this point in the history
Update the docker driver to return early from fetchOutputs
  • Loading branch information
carolynvs-msft authored Aug 14, 2019
2 parents fc81dbd + eabf76a commit 5f351d2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions driver/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,21 @@ func (d *Driver) exec(op *driver.Operation) (driver.OperationResult, error) {
select {
case err := <-errc:
if err != nil {
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID)
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID, op)
return opResult, containerError("error in container", err, fetchErr)
}
case s := <-statusc:
if s.StatusCode == 0 {
return d.fetchOutputs(ctx, resp.ID)
return d.fetchOutputs(ctx, resp.ID, op)
}
if s.Error != nil {
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID)
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID, op)
return opResult, containerError(fmt.Sprintf("container exit code: %d, message", s.StatusCode), err, fetchErr)
}
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID)
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID, op)
return opResult, containerError(fmt.Sprintf("container exit code: %d, message", s.StatusCode), err, fetchErr)
}
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID)
opResult, fetchErr := d.fetchOutputs(ctx, resp.ID, op)
if fetchErr != nil {
return opResult, fmt.Errorf("fetching outputs failed: %s", fetchErr)
}
Expand All @@ -259,10 +259,16 @@ func containerError(containerMessage string, containerErr, fetchErr error) error
// fetchOutputs takes a context and a container ID; it copies the /cnab/app/outputs directory from that container.
// The goal is to collect all the files in the directory (recursively) and put them in a flat map of path to contents.
// This map will be inside the OperationResult. When fetchOutputs returns an error, it may also return partial results.
func (d *Driver) fetchOutputs(ctx context.Context, container string) (driver.OperationResult, error) {
func (d *Driver) fetchOutputs(ctx context.Context, container string, op *driver.Operation) (driver.OperationResult, error) {
opResult := driver.OperationResult{
Outputs: map[string]string{},
}
// The /cnab/app/outputs directory probably only exists if outputs are created. In the
// case there are no outputs defined on the operation, there probably are none to copy
// and we should return early.
if len(op.Outputs) == 0 {
return opResult, nil
}
ioReader, _, err := d.dockerCli.Client().CopyFromContainer(ctx, container, "/cnab/app/outputs")
if err != nil {
return opResult, fmt.Errorf("error copying outputs from container: %s", err)
Expand Down

0 comments on commit 5f351d2

Please sign in to comment.