Skip to content

Commit

Permalink
Add clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
keimoon committed Jun 25, 2018
1 parent 9b7dd60 commit 0f53eb4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
12 changes: 12 additions & 0 deletions buildtree/buildtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ func (t *BuildTree) FindLatestTag(name string) (string, error) {
})
}

// Clean .
func (t *BuildTree) Clean() {
for _, node := range t.allNodes {
if node.buildRoot != "provided" {
err := utils.DockerRMI(node.name, node.tag)
if err != nil {
utils.PrintError(err)
}
}
}
}

// PrintTree prints the build tree
func (t *BuildTree) PrintTree(noColor bool) {
for _, node := range t.rootNodes {
Expand Down
48 changes: 48 additions & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © 2018 Anduin Transactions Inc
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cmd

import (
"os"

"github.com/anduintransaction/doriath/buildtree"
"github.com/anduintransaction/doriath/utils"
"github.com/spf13/cobra"
)

// cleanCmd represents the clean command
var cleanCmd = &cobra.Command{
Use: "clean",
Short: "Clean all local docker images defined in doriath.yml config file",
Long: "Clean all local docker images defined in doriath.yml config file",
Run: func(cmd *cobra.Command, args []string) {
t, err := buildtree.ReadBuildTreeFromFile(cfgFile, variableMap, variableFiles)
if err != nil {
utils.PrintError(err)
os.Exit(1)
}
t.Clean()
},
}

func init() {
RootCmd.AddCommand(cleanCmd)
}
2 changes: 1 addition & 1 deletion utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Version returns doriath version
func Version() string {
return "1.4.1"
return "1.4.2"
}

// ResolveDir appends a path to a rootDir
Expand Down

0 comments on commit 0f53eb4

Please sign in to comment.