Skip to content

system-reinstall-bootc: fallback image from /usr/lib/os-release#2135

Open
hone wants to merge 2 commits intobootc-dev:mainfrom
hone:default-image-os-release
Open

system-reinstall-bootc: fallback image from /usr/lib/os-release#2135
hone wants to merge 2 commits intobootc-dev:mainfrom
hone:default-image-os-release

Conversation

@hone
Copy link
Copy Markdown
Contributor

@hone hone commented Apr 9, 2026

Add a fallback option when arguments are specified for an image. It works in this order:

  1. BOOTC_REINSTALL_CONFIG env var to a YAML file
  2. --image flag
  3. reads /etc/os-release for BOOTC_IMAGE
  4. reads /usr/lib/os-release for BOOTC_IMAGE

Fixes: #1300

@github-actions github-actions Bot added the area/system-reinstall-bootc Issues related to system-reinstall-botoc label Apr 9, 2026
@hone hone marked this pull request as draft April 9, 2026 16:53
@bootc-bot bootc-bot Bot requested a review from jmarrero April 9, 2026 16:53
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fallback mechanism to retrieve the bootc image from os-release files when not specified via CLI or environment variables. The changes include a new parsing module, refactored argument handling, and updated CI scripts. Feedback suggests parsing CLI arguments earlier to support standard flags like --help, filtering empty strings during os-release lookups for better fallback reliability, and consolidating redundant CI steps.

