From 86da9e265956a1564b834e74193b31b61c4edbdb Mon Sep 17 00:00:00 2001 From: Toby Corbin Date: Fri, 6 Sep 2019 15:03:31 +0100 Subject: [PATCH 1/3] fix removing of images Signed-off-by: Toby Corbin --- actions/remove.go | 5 ++--- actions/stop-all.go | 16 ++++++++-------- utils/docker.go | 10 +++++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/actions/remove.go b/actions/remove.go index 0844d03c..7f6471e6 100644 --- a/actions/remove.go +++ b/actions/remove.go @@ -22,17 +22,16 @@ import ( //RemoveCommand to remove all codewind and project images func RemoveCommand(c *cli.Context) { tag := c.String("tag") - imageArr := [5]string{} + imageArr := [4]string{} imageArr[0] = "eclipse/codewind-pfe" imageArr[1] = "eclipse/codewind-performance" imageArr[2] = "eclipse/codewind-initialize" imageArr[3] = "cw-" - imageArr[4] = "appsody" networkName := "codewind" if tag != "" { for i := 0; i < len(imageArr); i++ { - if i == 3 || i == 4 { + if i == 3 { break } imageArr[i] = imageArr[i] + "-amd64:" + tag diff --git a/actions/stop-all.go b/actions/stop-all.go index 3082ddc8..eaee9a26 100644 --- a/actions/stop-all.go +++ b/actions/stop-all.go @@ -20,24 +20,24 @@ import ( //StopAllCommand to stop codewind and project containers func StopAllCommand() { - containerArr := [2]string{} + containerArr := [4]string{} containerArr[0] = "codewind-pfe" containerArr[1] = "codewind-performance" - containerArr[0] = "cw-" - containerArr[1] = "appsody" + containerArr[2] = "cw-" + containerArr[3] = "appsody" containers := utils.GetContainerList() fmt.Println("Stopping Codewind and Project containers") for _, container := range containers { for _, key := range containerArr { + fmt.Println(" container ", container.Names[0], "key ", key) if strings.HasPrefix(container.Image, key) { - fmt.Println(container) - // stop appsody containers with "cw-" in their name, and all other cw containers - if key != "appsody" || strings.Contains(container.Names[0], "cw-") { - fmt.Println("Stopping container ", container.Names, "... ") + //if strings.(container.Names[0], "cw-") { + fmt.Println("Stopping container ", container.Names[0], "... ") utils.StopContainer(container) - } + break + //} } } } diff --git a/utils/docker.go b/utils/docker.go index 6a583246..303c225f 100644 --- a/utils/docker.go +++ b/utils/docker.go @@ -291,9 +291,13 @@ func StopContainer(container types.Container) { errors.CheckErr(err, 108, "") } - // Remove the container so it isnt lingering in the background - if err := cli.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{}); err != nil { - errors.CheckErr(err, 108, "") + // Do not attempt to remove appsody images as that happens automatically + // when an appsody container stops + if !strings.HasPrefix(container.Image, "appsody") { + // Remove the container so it isnt lingering in the background + if err := cli.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{}); err != nil { + errors.CheckErr(err, 108, "") + } } } From 470a8eee6a2a8bfaed0b4240f30e302655977c4e Mon Sep 17 00:00:00 2001 From: Toby Corbin Date: Fri, 6 Sep 2019 15:06:00 +0100 Subject: [PATCH 2/3] Update stop-all.go --- actions/stop-all.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/actions/stop-all.go b/actions/stop-all.go index eaee9a26..4e114a83 100644 --- a/actions/stop-all.go +++ b/actions/stop-all.go @@ -31,13 +31,10 @@ func StopAllCommand() { fmt.Println("Stopping Codewind and Project containers") for _, container := range containers { for _, key := range containerArr { - fmt.Println(" container ", container.Names[0], "key ", key) if strings.HasPrefix(container.Image, key) { - //if strings.(container.Names[0], "cw-") { - fmt.Println("Stopping container ", container.Names[0], "... ") - utils.StopContainer(container) - break - //} + fmt.Println("Stopping container ", container.Names[0], "... ") + utils.StopContainer(container) + break } } } From c8dbd2bbf198ebdad6eec93ce6851c3bf7573433 Mon Sep 17 00:00:00 2001 From: Toby Corbin Date: Fri, 6 Sep 2019 15:28:59 +0100 Subject: [PATCH 3/3] add further check for the container name --- actions/stop-all.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/actions/stop-all.go b/actions/stop-all.go index 4e114a83..6b5649dc 100644 --- a/actions/stop-all.go +++ b/actions/stop-all.go @@ -32,9 +32,11 @@ func StopAllCommand() { for _, container := range containers { for _, key := range containerArr { if strings.HasPrefix(container.Image, key) { - fmt.Println("Stopping container ", container.Names[0], "... ") - utils.StopContainer(container) + if key != "appsody" || strings.Contains(container.Names[0], "cw-") { + fmt.Println("Stopping container ", container.Names[0], "... ") + utils.StopContainer(container) break + } } } }