@@ -6,7 +6,6 @@ use anyhow::{Context, Result};
6
6
7
7
use fn_error_context:: context;
8
8
use ostree:: { gio, glib} ;
9
- use ostree_container:: store:: LayeredImageState ;
10
9
use ostree_container:: OstreeImageReference ;
11
10
use ostree_ext:: container as ostree_container;
12
11
use ostree_ext:: container:: store:: PrepareResult ;
@@ -28,6 +27,13 @@ pub(crate) struct RequiredHostSpec<'a> {
28
27
pub ( crate ) image : & ' a ImageReference ,
29
28
}
30
29
30
+ /// State of a locally fetched image
31
+ pub ( crate ) struct ImageState {
32
+ pub ( crate ) manifest_digest : String ,
33
+ pub ( crate ) version : Option < String > ,
34
+ pub ( crate ) ostree_commit : String ,
35
+ }
36
+
31
37
impl < ' a > RequiredHostSpec < ' a > {
32
38
/// Given a (borrowed) host specification, "unwrap" its internal
33
39
/// options, giving a spec that is required to have a base container image.
@@ -40,6 +46,29 @@ impl<'a> RequiredHostSpec<'a> {
40
46
}
41
47
}
42
48
49
+ impl From < ostree_container:: store:: LayeredImageState > for ImageState {
50
+ fn from ( value : ostree_container:: store:: LayeredImageState ) -> Self {
51
+ let version = value. version ( ) . map ( |v| v. to_owned ( ) ) ;
52
+ let ostree_commit = value. get_commit ( ) . to_owned ( ) ;
53
+ Self {
54
+ manifest_digest : value. manifest_digest ,
55
+ version,
56
+ ostree_commit,
57
+ }
58
+ }
59
+ }
60
+
61
+ impl ImageState {
62
+ /// Fetch the manifest corresponding to this image. May not be available in all backends.
63
+ pub ( crate ) fn get_manifest (
64
+ & self ,
65
+ repo : & ostree:: Repo ,
66
+ ) -> Result < Option < ostree_ext:: oci_spec:: image:: ImageManifest > > {
67
+ ostree_container:: store:: query_image_commit ( repo, & self . ostree_commit )
68
+ . map ( |v| Some ( v. manifest ) )
69
+ }
70
+ }
71
+
43
72
/// Wrapper for pulling a container image, wiring up status output.
44
73
pub ( crate ) async fn new_importer (
45
74
repo : & ostree:: Repo ,
@@ -57,14 +86,14 @@ pub(crate) async fn pull(
57
86
sysroot : & SysrootLock ,
58
87
imgref : & ImageReference ,
59
88
quiet : bool ,
60
- ) -> Result < Box < LayeredImageState > > {
89
+ ) -> Result < Box < ImageState > > {
61
90
let repo = & sysroot. repo ( ) ;
62
91
let imgref = & OstreeImageReference :: from ( imgref. clone ( ) ) ;
63
92
let mut imp = new_importer ( repo, imgref) . await ?;
64
93
let prep = match imp. prepare ( ) . await ? {
65
94
PrepareResult :: AlreadyPresent ( c) => {
66
95
println ! ( "No changes in {} => {}" , imgref, c. manifest_digest) ;
67
- return Ok ( c ) ;
96
+ return Ok ( Box :: new ( ( * c ) . into ( ) ) ) ;
68
97
}
69
98
PrepareResult :: Ready ( p) => p,
70
99
} ;
@@ -89,7 +118,7 @@ pub(crate) async fn pull(
89
118
{
90
119
eprintln ! ( "{msg}" )
91
120
}
92
- Ok ( import)
121
+ Ok ( Box :: new ( ( * import) . into ( ) ) )
93
122
}
94
123
95
124
pub ( crate ) async fn cleanup ( sysroot : & SysrootLock ) -> Result < ( ) > {
@@ -143,16 +172,15 @@ async fn deploy(
143
172
sysroot : & SysrootLock ,
144
173
merge_deployment : Option < & Deployment > ,
145
174
stateroot : & str ,
146
- image : & LayeredImageState ,
175
+ image : & ImageState ,
147
176
origin : & glib:: KeyFile ,
148
177
) -> Result < ( ) > {
149
178
let stateroot = Some ( stateroot) ;
150
179
// Copy to move into thread
151
- let base_commit = image. get_commit ( ) . to_owned ( ) ;
152
180
let cancellable = gio:: Cancellable :: NONE ;
153
181
let _new_deployment = sysroot. stage_tree_with_options (
154
182
stateroot,
155
- & base_commit ,
183
+ image . ostree_commit . as_str ( ) ,
156
184
Some ( origin) ,
157
185
merge_deployment,
158
186
& Default :: default ( ) ,
@@ -166,7 +194,7 @@ async fn deploy(
166
194
pub ( crate ) async fn stage (
167
195
sysroot : & SysrootLock ,
168
196
stateroot : & str ,
169
- image : & LayeredImageState ,
197
+ image : & ImageState ,
170
198
spec : & RequiredHostSpec < ' _ > ,
171
199
) -> Result < ( ) > {
172
200
let merge_deployment = sysroot. merge_deployment ( Some ( stateroot) ) ;
@@ -187,11 +215,7 @@ pub(crate) async fn stage(
187
215
. await ?;
188
216
crate :: deploy:: cleanup ( sysroot) . await ?;
189
217
println ! ( "Queued for next boot: {imgref}" ) ;
190
- if let Some ( version) = image
191
- . configuration
192
- . as_ref ( )
193
- . and_then ( ostree_container:: version_for_config)
194
- {
218
+ if let Some ( version) = image. version . as_deref ( ) {
195
219
println ! ( " Version: {version}" ) ;
196
220
}
197
221
println ! ( " Digest: {}" , image. manifest_digest) ;
0 commit comments