bib: check /var/lib/containers/storage when using "--local"
Ensure to error early when the user is not passing the required ``` -v /var/lib/containers/storage:/var/lib/containers/storage ``` when doing a local build.
This commit is contained in:
parent
1bfb930266
commit
280f7626d5
1 changed files with 38 additions and 0 deletions
|
|
@ -3,8 +3,10 @@ package setup
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/moby/sys/mountinfo"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/osbuild/bootc-image-builder/bib/internal/podmanutil"
|
||||
|
|
@ -97,3 +99,39 @@ func Validate() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateHasContainerStorageMounted checks that the container storage
|
||||
// is mounted inside the container
|
||||
func ValidateHasContainerStorageMounted() error {
|
||||
if err := exec.Command("systemd-detect-virt", "-c").Run(); err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
// not running in a container, just exit
|
||||
if exitErr.ExitCode() == 1 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
containersStorage := "/var/lib/containers/storage"
|
||||
containerStorageMountFound := false
|
||||
|
||||
mnts, err := mountinfo.GetMounts(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, mnt := range mnts {
|
||||
if mnt.Mountpoint != containersStorage {
|
||||
continue
|
||||
}
|
||||
containerStorageMountFound = true
|
||||
if mnt.Root != containersStorage {
|
||||
return fmt.Errorf("not the host /var/lib/storage/containers but %q", mnt.Root)
|
||||
}
|
||||
}
|
||||
if !containerStorageMountFound {
|
||||
return fmt.Errorf("cannot find mount for %q", containersStorage)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue