Skip to content

Commit 5c948a5

Browse files
authored
Merge pull request #1347 from champtar/repro2
More reproducibility fixes / switch to canon-json
2 parents 350fb40 + 80deb0e commit 5c948a5

File tree

9 files changed

+40
-18
lines changed

9 files changed

+40
-18
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ lto = "yes"
4646
anstream = "0.6"
4747
anyhow = "1.0.82"
4848
camino = "1.1.6"
49+
canon-json = "0.2.1"
4950
cap-std-ext = "4.0.3"
5051
chrono = { version = "0.4.38", default-features = false }
5152
clap = "4.5.4"

lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ uuid = { version = "1.8.0", features = ["v4"] }
5656
tini = "1.3.0"
5757
comfy-table = "7.1.1"
5858
thiserror = { workspace = true }
59+
canon-json = { workspace = true }
5960

6061
[dev-dependencies]
6162
similar-asserts = { workspace = true }

lib/src/install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use anyhow::{anyhow, ensure, Context, Result};
2727
use bootc_utils::CommandRunExt;
2828
use camino::Utf8Path;
2929
use camino::Utf8PathBuf;
30+
use canon_json::CanonJsonSerialize;
3031
use cap_std::fs::{Dir, MetadataExt};
3132
use cap_std_ext::cap_std;
3233
use cap_std_ext::cap_std::fs::FileType;
@@ -619,7 +620,7 @@ pub(crate) fn print_configuration() -> Result<()> {
619620
let mut install_config = config::load_config()?.unwrap_or_default();
620621
install_config.filter_to_external();
621622
let stdout = std::io::stdout().lock();
622-
serde_json::to_writer(stdout, &install_config).map_err(Into::into)
623+
anyhow::Ok(install_config.to_canon_json_writer(stdout)?)
623624
}
624625

625626
#[context("Creating ostree deployment")]
@@ -1349,8 +1350,7 @@ async fn install_with_sysroot(
13491350
rootfs
13501351
.physical_root
13511352
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
1352-
serde_json::to_writer(f, &aleph)?;
1353-
anyhow::Ok(())
1353+
anyhow::Ok(aleph.to_canon_json_writer(f)?)
13541354
})
13551355
.context("Writing aleph version")?;
13561356

