Skip to content

Commit

Permalink
Gracefully shut down container when we want logs (#392)
Browse files Browse the repository at this point in the history
This gives the container a chance to flush out any pending logs,
otherwise we can end up with truncated logs.
  • Loading branch information
erikjohnston authored Jun 10, 2022
1 parent 6d086c4 commit 2503a6d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/docker/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,23 @@ func (d *Deployer) Deploy(ctx context.Context, blueprintName string) (*Deploymen
func (d *Deployer) Destroy(dep *Deployment, printServerLogs bool) {
for _, hsDep := range dep.HS {
if printServerLogs {
// If we want the logs we gracefully stop the containers to allow
// the logs to be flushed.
timeout := 1 * time.Second
err := d.Docker.ContainerStop(context.Background(), hsDep.ContainerID, &timeout)
if err != nil {
log.Printf("Destroy: Failed to destroy container %s : %s\n", hsDep.ContainerID, err)
}

printLogs(d.Docker, hsDep.ContainerID, hsDep.ContainerID)
} else {
err := d.Docker.ContainerKill(context.Background(), hsDep.ContainerID, "KILL")
if err != nil {
log.Printf("Destroy: Failed to destroy container %s : %s\n", hsDep.ContainerID, err)
}
}
err := d.Docker.ContainerKill(context.Background(), hsDep.ContainerID, "KILL")
if err != nil {
log.Printf("Destroy: Failed to destroy container %s : %s\n", hsDep.ContainerID, err)
}
err = d.Docker.ContainerRemove(context.Background(), hsDep.ContainerID, types.ContainerRemoveOptions{

err := d.Docker.ContainerRemove(context.Background(), hsDep.ContainerID, types.ContainerRemoveOptions{
Force: true,
})
if err != nil {
Expand Down

0 comments on commit 2503a6d

Please sign in to comment.