fix searching for the container id
All checks were successful
Declarative Tests / test (push) Successful in 50s
All checks were successful
Declarative Tests / test (push) Successful in 50s
This commit is contained in:
parent
6af91dec6c
commit
dc85c45226
@ -12,7 +12,7 @@ _ "os"
|
|||||||
_ "gopkg.in/yaml.v3"
|
_ "gopkg.in/yaml.v3"
|
||||||
_ "os/exec"
|
_ "os/exec"
|
||||||
_ "strings"
|
_ "strings"
|
||||||
"log"
|
"log/slog"
|
||||||
"github.com/docker/docker/api/types/strslice"
|
"github.com/docker/docker/api/types/strslice"
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
@ -199,13 +199,14 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) {
|
|||||||
All: true,
|
All: true,
|
||||||
Filters: filterArgs,
|
Filters: filterArgs,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("%w: %s %s", err, c.Type(), c.Name))
|
panic(fmt.Errorf("%w: %s %s", err, c.Type(), c.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
for _, containerName := range container.Names {
|
for _, containerName := range container.Names {
|
||||||
if containerName == c.Name {
|
if containerName == "/" + c.Name {
|
||||||
containerID = container.ID
|
containerID = container.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +218,9 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) {
|
|||||||
} else {
|
} else {
|
||||||
c.State = "present"
|
c.State = "present"
|
||||||
c.Id = containerJSON.ID
|
c.Id = containerJSON.ID
|
||||||
c.Name = containerJSON.Name
|
if c.Name == "" {
|
||||||
|
c.Name = containerJSON.Name
|
||||||
|
}
|
||||||
c.Path = containerJSON.Path
|
c.Path = containerJSON.Path
|
||||||
c.Image = containerJSON.Image
|
c.Image = containerJSON.Image
|
||||||
if containerJSON.State != nil {
|
if containerJSON.State != nil {
|
||||||
@ -231,6 +234,7 @@ func (c *Container) Read(ctx context.Context) ([]byte, error) {
|
|||||||
c.RestartCount = containerJSON.RestartCount
|
c.RestartCount = containerJSON.RestartCount
|
||||||
c.Driver = containerJSON.Driver
|
c.Driver = containerJSON.Driver
|
||||||
}
|
}
|
||||||
|
slog.Info("Read() ", "type", c.Type(), "name", c.Name, "Id", c.Id)
|
||||||
return yaml.Marshal(c)
|
return yaml.Marshal(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +245,7 @@ func (c *Container) Delete(ctx context.Context) error {
|
|||||||
Force: false,
|
Force: false,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to remove: %s\n", c.Id)
|
slog.Error("Failed to remove: ", "Id", c.Id)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user