Skip to content

Commit 664e527

Browse files
committed
Add function to inspect and pull the image
To use BIB we will need to also inpect images and pull them if required. So, let's make a function to take care of this task instead of copy-paste the same code. I think we should go back to have a podman pkg, it will make it easier in the future to switch between remote and local podman. Signed-off-by: German Maglione <[email protected]>
1 parent 5001fd9 commit 664e527

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

pkg/bootc/bootc_disk.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/containers/podman-bootc/pkg/utils"
1919

2020
"github.com/containers/podman/v5/pkg/bindings/containers"
21-
"github.com/containers/podman/v5/pkg/bindings/images"
2221
"github.com/containers/podman/v5/pkg/domain/entities/types"
2322
"github.com/containers/podman/v5/pkg/specgen"
2423
"github.com/docker/go-units"
@@ -277,32 +276,17 @@ func (p *BootcDisk) bootcInstallImageToDisk(quiet bool, diskConfig DiskImageConf
277276
}
278277

279278
// pullImage fetches the container image if not present
280-
func (p *BootcDisk) pullImage() (err error) {
281-
pullPolicy := "missing"
282-
ids, err := images.Pull(p.Ctx, p.ImageNameOrId, &images.PullOptions{Policy: &pullPolicy})
279+
func (p *BootcDisk) pullImage() error {
280+
imageData, err := utils.PullAndInspect(p.Ctx, p.ImageNameOrId)
283281
if err != nil {
284-
return fmt.Errorf("failed to pull image: %w", err)
285-
}
286-
287-
if len(ids) == 0 {
288-
return fmt.Errorf("no ids returned from image pull")
289-
}
290-
291-
if len(ids) > 1 {
292-
return fmt.Errorf("multiple ids returned from image pull")
293-
}
294-
295-
image, err := images.GetImage(p.Ctx, p.ImageNameOrId, &images.GetOptions{})
296-
if err != nil {
297-
return fmt.Errorf("failed to get image: %w", err)
282+
return err
298283
}
299-
p.imageData = image
300284

301-
imageId := ids[0]
302-
p.ImageId = imageId
303-
p.RepoTag = image.RepoTags[0]
285+
p.imageData = imageData
286+
p.ImageId = imageData.ID
287+
p.RepoTag = imageData.RepoTags[0]
304288

305-
return
289+
return nil
306290
}
307291

308292
// runInstallContainer runs the bootc installer in a container to create a disk image

pkg/utils/podman.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"github.com/containers/podman/v5/pkg/bindings/images"
9+
"github.com/containers/podman/v5/pkg/domain/entities/types"
810
"os"
911
"os/exec"
1012
"strings"
@@ -28,6 +30,22 @@ type machineInfo struct {
2830
rootful bool
2931
}
3032

33+
// PullAndInspect inpects the image, pulling in if the image if required
34+
func PullAndInspect(ctx context.Context, imageNameOrId string) (*types.ImageInspectReport, error) {
35+
pullPolicy := "missing"
36+
_, err := images.Pull(ctx, imageNameOrId, &images.PullOptions{Policy: &pullPolicy})
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to pull image: %w", err)
39+
}
40+
41+
imageInfo, err := images.GetImage(ctx, imageNameOrId, &images.GetOptions{})
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to inspect image: %w", err)
44+
}
45+
46+
return imageInfo, nil
47+
}
48+
3149
func GetMachineContext() (*MachineContext, error) {
3250
//podman machine connection
3351
machineInfo, err := getMachineInfo()

0 commit comments

Comments
 (0)