Skip to content

Commit

Permalink
driver: docker-compose, action: run: fix a bug when handling a signal…
Browse files Browse the repository at this point in the history
…, when no default container
  • Loading branch information
xmik committed Jan 4, 2020
1 parent e046b08 commit 407a956
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Implemented Ctrl+C (SigInt) to work for action: run for both drivers (docker and docker-compose).
The change in the run action for docker-compose driver is that now Dojo first explicitly invokes the pull action
and then it invokes the run action.
* Driver: docker-compose, action: run: fix a bug when handling a signal. Previously, when default container was
not (yet) created, there was a panic. But, it may happen that the default container is not created while
other containers are created. From now on, Dojo will not panic and it will stop the other containers.

### 0.8.0 (2020-Jan-01)

Expand Down
5 changes: 4 additions & 1 deletion docker_compose_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ func (dc DockerComposeDriver) HandleSignal(mergedConfig Config, runID string) in
}

defaultContainerID := dc.getDefaultContainerID(names)
// it may happen that the default container is not created, but other containers are
es := dc.stop(mergedConfig, runID, defaultContainerID)
dc.Logger.Log("info", "Stopping on signal finished")
return es
Expand Down Expand Up @@ -568,6 +569,7 @@ func (dc DockerComposeDriver) HandleMultipleSignal(mergedConfig Config, runID st
}

defaultContainerID := dc.getDefaultContainerID(names)
// it may happen that the default container is not created, but other containers are
es := dc.kill(mergedConfig, runID, defaultContainerID)
dc.Logger.Log("info", "Stopping on multiple signals finished")
return es
Expand All @@ -588,7 +590,8 @@ func (dc DockerComposeDriver) getDefaultContainerID(containersNames []string) st
return contanerInfo.ID
}
}
panic(fmt.Errorf("default container not found. Were the containers created?"))
dc.Logger.Log("info", "Default container not found")
return ""
}

// example output of docker-compose ps:
Expand Down
6 changes: 0 additions & 6 deletions docker_compose_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,9 @@ func Test_getDefaultContainerID_notCreated(t *testing.T) {
shellS := NewMockedShellServiceNotInteractive(logger)
driver := NewDockerComposeDriver(shellS, fs, logger)

defer func() {
r := recover()
assert.Contains(t, r.(error).Error(), "default container not found. Were the containers created?")
}()

names := []string{}
id := driver.getDefaultContainerID(names)
assert.Equal(t, "", id)
t.Fatal("Expected panic")
}

func Test_checkContainerIsRunning(t *testing.T) {
Expand Down

0 comments on commit 407a956

Please sign in to comment.