-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added cache command & improved TAR file generation
- Loading branch information
Christophe VILA
committed
Jun 26, 2020
1 parent
b8d4f36
commit 58ccf80
Showing
7 changed files
with
202 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# Release Notes | ||
|
||
## Version 3.0 - 03/16/2020 | ||
## Version 1.0.1 - 06/26/2020 | ||
* Added cache command to list and clean the containerd docker images cache | ||
* Generated TAR only contains the extracted images for the chart, instead of all the images contained in the cache | ||
|
||
## Version 1.0 - 06/20/2020 | ||
* First delivery on Github. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/containerd/containerd/namespaces" | ||
"github.com/gemalto/helm-image/internal/containerd" | ||
"github.com/spf13/cobra" | ||
"io" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
type cacheCmd struct { | ||
debug bool | ||
verbose bool | ||
} | ||
|
||
func newCacheListCmd(out io.Writer, c *cacheCmd) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "list", | ||
Short: "list docker images from local cache", | ||
Long: "list docker images from local cache", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.list() | ||
}, | ||
} | ||
} | ||
|
||
func newCacheCleanCmd(out io.Writer, c *cacheCmd) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "clean", | ||
Short: "remove all docker images from local cache", | ||
Long: "remove all docker images from local cache", | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.clean() | ||
}, | ||
} | ||
} | ||
|
||
func newCacheCmd(out io.Writer) *cobra.Command { | ||
c := &cacheCmd{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "cache", | ||
Short: "manage local cache of docker images", | ||
Long: "manage local cache of docker images", | ||
SilenceUsage: true, | ||
} | ||
|
||
cmd.AddCommand( | ||
newCacheListCmd(out, c), | ||
newCacheCleanCmd(out, c), | ||
) | ||
|
||
cmd.PersistentFlags().BoolVarP(&c.verbose, "verbose", "v", false, "enable verbose output") | ||
|
||
// When called through helm, debug mode is transmitted through the HELM_DEBUG envvar | ||
helmDebug := os.Getenv("HELM_DEBUG") | ||
if helmDebug == "1" || strings.EqualFold(helmDebug, "true") || strings.EqualFold(helmDebug, "on") { | ||
c.debug = true | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *cacheCmd) list() error { | ||
serverStarted := make(chan bool) | ||
serverKill := make(chan bool) | ||
serverKilled := make(chan bool) | ||
go containerd.Server(serverStarted, serverKill, serverKilled, c.debug) | ||
if !<-serverStarted { | ||
return fmt.Errorf("cannot start containerd server") | ||
} | ||
interrupt := make(chan os.Signal) | ||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-interrupt | ||
if c.debug { | ||
log.Println("Sending interrupt signal to containerd server...") | ||
} | ||
serverKill <- true | ||
<-serverKilled | ||
}() | ||
client, err := containerd.Client(c.debug) | ||
if err != nil { | ||
if c.debug { | ||
log.Println("Sending interrupt signal to containerd server...") | ||
} | ||
serverKill <- true | ||
<-serverKilled | ||
return err | ||
} | ||
ctx := namespaces.WithNamespace(context.Background(), "default") | ||
err = containerd.ListImages(ctx, client) | ||
if err != nil { | ||
if c.debug { | ||
log.Println("Sending interrupt signal to containerd server...") | ||
} | ||
serverKill <- true | ||
<-serverKilled | ||
return err | ||
} | ||
if c.debug { | ||
log.Println("Sending interrupt signal to containerd server...") | ||
} | ||
serverKill <- true | ||
<-serverKilled | ||
return nil | ||
} | ||
|
||
func (c *cacheCmd) clean() error { | ||
return containerd.DeleteContainerdDirectories() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters