Skip to content

Commit

Permalink
Update the docker driver to return early from fetchOutputs if there a…
Browse files Browse the repository at this point in the history
…re no outputs

defined on the operation. If there are none defined on the operation, there is
a good chance /cnab/app/outputs won't exist and we shouldn't try to copy from it.

If they do exist, we should continue and if it doesn't exist that is a failure case
with that invocation image.
  • Loading branch information
jeremyrickard committed Aug 13, 2019
1 parent 1ef7d96 commit eabf76a
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 eabf76a

Please sign in to comment.