Skip to content

Commit 65b2e45

Browse files
authored
Merge pull request #2254 from rgl/add-registry-push-oci-image-manigest-annotations
feat: add support for setting the pushed oci image manifest annotations
2 parents 86a5877 + 9ecb814 commit 65b2e45

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

crates/oci/src/client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Spin's client for distributing applications via OCI registries
22
3-
use std::collections::HashMap;
3+
use std::collections::{BTreeMap, HashMap};
44
use std::path::{Path, PathBuf};
55

66
use anyhow::{bail, Context, Result};
@@ -103,6 +103,7 @@ impl Client {
103103
&mut self,
104104
manifest_path: &Path,
105105
reference: impl AsRef<str>,
106+
annotations: Option<BTreeMap<String, String>>,
106107
) -> Result<Option<String>> {
107108
let reference: Reference = reference
108109
.as_ref()
@@ -121,7 +122,8 @@ impl Client {
121122
)
122123
.await?;
123124

124-
self.push_locked_core(locked, auth, reference).await
125+
self.push_locked_core(locked, auth, reference, annotations)
126+
.await
125127
}
126128

127129
/// Push a Spin application to an OCI registry and return the digest (or None
@@ -130,14 +132,16 @@ impl Client {
130132
&mut self,
131133
locked: LockedApp,
132134
reference: impl AsRef<str>,
135+
annotations: Option<BTreeMap<String, String>>,
133136
) -> Result<Option<String>> {
134137
let reference: Reference = reference
135138
.as_ref()
136139
.parse()
137140
.with_context(|| format!("cannot parse reference {}", reference.as_ref()))?;
138141
let auth = Self::auth(&reference).await?;
139142

140-
self.push_locked_core(locked, auth, reference).await
143+
self.push_locked_core(locked, auth, reference, annotations)
144+
.await
141145
}
142146

143147
/// Push a Spin application to an OCI registry and return the digest (or None
@@ -147,6 +151,7 @@ impl Client {
147151
locked: LockedApp,
148152
auth: RegistryAuth,
149153
reference: Reference,
154+
annotations: Option<BTreeMap<String, String>>,
150155
) -> Result<Option<String>> {
151156
let mut locked_app = locked.clone();
152157
let mut layers = self
@@ -199,7 +204,7 @@ impl Client {
199204
};
200205
let oci_config =
201206
oci_distribution::client::Config::oci_v1_from_config_file(oci_config_file, None)?;
202-
let manifest = OciImageManifest::build(&layers, &oci_config, None);
207+
let manifest = OciImageManifest::build(&layers, &oci_config, annotations);
203208

204209
let response = self
205210
.oci

src/commands/registry.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::opts::*;
22
use anyhow::{Context, Result};
33
use clap::{Parser, Subcommand};
44
use indicatif::{ProgressBar, ProgressStyle};
5+
use spin_common::arg_parser::parse_kv;
56
use spin_oci::Client;
67
use std::{io::Read, path::PathBuf, time::Duration};
78

@@ -61,6 +62,11 @@ pub struct Push {
6162
/// Cache directory for downloaded registry data.
6263
#[clap(long)]
6364
pub cache_dir: Option<PathBuf>,
65+
66+
/// Specifies the OCI image manifest annotations (in key=value format).
67+
/// Any existing value will be overwritten. Can be used multiple times.
68+
#[clap(long = "annotation", parse(try_from_str = parse_kv))]
69+
pub annotations: Vec<(String, String)>,
6470
}
6571

6672
impl Push {
@@ -70,11 +76,17 @@ impl Push {
7076
spin_build::build(&app_file, &[]).await?;
7177
}
7278

79+
let annotations = if self.annotations.is_empty() {
80+
None
81+
} else {
82+
Some(self.annotations.iter().cloned().collect())
83+
};
84+
7385
let mut client = spin_oci::Client::new(self.insecure, self.cache_dir.clone()).await?;
7486

7587
let _spinner = create_dotted_spinner(2000, "Pushing app to the Registry".to_owned());
7688

77-
let digest = client.push(&app_file, &self.reference).await?;
89+
let digest = client.push(&app_file, &self.reference, annotations).await?;
7890
match digest {
7991
Some(digest) => println!("Pushed with digest {digest}"),
8092
None => println!("Pushed; the registry did not return the digest"),

0 commit comments

Comments
 (0)