This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
/
remove.go
108 lines (94 loc) · 2.77 KB
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package actions
import (
"fmt"
"os"
"strings"
"github.com/eclipse/codewind-installer/pkg/docker"
"github.com/eclipse/codewind-installer/pkg/remote"
logr "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
//RemoveCommand to remove all codewind and project images
func RemoveCommand(c *cli.Context, dockerComposeFile string) {
tag := c.String("tag")
if tag == "" {
tag = "latest"
}
imageArr := []string{
"cw-",
}
dockerClient, dockerErr := docker.NewDockerClient()
if dockerErr != nil {
HandleDockerError(dockerErr)
os.Exit(1)
}
images, err := docker.GetImageList(dockerClient)
if err != nil {
HandleDockerError(err)
os.Exit(1)
}
fmt.Println("Removing Codewind docker images..")
for _, image := range images {
imageRepo := strings.Join(image.RepoDigests, " ")
imageTags := strings.Join(image.RepoTags, " ")
for _, key := range imageArr {
if strings.HasPrefix(imageRepo, key) || strings.HasPrefix(imageTags, key) {
if len(image.RepoTags) > 0 {
fmt.Println("Deleting Image ", image.RepoTags[0], "... ")
} else {
fmt.Println("Deleting Image ", image.ID, "... ")
}
docker.RemoveImage(image.ID)
}
}
}
dockerErr = docker.DockerComposeRemove(dockerComposeFile, tag)
if dockerErr != nil {
HandleDockerError(dockerErr)
os.Exit(1)
}
}
// DoRemoteRemove : Delete a remote Codewind deployment
func DoRemoteRemove(c *cli.Context) {
removeOptions := remote.RemoveDeploymentOptions{
Namespace: c.String("namespace"),
WorkspaceID: c.String("workspace"),
}
_, remInstError := remote.RemoveRemote(&removeOptions)
if remInstError != nil {
if printAsJSON {
fmt.Println(remInstError.Error())
} else {
logr.Errorf("Error: %v - %v\n", remInstError.Op, remInstError.Desc)
}
os.Exit(1)
}
os.Exit(0)
}
// DoRemoteKeycloakRemove : Delete a remote Keycloak deployment
func DoRemoteKeycloakRemove(c *cli.Context) {
removeOptions := remote.RemoveDeploymentOptions{
Namespace: c.String("namespace"),
WorkspaceID: c.String("workspace"),
}
_, remInstError := remote.RemoveRemoteKeycloak(&removeOptions)
if remInstError != nil {
if printAsJSON {
fmt.Println(remInstError.Error())
} else {
logr.Errorf("Error: %v - %v\n", remInstError.Op, remInstError.Desc)
}
os.Exit(1)
}
os.Exit(0)
}