Skip to content

Commit

Permalink
bib: rename --config to --iso-config
Browse files Browse the repository at this point in the history
Rename the --config option to --iso-config and error if it is
used for anything other than the ISO image.
  • Loading branch information
mvo5 committed Mar 26, 2024
1 parent ed3eb6f commit 1648936
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
19 changes: 12 additions & 7 deletions bib/cmd/bootc-image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func manifestFromCobra(cmd *cobra.Command, args []string) ([]byte, error) {
}

imgref := args[0]
configFile, _ := cmd.Flags().GetString("config")
isoConfigFile, _ := cmd.Flags().GetString("iso-config")
imgTypes, _ := cmd.Flags().GetStringArray("type")
rpmCacheRoot, _ := cmd.Flags().GetString("rpmmd")
targetArch, _ := cmd.Flags().GetString("target-arch")
Expand All @@ -262,11 +262,16 @@ func manifestFromCobra(cmd *cobra.Command, args []string) ([]byte, error) {
return nil, err
}

// bootc does not yet support arbitray blueprint customizations
if buildType != BuildTypeISO && isoConfigFile != "" {
return nil, fmt.Errorf("the --iso-config switch is only supported for ISO images")
}

var config *BuildConfig
if configFile != "" {
config, err = loadConfig(configFile)
if isoConfigFile != "" {
config, err = loadConfig(isoConfigFile)
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot load config: %w", err)
}
} else {
config = &BuildConfig{}
Expand Down Expand Up @@ -351,7 +356,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
fmt.Printf("Generating manifest %s\n", manifest_fname)
mf, err := manifestFromCobra(cmd, args)
if err != nil {
panic(err)
return err
}
fmt.Print("DONE\n")

Expand Down Expand Up @@ -468,7 +473,7 @@ func run() error {
}
rootCmd.AddCommand(manifestCmd)
manifestCmd.Flags().Bool("tls-verify", true, "require HTTPS and verify certificates when contacting registries")
manifestCmd.Flags().String("config", "", "build config file")
manifestCmd.Flags().String("iso-config", "", "build config file for the iso")
manifestCmd.Flags().String("rpmmd", "/rpmmd", "rpm metadata cache directory")
manifestCmd.Flags().String("target-arch", "", "build for the given target architecture (experimental)")
manifestCmd.Flags().StringArray("type", []string{"qcow2"}, fmt.Sprintf("image types to build [%s]", allImageTypesString()))
Expand All @@ -492,7 +497,7 @@ func run() error {
return err
}
}
if err := buildCmd.MarkFlagFilename("config"); err != nil {
if err := buildCmd.MarkFlagFilename("iso-config"); err != nil {
return err
}
buildCmd.MarkFlagsRequiredTogether("aws-region", "aws-bucket", "aws-ami-name")
Expand Down
39 changes: 39 additions & 0 deletions test/test_opts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import sys

import pytest

Expand Down Expand Up @@ -27,3 +28,41 @@ def test_bib_chown_opts(tmp_path, build_fake_container, chown_opt, expected_uid_
assert p.exists()
assert p.stat().st_uid == expected_uid_gid[0]
assert p.stat().st_gid == expected_uid_gid[1]


def test_bib_config_errors_for_default(tmp_path, build_fake_container):
output_path = tmp_path / "output"
output_path.mkdir(exist_ok=True)

ret = subprocess.run([
"podman", "run", "--rm",
"--privileged",
"--security-opt", "label=type:unconfined_t",
"-v", f"{output_path}:/output",
build_fake_container,
"--iso-config", "/some/random/config",
"quay.io/centos-bootc/centos-bootc:stream9",
], check=False, encoding="utf8", stdout=sys.stdout, stderr=subprocess.PIPE)
assert ret.returncode != 0
assert "the --iso-config switch is only supported for ISO images" in ret.stderr


def test_bib_iso_config_is_parsed(tmp_path, build_fake_container):
output_path = tmp_path / "output"
output_path.mkdir(exist_ok=True)

# check that config.json is tried to be loaded
(tmp_path / "config.json").write_text("invalid-json", encoding="utf8")
ret = subprocess.run([
"podman", "run", "--rm",
"--privileged",
"--security-opt", "label=type:unconfined_t",
"-v", f"{output_path}:/output",
"-v", f"{tmp_path}/config.json:/config.json",
build_fake_container,
"--iso-config", "/config.json",
"--type", "anaconda-iso",
"quay.io/centos-bootc/centos-bootc:stream9",
], check=False, encoding="utf8", stdout=sys.stdout, stderr=subprocess.PIPE)
assert ret.returncode != 0
assert "cannot load config: invalid character" in ret.stderr

0 comments on commit 1648936

Please sign in to comment.