Skip to content

Commit 9ecb814

Browse files
committed
feat: add support for setting the pushed oci image manifest annotations
Signed-off-by: Rui Lopes <[email protected]>
1 parent e198b9f commit 9ecb814

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};
@@ -97,6 +97,7 @@ impl Client {
9797
&mut self,
9898
manifest_path: &Path,
9999
reference: impl AsRef<str>,
100+
annotations: Option<BTreeMap<String, String>>,
100101
) -> Result<Option<String>> {
101102
let reference: Reference = reference
102103
.as_ref()
@@ -115,7 +116,8 @@ impl Client {
115116
)
116117
.await?;
117118

118-
self.push_locked_core(locked, auth, reference).await
119+
self.push_locked_core(locked, auth, reference, annotations)
120+
.await
119121
}
120122

121123
/// Push a Spin application to an OCI registry and return the digest (or None
@@ -124,14 +126,16 @@ impl Client {
124126
&mut self,
125127
locked: LockedApp,
126128
reference: impl AsRef<str>,
129+
annotations: Option<BTreeMap<String, String>>,
127130
) -> Result<Option<String>> {
128131
let reference: Reference = reference
129132
.as_ref()
130133
.parse()
131134
.with_context(|| format!("cannot parse reference {}", reference.as_ref()))?;
132135
let auth = Self::auth(&reference).await?;
133136

134-
self.push_locked_core(locked, auth, reference).await
137+
self.push_locked_core(locked, auth, reference, annotations)
138+
.await
135139
}
136140

137141
/// Push a Spin application to an OCI registry and return the digest (or None
@@ -141,6 +145,7 @@ impl Client {
141145
locked: LockedApp,
142146
auth: RegistryAuth,
143147
reference: Reference,
148+
annotations: Option<BTreeMap<String, String>>,
144149
) -> Result<Option<String>> {
145150
let mut locked_app = locked.clone();
146151
let mut layers = self
@@ -193,7 +198,7 @@ impl Client {
193198
};
194199
let oci_config =
195200
oci_distribution::client::Config::oci_v1_from_config_file(oci_config_file, None)?;
196-
let manifest = OciImageManifest::build(&layers, &oci_config, None);
201+
let manifest = OciImageManifest::build(&layers, &oci_config, annotations);
197202

198203
let response = self
199204
.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)