Skip to content

Commit 5dbed82

Browse files
committed
feat: Support versioned modules
1 parent 99410b8 commit 5dbed82

21 files changed

+337
-220
lines changed

process/drivers.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -200,35 +200,30 @@ impl Driver {
200200
let _ = oci_ref; // silence lint
201201

202202
if true {
203-
return Ok(40);
203+
return Ok(41);
204204
}
205205
}
206206

207207
info!("Retrieving OS version from {oci_ref}");
208208

209-
let inspect_opts = GetMetadataOpts::builder()
210-
.image(format!(
211-
"{}/{}",
212-
oci_ref.resolve_registry(),
213-
oci_ref.repository()
214-
))
215-
.tag(oci_ref.tag().unwrap_or("latest"))
216-
.platform(platform)
217-
.build();
218-
219-
let os_version = Self::get_metadata(&inspect_opts)
220-
.and_then(|inspection| {
221-
inspection.get_version().ok_or_else(|| {
222-
miette!(
223-
"Failed to parse version from metadata for {}",
224-
oci_ref.to_string().bold()
225-
)
226-
})
209+
let os_version = Self::get_metadata(
210+
&GetMetadataOpts::builder()
211+
.image(oci_ref)
212+
.platform(platform)
213+
.build(),
214+
)
215+
.and_then(|inspection| {
216+
inspection.get_version().ok_or_else(|| {
217+
miette!(
218+
"Failed to parse version from metadata for {}",
219+
oci_ref.to_string().bold()
220+
)
227221
})
228-
.or_else(|err| {
229-
warn!("Unable to get version via image inspection due to error:\n{err:?}");
230-
get_version_run_image(oci_ref)
231-
})?;
222+
})
223+
.or_else(|err| {
224+
warn!("Unable to get version via image inspection due to error:\n{err:?}");
225+
get_version_run_image(oci_ref)
226+
})?;
232227
trace!("os_version: {os_version}");
233228
Ok(os_version)
234229
}

process/drivers/buildah_driver.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{io::Write, process::Stdio};
22

33
use blue_build_utils::{cmd, credentials::Credentials};
4+
use colored::Colorize;
45
use log::{debug, error, info, trace};
56
use miette::{bail, miette, IntoDiagnostic, Result};
67
use semver::Version;
@@ -83,39 +84,48 @@ impl BuildDriver for BuildahDriver {
8384
fn tag(opts: &TagOpts) -> Result<()> {
8485
trace!("BuildahDriver::tag({opts:#?})");
8586

86-
let mut command = cmd!("buildah", "tag", &*opts.src_image, &*opts.dest_image,);
87+
let dest_image_str = opts.dest_image.to_string();
88+
89+
let mut command = cmd!(
90+
"buildah",
91+
"tag",
92+
opts.src_image.to_string(),
93+
&dest_image_str,
94+
);
8795

8896
trace!("{command:?}");
8997
if command.status().into_diagnostic()?.success() {
90-
info!("Successfully tagged {}!", opts.dest_image);
98+
info!("Successfully tagged {}!", dest_image_str.bold().green());
9199
} else {
92-
bail!("Failed to tag image {}", opts.dest_image);
100+
bail!("Failed to tag image {}", dest_image_str.bold().red());
93101
}
94102
Ok(())
95103
}
96104

97105
fn push(opts: &PushOpts) -> Result<()> {
98106
trace!("BuildahDriver::push({opts:#?})");
99107

108+
let image_str = opts.image.to_string();
109+
100110
let command = cmd!(
101111
"buildah",
102112
"push",
103113
format!(
104114
"--compression-format={}",
105115
opts.compression_type.unwrap_or_default()
106116
),
107-
&*opts.image,
117+
&image_str,
108118
);
109119

110120
trace!("{command:?}");
111121
let status = command
112-
.build_status(&opts.image, "Pushing Image")
122+
.build_status(&image_str, "Pushing Image")
113123
.into_diagnostic()?;
114124

115125
if status.success() {
116-
info!("Successfully pushed {}!", opts.image);
126+
info!("Successfully pushed {}!", image_str.bold().green());
117127
} else {
118-
bail!("Failed to push image {}", opts.image);
128+
bail!("Failed to push image {}", image_str.bold().red());
119129
}
120130
Ok(())
121131
}

process/drivers/cosign_driver.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use blue_build_utils::{
55
constants::{COSIGN_PASSWORD, COSIGN_PUB_PATH, COSIGN_YES},
66
credentials::Credentials,
77
};
8+
use colored::Colorize;
89
use log::{debug, trace};
910
use miette::{bail, miette, Context, IntoDiagnostic, Result};
1011

@@ -121,27 +122,32 @@ impl SigningDriver for CosignDriver {
121122
}
122123

123124
fn sign(opts: &SignOpts) -> Result<()> {
124-
let image_digest: &str = opts.image.as_ref();
125+
if opts.image.digest().is_none() {
126+
bail!(
127+
"Image ref {} is not a digest ref",
128+
opts.image.to_string().bold().red(),
129+
);
130+
}
131+
125132
let mut command = cmd!(
126133
"cosign",
127134
"sign",
128135
if let Some(ref key) = opts.key => format!("--key={key}"),
129136
"--recursive",
130-
image_digest,
137+
opts.image.to_string(),
131138
COSIGN_PASSWORD => "",
132139
COSIGN_YES => "true",
133140
);
134141

135142
trace!("{command:?}");
136143
if !command.status().into_diagnostic()?.success() {
137-
bail!("Failed to sign {image_digest}");
144+
bail!("Failed to sign {}", opts.image.to_string().bold().red());
138145
}
139146

140147
Ok(())
141148
}
142149

143150
fn verify(opts: &VerifyOpts) -> Result<()> {
144-
let image_name_tag: &str = opts.image.as_ref();
145151
let mut command = cmd!(
146152
"cosign",
147153
"verify",
@@ -157,12 +163,12 @@ impl SigningDriver for CosignDriver {
157163
),
158164
};
159165
},
160-
image_name_tag
166+
opts.image.to_string(),
161167
);
162168

163169
trace!("{command:?}");
164170
if !command.status().into_diagnostic()?.success() {
165-
bail!("Failed to verify {image_name_tag}");
171+
bail!("Failed to verify {}", opts.image.to_string().bold().red());
166172
}
167173

168174
Ok(())

process/drivers/docker_driver.rs

+33-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use blue_build_utils::{
1313
string_vec,
1414
};
1515
use cached::proc_macro::cached;
16+
use colored::Colorize;
1617
use log::{debug, info, trace, warn};
1718
use miette::{bail, miette, IntoDiagnostic, Result};
1819
use once_cell::sync::Lazy;
@@ -154,31 +155,35 @@ impl BuildDriver for DockerDriver {
154155
fn tag(opts: &TagOpts) -> Result<()> {
155156
trace!("DockerDriver::tag({opts:#?})");
156157

158+
let dest_image_str = opts.dest_image.to_string();
159+
157160
trace!("docker tag {} {}", opts.src_image, opts.dest_image);
158-
let status = cmd!("docker", "tag", &*opts.src_image, &*opts.dest_image,)
161+
let status = cmd!("docker", "tag", opts.src_image.to_string(), &dest_image_str)
159162
.status()
160163
.into_diagnostic()?;
161164

162165
if status.success() {
163-
info!("Successfully tagged {}!", opts.dest_image);
166+
info!("Successfully tagged {}!", dest_image_str.bold().green());
164167
} else {
165-
bail!("Failed to tag image {}", opts.dest_image);
168+
bail!("Failed to tag image {}", dest_image_str.bold().red());
166169
}
167170
Ok(())
168171
}
169172

170173
fn push(opts: &PushOpts) -> Result<()> {
171174
trace!("DockerDriver::push({opts:#?})");
172175

176+
let image_str = opts.image.to_string();
177+
173178
trace!("docker push {}", opts.image);
174-
let status = cmd!("docker", "push", &*opts.image)
179+
let status = cmd!("docker", "push", &image_str)
175180
.status()
176181
.into_diagnostic()?;
177182

178183
if status.success() {
179-
info!("Successfully pushed {}!", opts.image);
184+
info!("Successfully pushed {}!", image_str.bold().green());
180185
} else {
181-
bail!("Failed to push image {}", opts.image);
186+
bail!("Failed to push image {}", image_str.bold().red());
182187
}
183188
Ok(())
184189
}
@@ -315,18 +320,25 @@ impl BuildDriver for DockerDriver {
315320
],
316321
);
317322

318-
let final_images = match (opts.image.as_deref(), opts.archive_path.as_deref()) {
323+
let final_images = match (opts.image, opts.archive_path.as_deref()) {
319324
(Some(image), None) => {
320325
let images = if opts.tags.is_empty() {
321-
cmd!(command, "-t", image);
326+
let image = image.to_string();
327+
cmd!(command, "-t", &image);
322328
string_vec![image]
323329
} else {
324330
opts.tags.iter().for_each(|tag| {
325-
cmd!(command, "-t", format!("{image}:{tag}"));
331+
cmd!(
332+
command,
333+
"-t",
334+
format!("{}/{}:{tag}", image.resolve_registry(), image.repository())
335+
);
326336
});
327337
opts.tags
328338
.iter()
329-
.map(|tag| format!("{image}:{tag}"))
339+
.map(|tag| {
340+
format!("{}/{}:{tag}", image.resolve_registry(), image.repository())
341+
})
330342
.collect()
331343
};
332344
let first_image = images.first().unwrap();
@@ -348,8 +360,12 @@ impl BuildDriver for DockerDriver {
348360
images
349361
}
350362
(None, Some(archive_path)) => {
351-
cmd!(command, "--output", format!("type=oci,dest={archive_path}"));
352-
string_vec![archive_path]
363+
cmd!(
364+
command,
365+
"--output",
366+
format!("type=oci,dest={}", archive_path.display())
367+
);
368+
string_vec![archive_path.display().to_string()]
353369
}
354370
(Some(_), Some(_)) => bail!("Cannot use both image and archive path"),
355371
(None, None) => bail!("Need either the image or archive path set"),
@@ -385,16 +401,12 @@ impl InspectDriver for DockerDriver {
385401
#[cached(
386402
result = true,
387403
key = "String",
388-
convert = r#"{ format!("{}-{:?}-{}", &*opts.image, opts.tag.as_ref(), opts.platform)}"#,
404+
convert = r#"{ format!("{}-{}", opts.image, opts.platform)}"#,
389405
sync_writes = true
390406
)]
391407
fn get_metadata_cache(opts: &GetMetadataOpts) -> Result<ImageMetadata> {
392408
trace!("DockerDriver::get_metadata({opts:#?})");
393-
394-
let url = opts.tag.as_ref().map_or_else(
395-
|| format!("{}", opts.image),
396-
|tag| format!("{}:{tag}", opts.image),
397-
);
409+
let image_str = opts.image.to_string();
398410

399411
let mut command = cmd!(
400412
"docker",
@@ -409,16 +421,16 @@ fn get_metadata_cache(opts: &GetMetadataOpts) -> Result<ImageMetadata> {
409421
"inspect",
410422
"--format",
411423
"{{json .}}",
412-
&url
424+
&image_str,
413425
);
414426
trace!("{command:?}");
415427

416428
let output = command.output().into_diagnostic()?;
417429

418430
if output.status.success() {
419-
info!("Successfully inspected image {url}!");
431+
info!("Successfully inspected image {}!", image_str.bold().green());
420432
} else {
421-
bail!("Failed to inspect image {url}")
433+
bail!("Failed to inspect image {}", image_str.bold().red())
422434
}
423435

424436
serde_json::from_slice::<metadata::Metadata>(&output.stdout)

process/drivers/github_driver.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -230,55 +230,55 @@ mod test {
230230
setup_default_branch,
231231
None,
232232
string_vec![
233-
format!("{}-40", &*TIMESTAMP),
233+
format!("{}-41", &*TIMESTAMP),
234234
"latest",
235235
&*TIMESTAMP,
236-
format!("{COMMIT_SHA}-40"),
237-
"40",
236+
format!("{COMMIT_SHA}-41"),
237+
"41",
238238
],
239239
)]
240240
#[case::default_branch_alt_tags(
241241
setup_default_branch,
242242
Some(bon::vec![TEST_TAG_1, TEST_TAG_2]),
243243
string_vec![
244244
TEST_TAG_1,
245-
format!("{TEST_TAG_1}-40"),
246-
format!("{}-{TEST_TAG_1}-40", &*TIMESTAMP),
247-
format!("{COMMIT_SHA}-{TEST_TAG_1}-40"),
245+
format!("{TEST_TAG_1}-41"),
246+
format!("{}-{TEST_TAG_1}-41", &*TIMESTAMP),
247+
format!("{COMMIT_SHA}-{TEST_TAG_1}-41"),
248248
TEST_TAG_2,
249-
format!("{TEST_TAG_2}-40"),
250-
format!("{}-{TEST_TAG_2}-40", &*TIMESTAMP),
251-
format!("{COMMIT_SHA}-{TEST_TAG_2}-40"),
249+
format!("{TEST_TAG_2}-41"),
250+
format!("{}-{TEST_TAG_2}-41", &*TIMESTAMP),
251+
format!("{COMMIT_SHA}-{TEST_TAG_2}-41"),
252252
],
253253
)]
254254
#[case::pr_branch(
255255
setup_pr_branch,
256256
None,
257-
string_vec!["pr-12-40", format!("{COMMIT_SHA}-40")],
257+
string_vec!["pr-12-41", format!("{COMMIT_SHA}-41")],
258258
)]
259259
#[case::pr_branch_alt_tags(
260260
setup_pr_branch,
261261
Some(bon::vec![TEST_TAG_1, TEST_TAG_2]),
262262
string_vec![
263-
format!("pr-12-{TEST_TAG_1}-40"),
264-
format!("{COMMIT_SHA}-{TEST_TAG_1}-40"),
265-
format!("pr-12-{TEST_TAG_2}-40"),
266-
format!("{COMMIT_SHA}-{TEST_TAG_2}-40"),
263+
format!("pr-12-{TEST_TAG_1}-41"),
264+
format!("{COMMIT_SHA}-{TEST_TAG_1}-41"),
265+
format!("pr-12-{TEST_TAG_2}-41"),
266+
format!("{COMMIT_SHA}-{TEST_TAG_2}-41"),
267267
],
268268
)]
269269
#[case::branch(
270270
setup_branch,
271271
None,
272-
string_vec![format!("{COMMIT_SHA}-40"), "br-test-40"],
272+
string_vec![format!("{COMMIT_SHA}-41"), "br-test-41"],
273273
)]
274274
#[case::branch_alt_tags(
275275
setup_branch,
276276
Some(bon::vec![TEST_TAG_1, TEST_TAG_2]),
277277
string_vec![
278-
format!("br-{BR_REF_NAME}-{TEST_TAG_1}-40"),
279-
format!("{COMMIT_SHA}-{TEST_TAG_1}-40"),
280-
format!("br-{BR_REF_NAME}-{TEST_TAG_2}-40"),
281-
format!("{COMMIT_SHA}-{TEST_TAG_2}-40"),
278+
format!("br-{BR_REF_NAME}-{TEST_TAG_1}-41"),
279+
format!("{COMMIT_SHA}-{TEST_TAG_1}-41"),
280+
format!("br-{BR_REF_NAME}-{TEST_TAG_2}-41"),
281+
format!("{COMMIT_SHA}-{TEST_TAG_2}-41"),
282282
],
283283
)]
284284
fn generate_tags(

0 commit comments

Comments
 (0)