bib/internal/setup: validate container tags early
Check that the container has the expected bootc tags early and fail if they are missing.
This commit is contained in:
parent
4fa4ad34a0
commit
2a89cb6739
2 changed files with 25 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
|
@ -148,3 +149,17 @@ func validateCanRunTargetArch(targetArch string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValidateHasContainerTags(imgref string) error {
|
||||||
|
output, err := exec.Command("podman", "image", "inspect", imgref, "--format", "{{.Labels}}").Output()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed inspect image: %w", util.OutputErr(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
tags := string(output)
|
||||||
|
if !strings.Contains(tags, "containers.bootc:1") {
|
||||||
|
return fmt.Errorf("image %s is not a bootc image", imgref)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,3 +61,13 @@ func TestValidateCanRunTargetArchUnexpectedOutput(t *testing.T) {
|
||||||
err := setup.ValidateCanRunTargetArch("fakearch")
|
err := setup.ValidateCanRunTargetArch("fakearch")
|
||||||
assert.ErrorContains(t, err, `internal error: unexpected output`)
|
assert.ErrorContains(t, err, `internal error: unexpected output`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateTags(t *testing.T) {
|
||||||
|
imageref := "quay.io/centos-bootc/centos-bootc:stream9"
|
||||||
|
err := setup.ValidateHasContainerTags(imageref)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
badImageRef := "quay.io/centos/centos:stream9"
|
||||||
|
err = setup.ValidateHasContainerTags(badImageRef)
|
||||||
|
assert.ErrorContains(t, err, "image quay.io/centos/centos:stream9 is not a bootc image")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue