Skip to content

Commit c70c528

Browse files
committed
Revert "Fixing rm command and API…"
This reverts commit 26edba0. Conflicts: docker/container.go
1 parent fb4bf10 commit c70c528

File tree

5 files changed

+15
-112
lines changed

5 files changed

+15
-112
lines changed

cli/app/app.go

+3-19
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,10 @@ func ProjectPull(p *project.Project, c *cli.Context) {
163163

164164
// ProjectDelete delete services.
165165
func ProjectDelete(p *project.Project, c *cli.Context) {
166-
stoppedContainers, err := p.ListStoppedContainers(c.Args()...)
167-
if err != nil {
168-
logrus.Fatal(err)
169-
}
170-
if len(stoppedContainers) == 0 {
171-
fmt.Println("No stopped containers")
172-
return
173-
}
174-
if !c.Bool("force") {
175-
fmt.Printf("Going to remove %v\nAre you sure? [yN]\n", strings.Join(stoppedContainers, ", "))
176-
var answer string
177-
_, err := fmt.Scanln(&answer)
178-
if err != nil {
179-
logrus.Fatal(err)
180-
}
181-
if answer != "y" && answer != "Y" {
182-
return
183-
}
166+
if !c.Bool("force") && len(c.Args()) == 0 {
167+
logrus.Fatal("Will not remove all services without --force")
184168
}
185-
err = p.Delete(c.Args()...)
169+
err := p.Delete(c.Args()...)
186170
if err != nil {
187171
logrus.Fatal(err)
188172
}

docker/container.go

-15
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,6 @@ func (c *Container) Delete() error {
230230
return nil
231231
}
232232

233-
// IsRunning returns the running state of the container.
234-
func (c *Container) IsRunning() (bool, error) {
235-
container, err := c.findExisting()
236-
if err != nil || container == nil {
237-
return false, err
238-
}
239-
240-
info, err := c.client.ContainerInspect(container.ID)
241-
if err != nil {
242-
return false, err
243-
}
244-
245-
return info.State.Running, nil
246-
}
247-
248233
// Up creates and start the container based on the image name and send an event
249234
// to notify the container has been created. If the container exists but is stopped
250235
// it tries to start it.

integration/rm_test.go

+12-44
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,17 @@ func (s *RunSuite) TestDelete(c *C) {
1515
c.Assert(cn, NotNil)
1616
c.Assert(cn.State.Running, Equals, true)
1717

18-
s.FromText(c, p, "stop", SimpleTemplate)
19-
s.FromText(c, p, "rm", "--force", SimpleTemplate)
18+
s.FromText(c, p, "rm", "--force", `
19+
hello:
20+
image: busybox
21+
stdin_open: true
22+
tty: true
23+
`)
2024

2125
cn = s.GetContainerByName(c, name)
2226
c.Assert(cn, IsNil)
2327
}
2428

25-
func (s *RunSuite) TestDeleteOnlyRemovesStopped(c *C) {
26-
projectTemplate := `
27-
hello:
28-
image: busybox
29-
stdin_open: true
30-
tty: true
31-
bye:
32-
image: busybox
33-
stdin_open: true
34-
tty: true
35-
`
36-
37-
p := s.ProjectFromText(c, "up", projectTemplate)
38-
39-
helloName := fmt.Sprintf("%s_%s_1", p, "hello")
40-
byeName := fmt.Sprintf("%s_%s_1", p, "bye")
41-
42-
helloContainer := s.GetContainerByName(c, helloName)
43-
c.Assert(helloContainer, NotNil)
44-
c.Assert(helloContainer.State.Running, Equals, true)
45-
46-
byeContainer := s.GetContainerByName(c, byeName)
47-
c.Assert(byeContainer, NotNil)
48-
c.Assert(byeContainer.State.Running, Equals, true)
49-
50-
s.FromText(c, p, "stop", "bye", projectTemplate)
51-
52-
byeContainer = s.GetContainerByName(c, byeName)
53-
c.Assert(byeContainer, NotNil)
54-
c.Assert(byeContainer.State.Running, Equals, false)
55-
56-
s.FromText(c, p, "rm", "--force", projectTemplate)
57-
58-
byeContainer = s.GetContainerByName(c, byeName)
59-
c.Assert(byeContainer, IsNil)
60-
61-
helloContainer = s.GetContainerByName(c, helloName)
62-
c.Assert(helloContainer, NotNil)
63-
}
64-
6529
func (s *RunSuite) TestDeleteWithVol(c *C) {
6630
p := s.ProjectFromText(c, "up", SimpleTemplate)
6731

@@ -71,8 +35,12 @@ func (s *RunSuite) TestDeleteWithVol(c *C) {
7135
c.Assert(cn, NotNil)
7236
c.Assert(cn.State.Running, Equals, true)
7337

74-
s.FromText(c, p, "stop", SimpleTemplate)
75-
s.FromText(c, p, "rm", "--force", "-v", SimpleTemplate)
38+
s.FromText(c, p, "rm", "--force", "-v", `
39+
hello:
40+
image: busybox
41+
stdin_open: true
42+
tty: true
43+
`)
7644

7745
cn = s.GetContainerByName(c, name)
7846
c.Assert(cn, IsNil)

project/project.go

-33
Original file line numberDiff line numberDiff line change
@@ -239,39 +239,6 @@ func (p *Project) Pull(services ...string) error {
239239
}), nil)
240240
}
241241

242-
// ListStoppedContainers lists the stopped containers for the specified services.
243-
func (p *Project) ListStoppedContainers(services ...string) ([]string, error) {
244-
stoppedContainers := []string{}
245-
err := p.forEach(services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) {
246-
wrapper.Do(nil, EventServiceDeleteStart, EventServiceDelete, func(service Service) error {
247-
containers, innerErr := service.Containers()
248-
if innerErr != nil {
249-
return innerErr
250-
}
251-
252-
for _, container := range containers {
253-
running, innerErr := container.IsRunning()
254-
if innerErr != nil {
255-
log.Error(innerErr)
256-
}
257-
if !running {
258-
containerID, innerErr := container.ID()
259-
if innerErr != nil {
260-
log.Error(innerErr)
261-
}
262-
stoppedContainers = append(stoppedContainers, containerID)
263-
}
264-
}
265-
266-
return nil
267-
})
268-
}), nil)
269-
if err != nil {
270-
return nil, err
271-
}
272-
return stoppedContainers, nil
273-
}
274-
275242
// Delete removes the specified services (like docker rm).
276243
func (p *Project) Delete(services ...string) error {
277244
return p.perform(EventProjectDeleteStart, EventProjectDeleteDone, services, wrapperAction(func(wrapper *serviceWrapper, wrappers map[string]*serviceWrapper) {

project/types.go

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ type Container interface {
268268
ID() (string, error)
269269
Name() string
270270
Port(port string) (string, error)
271-
IsRunning() (bool, error)
272271
}
273272

274273
// ServiceFactory is an interface factory to create Service object for the specified

0 commit comments

Comments
 (0)