Comment thread crates/system-reinstall-bootc/src/main.rs
Comment thread crates/system-reinstall-bootc/src/main.rs Outdated
Comment thread crates/system-reinstall-bootc/src/main.rs Outdated
Comment thread tmt/plans/integration.fmf
Comment on lines +28 to +39
order: 97
script:
- mkdir -p bootc && cp /var/share/test-artifacts/*.src.rpm bootc
- cd bootc && rpm2cpio *.src.rpm | cpio -idmv && rm -f *-vendor.tar.zstd && zstd -d *.tar.zstd && tar -xvf *.tar -C . --strip-components=1 && ls -al
- pwd && ls -al && cd bootc/hack && ./provision-packit.sh
when: running_env != image_mode
- how: shell
order: 98
script:
- echo 'BOOTC_IMAGE=localhost/bootc' | tee -a /usr/lib/os-release
- pwd && ls -al && cd bootc/hack && ./provision-packit.sh
when: running_env != image_mode
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two shell steps are redundant and inefficient. Both steps perform the same setup and run provision-packit.sh, which includes a time-consuming podman build operation. Since provision-packit.sh is already designed to handle both the explicit argument and the os-release fallback, you should combine these into a single step to avoid rebuilding the image and repeating the setup in CI.

    order: 97
    script:
      - mkdir -p bootc && cp /var/share/test-artifacts/*.src.rpm bootc
      - cd bootc && rpm2cpio *.src.rpm | cpio -idmv && rm -f *-vendor.tar.zstd && zstd -d *.tar.zstd && tar -xvf *.tar -C . --strip-components=1 && ls -al
      - pwd && ls -al && cd bootc/hack && ./provision-packit.sh
      - echo 'BOOTC_IMAGE=localhost/bootc' | tee -a /usr/lib/os-release
      - ./provision-packit.sh
    when: running_env != image_mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was easier to just build the image twice than try to do a cleanup step for testing the BOOTC_IMAGE path on reinstall.

@hone
Copy link
Copy Markdown
Contributor Author

hone commented Apr 9, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to automatically detect the bootc image from os-release files (/etc/os-release or /usr/lib/os-release) if not provided via the CLI. It also adds logic to automatically inherit host SSH keys when cloud-init is detected in the target image. Key changes include a new os_release module for parsing, updates to the CLI argument handling, and integration test adjustments. Feedback highlights a critical path error where a container-internal path is used as a host path for SSH key inheritance, potential inefficiencies and failures in the updated test plan, and an opportunity to refactor the image resolution logic for better maintainability.

Comment thread crates/system-reinstall-bootc/src/main.rs Outdated
Comment thread tmt/plans/integration.fmf
Comment thread crates/system-reinstall-bootc/src/main.rs Outdated
@hone hone force-pushed the default-image-os-release branch from 5bb1c1e to ee263a3 Compare April 9, 2026 22:43
@hone hone marked this pull request as ready for review April 10, 2026 06:06
@hone hone force-pushed the default-image-os-release branch from a168777 to a21dcba Compare April 10, 2026 16:49
Copy link
Copy Markdown
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for working on this!

continue;
}

if let Some((key, value)) = line.split_once('=') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit, also could be let/else here and avoid further nesting

Comment on lines +24 to +30
if value.starts_with('"') && value.ends_with('"') && value.len() >= 2 {
let unquoted = &value[1..value.len() - 1];
let processed = unquoted
.replace(r#"\""#, "\"")
.replace(r#"\\"#, "\\")
.replace(r#"\$"#, "$")
.replace(r#"\`"#, "`");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use shlex to parse this, it's already in the depchain

.iter()
.find_map(|path| {
os_release::get_bootc_image_from_file(path)
.ok()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally avoid "error swallowing" like this. There's two different cases:

}

#[context("image_has_cloud_init")]
pub(crate) fn image_has_cloud_init(image: &str) -> Result<bool> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bootc-dev/bcvk#245 we're proposing to standardize labels on images that have Ignition, it could make sense to do the same for cloud-init.

Separate effort from this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already an issue for that?

Comment thread crates/system-reinstall-bootc/src/main.rs Outdated
@hone
Copy link
Copy Markdown
Contributor Author

hone commented Apr 13, 2026

How concerned should I be about these packit failures?

@jeckersb
Copy link
Copy Markdown
Collaborator

How concerned should I be about these packit failures?

The s390x build ones at least can be ignored for now, there's a known issue with those.

@hone hone requested a review from cgwalters April 14, 2026 04:20
@hone hone force-pushed the default-image-os-release branch from 9bb1f27 to c8cc3f2 Compare April 18, 2026 01:13
@jmarrero
Copy link
Copy Markdown
Contributor

jmarrero commented Apr 21, 2026

Thank you again for this. This needs another run of: cargo fmt which CI is complaining about and commits should be squashed. We tend to keep commits functionally grouped, if it's addressing reviews just add it to the main commit that touched that file.

@hone
Copy link
Copy Markdown
Contributor Author

hone commented Apr 23, 2026

Thank you again for this. This needs another run of: cargo fmt which CI is complaining about and commits should be squashed. We tend to keep commits functionally grouped, if it's addressing reviews just add it to the main commit that touched that file.

@jmarrero happy to do that. Before I squash, should I split out the ssh authorized keys pieces or keep it in this PR?

@jmarrero
Copy link
Copy Markdown
Contributor

jmarrero commented Apr 23, 2026

Thank you again for this. This needs another run of: cargo fmt which CI is complaining about and commits should be squashed. We tend to keep commits functionally grouped, if it's addressing reviews just add it to the main commit that touched that file.

@jmarrero happy to do that. Before I squash, should I split out the ssh authorized keys pieces or keep it in this PR?

Yes, I would move the ssh stuff to it's own PR where we will have some additional discussions on it. The background here is that we are not 100% sure yet if we can assume the target image has cloud-init and we might want to support checking for ignition or/and cloud init on the distributions we maintain. There is some uncertainty of assuming this still. When the issue was created I think were more certain about cloud-init vs ignition.

@hone hone force-pushed the default-image-os-release branch 2 times, most recently from c2827c9 to 8a9b9d4 Compare April 23, 2026 23:15
hone added 2 commits April 23, 2026 18:29
Add a fallback option when arguments are specified for an image. It
works in this order:
  1. BOOTC_REINSTALL_CONFIG env var to a YAML file
  2. `--image` flag
  3. reads /etc/os-release for BOOTC_IMAGE
  4. reads /usr/lib/os-release for BOOTC_IMAGE

Fixes: bootc-dev#1300

Signed-off-by: Terence Lee <hone02@gmail.com>
Remove duplicate cloud-init from hack/packages.txt

Signed-off-by: Terence Lee <hone02@gmail.com>
@hone hone force-pushed the default-image-os-release branch from 8a9b9d4 to 5bc8f73 Compare April 23, 2026 23:30
@hone
Copy link
Copy Markdown
Contributor Author

hone commented Apr 23, 2026

Yes, I would move the ssh stuff to it's own PR where we will have some additional discussions on it. The background here is that we are not 100% sure yet if we can assume the target image has cloud-init and we might want to support checking for ignition or/and cloud init on the distributions we maintain. There is some uncertainty of assuming this still. When the issue was created I think were more certain about cloud-init vs ignition.

Ok, I've squased the PR. I didn't squash 8a9b9d4 b/c it's not totally related to my PR, but something I needed to do to get CI to pass.

I've also moved the ssh authorized_keys + cloud-init commits into #2163 .

Copy link
Copy Markdown
Contributor

@jmarrero jmarrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/system-reinstall-bootc Issues related to system-reinstall-botoc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for default image from /usr/lib/os-release or so

4 participants