@@ -33,6 +33,24 @@ enum Opt {
3333 tag : Option < String > ,
3434 } ,
3535
36+ /// Compose a static-linked executable file into an oci-archive tar file
37+ Runnable {
38+ /// Path of static-linked exetuable file
39+ input : PathBuf ,
40+
41+ /// Path of output tar archive in oci-archive format. Default is input file name with .tar extension
42+ #[ arg( short = 'o' , long = "output" ) ]
43+ output : Option < PathBuf > ,
44+
45+ /// Overwrite the output file if it exists
46+ #[ arg( short = 'f' , long = "overwrite" ) ]
47+ overwrite : bool ,
48+
49+ /// Name of container, use UUID v4 hyphenated if not set.
50+ #[ arg( short = 't' , long = "tag" ) ]
51+ tag : Option < String > ,
52+ } ,
53+
3654 /// Load and expand container local cache
3755 Load {
3856 /// Input oci-archive
@@ -121,6 +139,33 @@ fn main() -> Result<()> {
121139 let _artifact = b. build ( ) ?;
122140 }
123141
142+ Opt :: Runnable {
143+ input,
144+ output,
145+ overwrite,
146+ tag,
147+ } => {
148+ let output = output. unwrap_or_else ( || {
149+ let mut output = input. clone ( ) ;
150+ output. set_extension ( "tar" ) ;
151+ output
152+ } ) ;
153+ let image_name = if let Some ( name) = tag {
154+ ocipkg:: ImageName :: parse ( & name) ?
155+ } else {
156+ ocipkg:: ImageName :: default ( )
157+ } ;
158+
159+ if overwrite && output. exists ( ) {
160+ log:: warn!( "Overwriting existing file: {}" , output. display( ) ) ;
161+ std:: fs:: remove_file ( & output) ?;
162+ }
163+
164+ log:: info!( "Creating runnable image at {}" , output. display( ) ) ;
165+ let _out =
166+ ocipkg:: image:: RunnableBuilder :: new_archive ( output, image_name) ?. build ( & input) ?;
167+ }
168+
124169 Opt :: Load { input, overwrite } => {
125170 ocipkg:: image:: load ( & input, overwrite) ?;
126171 }
0 commit comments