feat: remove dangling or unused images from local storage after build
This commit is contained in:
		| @@ -35,6 +35,8 @@ var Commands []config.DockerCommand | |||||||
|  |  | ||||||
| var UseCache = true | var UseCache = true | ||||||
|  |  | ||||||
|  | var Prune = true | ||||||
|  |  | ||||||
| type Image struct { | type Image struct { | ||||||
| 	Name   string | 	Name   string | ||||||
| 	Distro distro.Distro | 	Distro distro.Distro | ||||||
| @@ -231,7 +233,16 @@ func (c Container) Build(image string, envs, runs []string) (err error) { | |||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (c Container) prune() error { | ||||||
|  | 	c.Log.Debug().Msg("remove dangling or unused images from local storage") | ||||||
|  | 	return exec.Command(Runtime, "image", "prune", "-f").Run() | ||||||
|  | } | ||||||
|  |  | ||||||
| func (c Container) build(imagePath string) (output string, err error) { | func (c Container) build(imagePath string) (output string, err error) { | ||||||
|  | 	if Prune { | ||||||
|  | 		defer c.prune() | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	args := []string{"build"} | 	args := []string{"build"} | ||||||
| 	if !UseCache { | 	if !UseCache { | ||||||
| 		args = append(args, "--pull", "--no-cache") | 		args = append(args, "--pull", "--no-cache") | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								kernel.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								kernel.go
									
									
									
									
									
								
							| @@ -31,6 +31,7 @@ type KernelCmd struct { | |||||||
| 	Threads    int  `help:"threads for parallel installation" default:"1"` | 	Threads    int  `help:"threads for parallel installation" default:"1"` | ||||||
| 	Update     bool `help:"update container"` | 	Update     bool `help:"update container"` | ||||||
| 	Max        int  `help:"maximum kernels to download" default:"100500"` | 	Max        int  `help:"maximum kernels to download" default:"100500"` | ||||||
|  | 	NoPrune    bool `help:"do not remove dangling or unused images from local storage after build"` | ||||||
|  |  | ||||||
| 	ContainerTimeout time.Duration `help:"container timeout"` | 	ContainerTimeout time.Duration `help:"container timeout"` | ||||||
|  |  | ||||||
| @@ -157,6 +158,9 @@ func (cmd *KernelCmd) Generate(g *Globals, km config.Target) (err error) { | |||||||
| 	if cmd.Update { | 	if cmd.Update { | ||||||
| 		container.UseCache = false | 		container.UseCache = false | ||||||
| 	} | 	} | ||||||
|  | 	if cmd.NoPrune { | ||||||
|  | 		container.Prune = false | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	cmd.kcfg, err = config.ReadKernelConfig(g.Config.Kernels) | 	cmd.kcfg, err = config.ReadKernelConfig(g.Config.Kernels) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -246,6 +250,13 @@ type KernelListRemoteCmd struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (cmd *KernelListRemoteCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) { | func (cmd *KernelListRemoteCmd) Run(kernelCmd *KernelCmd, g *Globals) (err error) { | ||||||
|  | 	if kernelCmd.Update { | ||||||
|  | 		container.UseCache = false | ||||||
|  | 	} | ||||||
|  | 	if kernelCmd.NoPrune { | ||||||
|  | 		container.Prune = false | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	distroType, err := distro.NewID(cmd.Distro) | 	distroType, err := distro.NewID(cmd.Distro) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return | 		return | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user