lib/src/progress_jsonl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! see <https://jsonlines.org/>.
33
44
use anyhow::Result;
5+
use canon_json::CanonJsonSerialize;
56
use schemars::JsonSchema;
67
use serde::Serialize;
78
use std::borrow::Cow;
@@ -199,8 +200,8 @@ impl TryFrom<RawProgressFd> for ProgressWriter {
199200
impl ProgressWriter {
200201
/// Serialize the target value as a single line of JSON and write it.
201202
async fn send_impl_inner<T: Serialize>(inner: &mut ProgressWriterInner, v: T) -> Result<()> {
202-
// serde is guaranteed not to output newlines here
203-
let buf = serde_json::to_vec(&v)?;
203+
// canon_json is guaranteed not to output newlines here
204+
let buf = v.to_canon_json_vec()?;
204205
inner.fd.write_all(&buf).await?;
205206
// We always end in a newline
206207
inner.fd.write_all(b"\n").await?;

lib/src/status.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::Read;
55
use std::io::Write;
66

77
use anyhow::{Context, Result};
8+
use canon_json::CanonJsonSerialize;
89
use fn_error_context::context;
910
use ostree::glib;
1011
use ostree_container::OstreeImageReference;
@@ -320,7 +321,9 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
320321
};
321322
let format = opts.format.unwrap_or(legacy_opt);
322323
match format {
323-
OutputFormat::Json => serde_json::to_writer(&mut out, &host).map_err(anyhow::Error::new),
324+
OutputFormat::Json => host
325+
.to_canon_json_writer(&mut out)
326+
.map_err(anyhow::Error::new),
324327
OutputFormat::Yaml => serde_yaml::to_writer(&mut out, &host).map_err(anyhow::Error::new),
325328
OutputFormat::HumanReadable => human_readable_output(&mut out, &host),
326329
}

ostree-ext/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ indexmap = { version = "2.2.2", features = ["serde"] }
5151
indoc = { version = "2", optional = true }
5252
xshell = { version = "0.2", optional = true }
5353
similar-asserts = { version = "1.5.0", optional = true }
54+
canon-json = { workspace = true }
5455

5556
[dev-dependencies]
5657
quickcheck = "1"

ostree-ext/src/cli.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
use anyhow::{Context, Result};
99
use camino::{Utf8Path, Utf8PathBuf};
10+
use canon_json::CanonJsonSerialize;
1011
use cap_std::fs::Dir;
1112
use cap_std_ext::cap_std;
1213
use cap_std_ext::prelude::CapStdExtDirExt;
@@ -880,7 +881,9 @@ async fn container_store(
880881
if let Some(check) = check.as_deref() {
881882
let rootfs = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
882883
rootfs.atomic_replace_with(check.as_str().trim_start_matches('/'), |w| {
883-
serde_json::to_writer(w, &prep.manifest).context("Serializing manifest")
884+
prep.manifest
885+
.to_canon_json_writer(w)
886+
.context("Serializing manifest")
884887
})?;
885888
// In check mode, we're done
886889
return Ok(());
@@ -1010,7 +1013,8 @@ fn handle_serialize_to_file<T: serde::Serialize>(path: Option<&Utf8Path>, obj: T
10101013
let mut out = std::fs::File::create(path)
10111014
.map(BufWriter::new)
10121015
.with_context(|| anyhow::anyhow!("Opening {path} for writing"))?;
1013-
serde_json::to_writer(&mut out, &obj).context("Serializing output")?;
1016+
obj.to_canon_json_writer(&mut out)
1017+
.context("Serializing output")?;
10141018
}
10151019
Ok(())
10161020
}
@@ -1136,9 +1140,9 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
11361140
let stdout = std::io::stdout().lock();
11371141
let mut stdout = std::io::BufWriter::new(stdout);
11381142
if config {
1139-
serde_json::to_writer(&mut stdout, &image.configuration)?;
1143+
image.configuration.to_canon_json_writer(&mut stdout)?;
11401144
} else {
1141-
serde_json::to_writer(&mut stdout, &image.manifest)?;
1145+
image.manifest.to_canon_json_writer(&mut stdout)?;
11421146
}
11431147
stdout.flush()?;
11441148
Ok(())

ostree-ext/src/container/store.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::sysroot::SysrootLock;
1414
use crate::utils::ResultExt;
1515
use anyhow::{anyhow, Context};
1616
use camino::{Utf8Path, Utf8PathBuf};
17+
use canon_json::CanonJsonSerialize;
1718
use cap_std_ext::cap_std;
1819
use cap_std_ext::cap_std::fs::{Dir, MetadataExt};
1920
use cap_std_ext::cmdext::CapStdExtCommandExt;
@@ -603,9 +604,13 @@ impl ImageImporter {
603604
Self::CACHED_KEY_MANIFEST_DIGEST,
604605
manifest_digest.to_string(),
605606
);
606-
let cached_manifest = serde_json::to_string(manifest).context("Serializing manifest")?;
607+
let cached_manifest = manifest
608+
.to_canon_json_string()
609+
.context("Serializing manifest")?;
607610
commitmeta.insert(Self::CACHED_KEY_MANIFEST, cached_manifest);
608-
let cached_config = serde_json::to_string(config).context("Serializing config")?;
611+
let cached_config = config
612+
.to_canon_json_string()
613+
.context("Serializing config")?;
609614
commitmeta.insert(Self::CACHED_KEY_CONFIG, cached_config);
610615
let commitmeta = commitmeta.to_variant();
611616
// Clone these to move into blocking method
@@ -1042,15 +1047,19 @@ impl ImageImporter {
10421047
let _ = self.layer_byte_progress.take();
10431048
let _ = self.layer_progress.take();
10441049

1045-
let serialized_manifest = serde_json::to_string(&import.manifest)?;
1046-
let serialized_config = serde_json::to_string(&import.config)?;
10471050
let mut metadata = HashMap::new();
10481051
metadata.insert(
10491052
META_MANIFEST_DIGEST,
10501053
import.manifest_digest.to_string().to_variant(),
10511054
);
1052-
metadata.insert(META_MANIFEST, serialized_manifest.to_variant());
1053-
metadata.insert(META_CONFIG, serialized_config.to_variant());
1055+
metadata.insert(
1056+
META_MANIFEST,
1057+
import.manifest.to_canon_json_string()?.to_variant(),
1058+
);
1059+
metadata.insert(
1060+
META_CONFIG,
1061+
import.config.to_canon_json_string()?.to_variant(),
1062+
);
10541063
metadata.insert(
10551064
"ostree.importer.version",
10561065
env!("CARGO_PKG_VERSION").to_variant(),

0 commit comments

Comments
 (0)