mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
fixes for Linux
This commit is contained in:
parent
a1924cf1e6
commit
046d70e16c
2 changed files with 61 additions and 13 deletions
BIN
lazypodman
BIN
lazypodman
Binary file not shown.
|
|
@ -36,8 +36,7 @@ func (r *LibpodRuntime) Mode() string {
|
||||||
// Close shuts down the libpod runtime.
|
// Close shuts down the libpod runtime.
|
||||||
func (r *LibpodRuntime) Close() error {
|
func (r *LibpodRuntime) Close() error {
|
||||||
if r.runtime != nil {
|
if r.runtime != nil {
|
||||||
_, err := r.runtime.Shutdown(false)
|
return r.runtime.Shutdown(false)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +135,7 @@ func (r *LibpodRuntime) ContainerTop(ctx context.Context, id string) ([]string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
// Top returns []string where each string is a line (header + processes)
|
||||||
result, err := ctr.Top([]string{})
|
result, err := ctr.Top([]string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
@ -143,12 +143,19 @@ func (r *LibpodRuntime) ContainerTop(ctx context.Context, id string) ([]string,
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
return result[0], result[1:], nil
|
// Parse the result: first line is headers, rest are process rows
|
||||||
|
// Each line is space-separated fields
|
||||||
|
headers := splitFields(result[0])
|
||||||
|
var processes [][]string
|
||||||
|
for _, line := range result[1:] {
|
||||||
|
processes = append(processes, splitFields(line))
|
||||||
|
}
|
||||||
|
return headers, processes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PruneContainers removes all stopped containers.
|
// PruneContainers removes all stopped containers.
|
||||||
func (r *LibpodRuntime) PruneContainers(ctx context.Context) error {
|
func (r *LibpodRuntime) PruneContainers(ctx context.Context) error {
|
||||||
_, err := r.runtime.PruneContainers(ctx, nil)
|
_, err := r.runtime.PruneContainers(nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,8 +246,15 @@ func (r *LibpodRuntime) RemoveImage(ctx context.Context, id string, force bool)
|
||||||
|
|
||||||
// PruneImages removes unused images.
|
// PruneImages removes unused images.
|
||||||
func (r *LibpodRuntime) PruneImages(ctx context.Context) error {
|
func (r *LibpodRuntime) PruneImages(ctx context.Context) error {
|
||||||
_, err := r.runtime.LibimageRuntime().PruneImages(ctx, nil)
|
// RemoveImages with no names and dangling=true filter prunes dangling images
|
||||||
return err
|
opts := &libimage.RemoveImagesOptions{
|
||||||
|
Filters: []string{"dangling=true"},
|
||||||
|
}
|
||||||
|
_, errs := r.runtime.LibimageRuntime().RemoveImages(ctx, nil, opts)
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return errs[0]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volume operations
|
// Volume operations
|
||||||
|
|
@ -283,14 +297,16 @@ func (r *LibpodRuntime) ListNetworks(ctx context.Context) ([]NetworkSummary, err
|
||||||
|
|
||||||
// RemoveNetwork removes a network.
|
// RemoveNetwork removes a network.
|
||||||
func (r *LibpodRuntime) RemoveNetwork(ctx context.Context, name string) error {
|
func (r *LibpodRuntime) RemoveNetwork(ctx context.Context, name string) error {
|
||||||
_, err := r.runtime.Network().NetworkRemove(name)
|
return r.runtime.Network().NetworkRemove(name)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PruneNetworks removes unused networks.
|
// PruneNetworks removes unused networks.
|
||||||
|
// Note: libnetwork doesn't have a direct prune method, so we skip this for now.
|
||||||
|
// Proper implementation would require checking which networks are in use.
|
||||||
func (r *LibpodRuntime) PruneNetworks(ctx context.Context) error {
|
func (r *LibpodRuntime) PruneNetworks(ctx context.Context) error {
|
||||||
_, err := r.runtime.Network().NetworkPrune(nil)
|
// NetworkPrune is not available in libnetwork interface
|
||||||
return err
|
// TODO: Implement manual pruning by listing networks and checking usage
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events streams container runtime events.
|
// Events streams container runtime events.
|
||||||
|
|
@ -366,6 +382,12 @@ func convertLibpodContainerInspect(data *define.InspectContainerData) *Container
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get LogPath from HostConfig.LogConfig if available
|
||||||
|
logPath := ""
|
||||||
|
if data.HostConfig != nil && data.HostConfig.LogConfig != nil {
|
||||||
|
logPath = data.HostConfig.LogConfig.Path
|
||||||
|
}
|
||||||
|
|
||||||
details := &ContainerDetails{
|
details := &ContainerDetails{
|
||||||
ID: data.ID,
|
ID: data.ID,
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
|
|
@ -377,7 +399,7 @@ func convertLibpodContainerInspect(data *define.InspectContainerData) *Container
|
||||||
ResolvConfPath: data.ResolvConfPath,
|
ResolvConfPath: data.ResolvConfPath,
|
||||||
HostnamePath: data.HostnamePath,
|
HostnamePath: data.HostnamePath,
|
||||||
HostsPath: data.HostsPath,
|
HostsPath: data.HostsPath,
|
||||||
LogPath: data.LogPath,
|
LogPath: logPath,
|
||||||
RestartCount: int(data.RestartCount),
|
RestartCount: int(data.RestartCount),
|
||||||
Driver: data.Driver,
|
Driver: data.Driver,
|
||||||
MountLabel: data.MountLabel,
|
MountLabel: data.MountLabel,
|
||||||
|
|
@ -402,9 +424,15 @@ func convertLibpodContainerInspect(data *define.InspectContainerData) *Container
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Config != nil {
|
if data.Config != nil {
|
||||||
|
// OnBuild is *string in Podman, convert to []string for our interface
|
||||||
|
var onBuild []string
|
||||||
|
if data.Config.OnBuild != nil && *data.Config.OnBuild != "" {
|
||||||
|
onBuild = []string{*data.Config.OnBuild}
|
||||||
|
}
|
||||||
|
|
||||||
details.Config = &ContainerConfig{
|
details.Config = &ContainerConfig{
|
||||||
Hostname: data.Config.Hostname,
|
Hostname: data.Config.Hostname,
|
||||||
Domainname: data.Config.Domainname,
|
Domainname: data.Config.DomainName,
|
||||||
User: data.Config.User,
|
User: data.Config.User,
|
||||||
AttachStdin: data.Config.AttachStdin,
|
AttachStdin: data.Config.AttachStdin,
|
||||||
AttachStdout: data.Config.AttachStdout,
|
AttachStdout: data.Config.AttachStdout,
|
||||||
|
|
@ -417,7 +445,7 @@ func convertLibpodContainerInspect(data *define.InspectContainerData) *Container
|
||||||
Image: data.Config.Image,
|
Image: data.Config.Image,
|
||||||
WorkingDir: data.Config.WorkingDir,
|
WorkingDir: data.Config.WorkingDir,
|
||||||
Entrypoint: data.Config.Entrypoint,
|
Entrypoint: data.Config.Entrypoint,
|
||||||
OnBuild: data.Config.OnBuild,
|
OnBuild: onBuild,
|
||||||
Labels: data.Config.Labels,
|
Labels: data.Config.Labels,
|
||||||
StopSignal: data.Config.StopSignal,
|
StopSignal: data.Config.StopSignal,
|
||||||
}
|
}
|
||||||
|
|
@ -539,3 +567,23 @@ func convertLibpodNetworkList(nets []nettypes.Network) []NetworkSummary {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// splitFields splits a string by whitespace into fields.
|
||||||
|
func splitFields(s string) []string {
|
||||||
|
var fields []string
|
||||||
|
var field []rune
|
||||||
|
for _, r := range s {
|
||||||
|
if r == ' ' || r == '\t' {
|
||||||
|
if len(field) > 0 {
|
||||||
|
fields = append(fields, string(field))
|
||||||
|
field = nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
field = append(field, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(field) > 0 {
|
||||||
|
fields = append(fields, string(field))
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue