@@ -48,6 +48,16 @@ const MAX_LAYER_COUNT: usize = 500;
48
48
/// rather than pushing as a separate layer
49
49
const DEFAULT_CONTENT_REF_INLINE_MAX_SIZE : usize = 128 ;
50
50
51
+ /// Mode of assembly of a Spin application into an OCI image
52
+ enum AssemblyMode {
53
+ /// Assemble the application as one layer per component and one layer for
54
+ /// every static asset included with a given component
55
+ Simple ,
56
+ /// Assemble the application as one layer per component and one compressed
57
+ /// archive layer containing all static assets included with a given component
58
+ Archive ,
59
+ }
60
+
51
61
/// Client for interacting with an OCI registry for Spin applications.
52
62
pub struct Client {
53
63
/// Global cache for the metadata, Wasm modules, and static assets pulled from OCI registries.
@@ -134,7 +144,7 @@ impl Client {
134
144
) -> Result < Option < String > > {
135
145
let mut locked_app = locked. clone ( ) ;
136
146
let mut layers = self
137
- . assemble_layers ( & mut locked_app, false )
147
+ . assemble_layers ( & mut locked_app, AssemblyMode :: Simple )
138
148
. await
139
149
. context ( "could not assemble layers for locked application" ) ?;
140
150
@@ -143,7 +153,7 @@ impl Client {
143
153
if layers. len ( ) > MAX_LAYER_COUNT - 1 {
144
154
locked_app = locked. clone ( ) ;
145
155
layers = self
146
- . assemble_layers ( & mut locked_app, true )
156
+ . assemble_layers ( & mut locked_app, AssemblyMode :: Archive )
147
157
. await
148
158
. context ( "could not assemble archive layers for locked application" ) ?;
149
159
}
@@ -198,16 +208,12 @@ impl Client {
198
208
Ok ( digest)
199
209
}
200
210
201
- /// Assemble ImageLayers for a locked application and return the
202
- /// resulting Vec<ImageLayer>.
203
- /// There will always be one layer per component wasm file and
204
- /// their may be one layer for each static asset included with each component
205
- /// or one archive layer per component consolidating all static assets together,
206
- /// to avoid exceeding certain registry layer count limits.
211
+ /// Assemble ImageLayers for a locked application using the provided
212
+ /// AssemblyMode and return the resulting Vec<ImageLayer>.
207
213
async fn assemble_layers (
208
214
& mut self ,
209
215
locked : & mut LockedApp ,
210
- archive : bool ,
216
+ assembly_mode : AssemblyMode ,
211
217
) -> Result < Vec < ImageLayer > > {
212
218
let mut layers = Vec :: new ( ) ;
213
219
let mut components = Vec :: new ( ) ;
@@ -236,20 +242,21 @@ impl Client {
236
242
. context ( "file mount loaded from disk should contain a file source" ) ?;
237
243
let source = parse_file_url ( source. as_str ( ) ) ?;
238
244
239
- if archive {
240
- self . push_archive_layer ( & source, & mut files, & mut layers)
245
+ match assembly_mode {
246
+ AssemblyMode :: Archive => self
247
+ . push_archive_layer ( & source, & mut files, & mut layers)
241
248
. await
242
249
. context ( format ! (
243
250
"cannot push archive layer for source {}" ,
244
251
quoted_path( & source)
245
- ) ) ?;
246
- } else {
247
- self . push_file_layers ( & source, & mut files, & mut layers)
252
+ ) ) ?,
253
+ AssemblyMode :: Simple => self
254
+ . push_file_layers ( & source, & mut files, & mut layers)
248
255
. await
249
256
. context ( format ! (
250
257
"cannot push file layers for source {}" ,
251
258
quoted_path( & source)
252
- ) ) ?;
259
+ ) ) ?,
253
260
}
254
261
}
255
262
c. files = files;
@@ -803,7 +810,7 @@ mod test {
803
810
"digest" : "digest" ,
804
811
}
805
812
} ] ) ,
806
- expected_layer_count : 2 ,
813
+ expected_layer_count : 0 ,
807
814
expected_error : Some ( "Invalid URL: \" \" " ) ,
808
815
} ,
809
816
TestCase {
@@ -892,7 +899,7 @@ mod test {
892
899
assert_eq ! (
893
900
e,
894
901
client
895
- . assemble_layers( & mut locked, false )
902
+ . assemble_layers( & mut locked, AssemblyMode :: Simple )
896
903
. await
897
904
. unwrap_err( )
898
905
. to_string( ) ,
@@ -904,7 +911,7 @@ mod test {
904
911
assert_eq ! (
905
912
tc. expected_layer_count,
906
913
client
907
- . assemble_layers( & mut locked, false )
914
+ . assemble_layers( & mut locked, AssemblyMode :: Simple )
908
915
. await
909
916
. unwrap( )
910
917
. len( ) ,
0 commit comments