composeContainerPrintableTab constructs composeContainerPrintable with fields only for console output.
(ctx context.Context, container containerd.Container, gOptions types.GlobalCommandOptions)
| 235 | // composeContainerPrintableTab constructs composeContainerPrintable with fields |
| 236 | // only for console output. |
| 237 | func composeContainerPrintableTab(ctx context.Context, container containerd.Container, gOptions types.GlobalCommandOptions) (composeContainerPrintable, error) { |
| 238 | info, err := container.Info(ctx, containerd.WithoutRefreshedMetadata) |
| 239 | if err != nil { |
| 240 | return composeContainerPrintable{}, err |
| 241 | } |
| 242 | spec, err := container.Spec(ctx) |
| 243 | if err != nil { |
| 244 | return composeContainerPrintable{}, err |
| 245 | } |
| 246 | status := formatter.ContainerStatus(ctx, container) |
| 247 | if status == "Up" { |
| 248 | status = "running" // corresponds to Docker Compose v2.0.1 |
| 249 | } |
| 250 | image, err := container.Image(ctx) |
| 251 | if err != nil { |
| 252 | return composeContainerPrintable{}, err |
| 253 | } |
| 254 | dataStore, err := clientutil.DataStore(gOptions.DataRoot, gOptions.Address) |
| 255 | if err != nil { |
| 256 | return composeContainerPrintable{}, err |
| 257 | } |
| 258 | containerLabels, err := container.Labels(ctx) |
| 259 | if err != nil { |
| 260 | return composeContainerPrintable{}, err |
| 261 | } |
| 262 | ports, err := portutil.LoadPortMappings(dataStore, gOptions.Namespace, info.ID, containerLabels) |
| 263 | if err != nil { |
| 264 | return composeContainerPrintable{}, err |
| 265 | } |
| 266 | |
| 267 | return composeContainerPrintable{ |
| 268 | Name: info.Labels[labels.Name], |
| 269 | Image: image.Metadata().Name, |
| 270 | Command: formatter.InspectContainerCommandTrunc(spec), |
| 271 | Service: info.Labels[labels.ComposeService], |
| 272 | State: status, |
| 273 | Ports: formatter.FormatPorts(ports), |
| 274 | }, nil |
| 275 | } |
| 276 | |
| 277 | // composeContainerPrintableJSON constructs composeContainerPrintable with fields |
| 278 | // only for json output and compatible docker output. |
no test coverage detected
searching dependent graphs…