Skip to content

Commit 5d46e24

Browse files
committed
install: Compute target image reference upfront
Prep for verifying it before we do an install. Signed-off-by: Colin Walters <[email protected]>
1 parent e362eaf commit 5d46e24

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

lib/src/install.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub(crate) struct State {
200200
pub(crate) setenforce_guard: Option<crate::lsm::SetEnforceGuard>,
201201
#[allow(dead_code)]
202202
pub(crate) config_opts: InstallConfigOpts,
203-
pub(crate) target_opts: InstallTargetOpts,
203+
pub(crate) target_imgref: ostree_container::OstreeImageReference,
204204
pub(crate) install_config: config::InstallConfiguration,
205205
}
206206

@@ -435,32 +435,8 @@ async fn initialize_ostree_root_from_self(
435435
) -> Result<InstallAleph> {
436436
let rootfs_dir = &root_setup.rootfs_fd;
437437
let rootfs = root_setup.rootfs.as_path();
438-
let opts = &state.target_opts;
439438
let cancellable = gio::Cancellable::NONE;
440439

441-
// Parse the target CLI image reference options and create the *target* image
442-
// reference, which defaults to pulling from a registry.
443-
let target_sigverify = if opts.target_no_signature_verification {
444-
SignatureSource::ContainerPolicyAllowInsecure
445-
} else if let Some(remote) = opts.target_ostree_remote.as_deref() {
446-
SignatureSource::OstreeRemote(remote.to_string())
447-
} else {
448-
SignatureSource::ContainerPolicy
449-
};
450-
let target_imgname = opts
451-
.target_imgref
452-
.as_deref()
453-
.unwrap_or(state.source.imageref.name.as_str());
454-
let target_transport = ostree_container::Transport::try_from(opts.target_transport.as_str())?;
455-
let target_imgref = ostree_container::OstreeImageReference {
456-
sigverify: target_sigverify,
457-
imgref: ostree_container::ImageReference {
458-
transport: target_transport,
459-
name: target_imgname.to_string(),
460-
},
461-
};
462-
tracing::debug!("Target image reference: {target_imgref}");
463-
464440
// TODO: make configurable?
465441
let stateroot = STATEROOT_DEFAULT;
466442
Task::new_and_run(
@@ -535,12 +511,12 @@ async fn initialize_ostree_root_from_self(
535511
.collect::<Vec<_>>();
536512
let mut options = ostree_container::deploy::DeployOpts::default();
537513
options.kargs = Some(kargs.as_slice());
538-
options.target_imgref = Some(&target_imgref);
514+
options.target_imgref = Some(&state.target_imgref);
539515
options.proxy_cfg = Some(proxy_cfg);
540516
println!("Creating initial deployment");
517+
let target_image = state.target_imgref.to_string();
541518
let state =
542519
ostree_container::deploy::deploy(&sysroot, stateroot, &src_imageref, Some(options)).await?;
543-
let target_image = target_imgref.to_string();
544520
let digest = state.manifest_digest.as_str();
545521
println!("Installed: {target_image}");
546522
println!(" Digest: {digest}");
@@ -816,6 +792,30 @@ async fn prepare_install(
816792

817793
let source = SourceInfo::from_container(&container_info)?;
818794

795+
// Parse the target CLI image reference options and create the *target* image
796+
// reference, which defaults to pulling from a registry.
797+
let target_sigverify = if target_opts.target_no_signature_verification {
798+
SignatureSource::ContainerPolicyAllowInsecure
799+
} else if let Some(remote) = target_opts.target_ostree_remote.as_deref() {
800+
SignatureSource::OstreeRemote(remote.to_string())
801+
} else {
802+
SignatureSource::ContainerPolicy
803+
};
804+
let target_imgname = target_opts
805+
.target_imgref
806+
.as_deref()
807+
.unwrap_or(source.imageref.name.as_str());
808+
let target_transport =
809+
ostree_container::Transport::try_from(target_opts.target_transport.as_str())?;
810+
let target_imgref = ostree_container::OstreeImageReference {
811+
sigverify: target_sigverify,
812+
imgref: ostree_container::ImageReference {
813+
transport: target_transport,
814+
name: target_imgname.to_string(),
815+
},
816+
};
817+
tracing::debug!("Target image reference: {target_imgref}");
818+
819819
ensure_var()?;
820820
propagate_tmp_mounts_to_host()?;
821821

@@ -841,7 +841,7 @@ async fn prepare_install(
841841
setenforce_guard,
842842
source,
843843
config_opts,
844-
target_opts,
844+
target_imgref,
845845
install_config,
846846
});
847847

0 commit comments

Comments
 (0)