Skip to content

Commit 1a79b1d

Browse files
ondrejbudaimvo5
authored andcommitted
bib: make build the default subcommand
Prior this commit, the bootc-image-builder container image had a custom entrypoint that hardcoded the use of the build subcommand. This meant that if a user wanted to use a different subcommand, they had to overwrite the entrypoint. This commit changes the cobra code in bib to fallback to build if no subcommand was given. This is slighly ugly, but it allows us to remove the custom entrypoint, streamlining the use of subcommands. Let's see an example of calling the version subcommand: Before: podman run --rm -it --entrypoint=/usr/bin/bootc-image-builder \ quay.io/centos-bootc/bootc-image-builder:latest version After: sudo podman run --rm -it \ quay.io/centos-bootc/bootc-image-builder:latest version Kudos to https://github.com/IKukhta for his code from spf13/cobra#823 (comment)
1 parent 835e064 commit 1a79b1d

File tree

7 files changed

+16
-28
lines changed

7 files changed

+16
-28
lines changed

Containerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ COPY ./group_osbuild-osbuild-fedora.repo /etc/yum.repos.d/
1616
COPY ./package-requires.txt .
1717
RUN grep -vE '^#' package-requires.txt | xargs dnf install -y && rm -f package-requires.txt && dnf clean all
1818
COPY --from=builder /build/bin/* /usr/bin/
19-
COPY entrypoint.sh /
2019
COPY bib/data /usr/share/bootc-image-builder
2120

22-
ENTRYPOINT ["/entrypoint.sh"]
21+
ENTRYPOINT ["/usr/bin/bootc-image-builder"]
2322
VOLUME /output
2423
WORKDIR /output
2524
VOLUME /store

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,7 @@ The contents of the file `$(pwd)/wheel-passwordless-sudo` should be
522522

523523
Please report bugs to the [Bug Tracker](https://github.com/osbuild/bootc-image-builder/issues) and include instructions to reproduce and the output of:
524524
```
525-
$ sudo podman run --rm -it --entrypoint=/usr/bin/bootc-image-builder \
526-
quay.io/centos-bootc/bootc-image-builder:latest version
525+
$ sudo podman run --rm -it quay.io/centos-bootc/bootc-image-builder:latest version
527526
```
528527

529528
## 📊 Project

bib/cmd/bootc-image-builder/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,6 @@ func run() error {
623623
buildCmd.Flags().String("output", ".", "artifact output directory")
624624
buildCmd.Flags().String("progress", "text", "type of progress bar to use")
625625
buildCmd.Flags().String("store", "/store", "osbuild store for intermediate pipeline trees")
626-
627626
// flag rules
628627
for _, dname := range []string{"output", "store", "rpmmd"} {
629628
if err := buildCmd.MarkFlagDirname(dname); err != nil {
@@ -635,6 +634,17 @@ func run() error {
635634
}
636635
buildCmd.MarkFlagsRequiredTogether("aws-region", "aws-bucket", "aws-ami-name")
637636

637+
// If no subcommand is given, assume the user wants to use the build subcommand
638+
// See https://github.com/spf13/cobra/issues/823#issuecomment-870027246
639+
// which cannot be used verbatim because the arguments for "build" like
640+
// "quay.io" will create an "err != nil". Ideally we could check err
641+
// for something like cobra.UnknownCommandError but cobra just gives
642+
// us an error string
643+
_, _, err := rootCmd.Find(os.Args[1:])
644+
if err != nil && !slices.Contains([]string{"help", "completion"}, os.Args[1]) {
645+
args := append([]string{buildCmd.Name()}, os.Args[1:]...)
646+
rootCmd.SetArgs(args)
647+
}
638648
return rootCmd.Execute()
639649
}
640650

devel/Containerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ COPY --from=osbuild-builder /build/rpmbuild/RPMS/noarch/*.rpm /rpms/
2727
COPY ./package-requires.txt .
2828
RUN grep -vE '^#' package-requires.txt | xargs dnf install -y && rm -f package-requires.txt && dnf install -y /rpms/*.rpm && dnf clean all
2929
COPY --from=bib-builder /build/bin/bootc-image-builder /usr/bin/bootc-image-builder
30-
COPY entrypoint.sh /entrypoint.sh
3130

32-
ENTRYPOINT ["/entrypoint.sh"]
31+
ENTRYPOINT ["/usr/bin/bootc-image-builder"]
3332
VOLUME /output
3433
WORKDIR /output
3534
VOLUME /store

entrypoint.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/test_manifest.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def find_image_size_from(manifest_str):
3333
def test_manifest_smoke(build_container, tc):
3434
output = subprocess.check_output([
3535
*testutil.podman_run_common,
36-
"--entrypoint=/usr/bin/bootc-image-builder",
3736
build_container,
3837
"manifest",
3938
*tc.bib_rootfs_args(),
@@ -53,7 +52,6 @@ def test_manifest_smoke(build_container, tc):
5352
def test_iso_manifest_smoke(build_container, tc):
5453
output = subprocess.check_output([
5554
*testutil.podman_run_common,
56-
"--entrypoint=/usr/bin/bootc-image-builder",
5755
build_container,
5856
"manifest",
5957
"--type=anaconda-iso", f"{tc.container_ref}",
@@ -82,7 +80,6 @@ def test_manifest_disksize(tmp_path, build_container, tc):
8280
print(f"using {container_tag}")
8381
manifest_str = subprocess.check_output([
8482
*testutil.podman_run_common,
85-
"--entrypoint", "/usr/bin/bootc-image-builder",
8683
build_container,
8784
"manifest", "--local",
8885
*tc.bib_rootfs_args(),
@@ -102,7 +99,6 @@ def test_manifest_local_checks_containers_storage_errors(build_container):
10299
"podman", "run", "--rm",
103100
"--privileged",
104101
"--security-opt", "label=type:unconfined_t",
105-
"--entrypoint=/usr/bin/bootc-image-builder",
106102
build_container,
107103
"manifest", "--local", "arg-not-used",
108104
], check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf8")
@@ -121,7 +117,6 @@ def test_manifest_local_checks_containers_storage_works(tmp_path, build_containe
121117
with make_container(tmp_path) as container_tag:
122118
subprocess.run([
123119
*testutil.podman_run_common,
124-
"--entrypoint=/usr/bin/bootc-image-builder",
125120
build_container,
126121
"manifest", "--local",
127122
*tc.bib_rootfs_args(),
@@ -141,7 +136,6 @@ def test_manifest_cross_arch_check(tmp_path, build_container):
141136
with pytest.raises(subprocess.CalledProcessError) as exc:
142137
subprocess.run([
143138
*testutil.podman_run_common,
144-
"--entrypoint=/usr/bin/bootc-image-builder",
145139
build_container,
146140
"manifest", "--target-arch=aarch64",
147141
"--local", f"localhost/{container_tag}"
@@ -165,7 +159,6 @@ def test_manifest_rootfs_respected(build_container, tc):
165159
# TODO: derive container and fake "bootc install print-configuration"?
166160
output = subprocess.check_output([
167161
*testutil.podman_run_common,
168-
"--entrypoint=/usr/bin/bootc-image-builder",
169162
build_container,
170163
"manifest", f"{tc.container_ref}",
171164
])
@@ -183,7 +176,6 @@ def test_manifest_rootfs_override(build_container):
183176

184177
output = subprocess.check_output([
185178
*testutil.podman_run_common,
186-
"--entrypoint=/usr/bin/bootc-image-builder",
187179
build_container,
188180
"manifest", "--rootfs", "btrfs", f"{container_ref}",
189181
])
@@ -216,7 +208,6 @@ def test_manifest_user_customizations_toml(tmp_path, build_container):
216208
output = subprocess.check_output([
217209
*testutil.podman_run_common,
218210
"-v", f"{config_toml_path}:/config.toml:ro",
219-
"--entrypoint=/usr/bin/bootc-image-builder",
220211
build_container,
221212
"manifest", f"{container_ref}",
222213
])
@@ -243,7 +234,6 @@ def test_manifest_installer_customizations(tmp_path, build_container):
243234
output = subprocess.check_output([
244235
*testutil.podman_run_common,
245236
"-v", f"{config_toml_path}:/config.toml:ro",
246-
"--entrypoint=/usr/bin/bootc-image-builder",
247237
build_container,
248238
"manifest", "--type=anaconda-iso", f"{container_ref}",
249239
])
@@ -297,7 +287,6 @@ def test_mount_ostree_error(tmpdir_factory, build_container):
297287
subprocess.check_output([
298288
*testutil.podman_run_common,
299289
"-v", f"{output_path}:/output",
300-
"--entrypoint=/usr/bin/bootc-image-builder",
301290
build_container,
302291
"manifest", f"{container_ref}",
303292
"--config", "/output/config.json",
@@ -317,8 +306,9 @@ def test_manifest_checks_build_container_is_bootc(build_container, container_ref
317306
def check_image_ref():
318307
subprocess.check_output([
319308
*testutil.podman_run_common,
320-
f'--entrypoint=["/usr/bin/bootc-image-builder", "manifest", "{container_ref}"]',
321309
build_container,
310+
"manifest",
311+
container_ref,
322312
], stderr=subprocess.PIPE, encoding="utf8")
323313
if should_error:
324314
with pytest.raises(subprocess.CalledProcessError) as exc:
@@ -333,7 +323,6 @@ def test_manifest_target_arch_smoke(build_container, tc):
333323
# TODO: actually build an image too
334324
output = subprocess.check_output([
335325
*testutil.podman_run_common,
336-
"--entrypoint=/usr/bin/bootc-image-builder",
337326
build_container,
338327
"manifest",
339328
*tc.bib_rootfs_args(),
@@ -386,7 +375,6 @@ def test_manifest_anaconda_module_customizations(tmpdir_factory, build_container
386375
output = subprocess.check_output([
387376
*testutil.podman_run_common,
388377
"-v", f"{output_path}:/output",
389-
"--entrypoint=/usr/bin/bootc-image-builder",
390378
build_container,
391379
"manifest",
392380
"--config", "/output/config.json",

test/test_opts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def test_bib_help_hides_config(tmp_path, container_storage, build_fake_container
122122
"--security-opt", "label=type:unconfined_t",
123123
"-v", f"{container_storage}:/var/lib/containers/storage",
124124
"-v", f"{output_path}:/output",
125-
"--entrypoint=/usr/bin/bootc-image-builder",
126125
build_fake_container,
127126
"manifest", "--help",
128127
], check=True, capture_output=True, text=True)
@@ -159,7 +158,6 @@ def test_bib_version(tmp_path, container_storage, build_fake_container):
159158
"--security-opt", "label=type:unconfined_t",
160159
"-v", f"{container_storage}:/var/lib/containers/storage",
161160
"-v", f"{output_path}:/output",
162-
"--entrypoint=/usr/bin/bootc-image-builder",
163161
build_fake_container,
164162
"version",
165163
], check=True, capture_output=True, text=True)

0 commit comments

Comments
 (0)