Skip to content

Commit

Permalink
docker.container: always return resource
Browse files Browse the repository at this point in the history
fixes #343
  • Loading branch information
ryane committed Oct 5, 2016
1 parent f084f0b commit bf553bf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions resource/docker/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ type Container struct {

// Check that a docker container with the specified configuration exists
func (c *Container) Check(resource.Renderer) (resource.TaskStatus, error) {
c.Status = resource.NewStatus()
if c.Status == nil {
c.Status = resource.NewStatus()
}
container, err := c.client.FindContainer(c.Name)
if err != nil {
c.Status.Level = resource.StatusFatal
Expand All @@ -85,6 +87,9 @@ func (c *Container) Check(resource.Renderer) (resource.TaskStatus, error) {

// Apply starts a docker container with the specified configuration
func (c *Container) Apply() (resource.TaskStatus, error) {
if c.Status == nil {
c.Status = resource.NewStatus()
}
volumes, binds := volumeConfigs(c.Volumes)
config := &dc.Config{
Image: c.Image,
Expand Down Expand Up @@ -113,13 +118,13 @@ func (c *Container) Apply() (resource.TaskStatus, error) {

container, err := c.client.CreateContainer(opts)
if err != nil {
return nil, errors.Wrapf(err, "failed to run container %s", c.Name)
return c, err
}

if c.CStatus == "" || c.CStatus == containerStatusRunning {
err = c.client.StartContainer(c.Name, container.ID)
if err != nil {
return nil, errors.Wrapf(err, "failed to start container %s", c.Name)
return c, err
}
}

Expand Down

0 comments on commit bf553bf

Please sign in to comment.