@@ -15,7 +15,10 @@ use std::{
1515use super :: { image:: Image , VmState } ;
1616use anyhow:: { bail, Context , Result } ;
1717use bon:: Builder ;
18- use dstack_types:: shared_filenames:: { APP_COMPOSE , ENCRYPTED_ENV , INSTANCE_INFO , USER_CONFIG } ;
18+ use dstack_types:: {
19+ shared_filenames:: { APP_COMPOSE , ENCRYPTED_ENV , INSTANCE_INFO , USER_CONFIG } ,
20+ AppCompose ,
21+ } ;
1922use dstack_vmm_rpc as pb;
2023use fs_err as fs;
2124use serde:: { Deserialize , Serialize } ;
@@ -37,6 +40,7 @@ pub struct VmInfo {
3740 pub boot_error : String ,
3841 pub shutdown_progress : String ,
3942 pub image_version : String ,
43+ pub gateway_enabled : bool ,
4044}
4145
4246#[ derive( Debug , Builder ) ]
@@ -46,6 +50,7 @@ pub struct VmConfig {
4650 pub cid : u32 ,
4751 pub networking : Networking ,
4852 pub workdir : PathBuf ,
53+ pub gateway_enabled : bool ,
4954}
5055
5156#[ derive( Deserialize , Serialize ) ]
@@ -79,7 +84,7 @@ fn create_hd(
7984}
8085
8186impl VmInfo {
82- pub fn to_pb ( & self , gw : & GatewayConfig ) -> pb:: VmInfo {
87+ pub fn to_pb ( & self , gw : & GatewayConfig , brief : bool ) -> pb:: VmInfo {
8388 let workdir = VmWorkDir :: new ( & self . workdir ) ;
8489 pb:: VmInfo {
8590 id : self . manifest . id . clone ( ) ,
@@ -90,47 +95,57 @@ impl VmInfo {
9095 boot_error : self . boot_error . clone ( ) ,
9196 shutdown_progress : self . shutdown_progress . clone ( ) ,
9297 image_version : self . image_version . clone ( ) ,
93- configuration : Some ( pb:: VmConfiguration {
94- name : self . manifest . name . clone ( ) ,
95- image : self . manifest . image . clone ( ) ,
96- compose_file : {
97- fs:: read_to_string ( workdir. app_compose_path ( ) ) . unwrap_or_default ( )
98- } ,
99- encrypted_env : { fs:: read ( workdir. encrypted_env_path ( ) ) . unwrap_or_default ( ) } ,
100- user_config : { fs:: read_to_string ( workdir. user_config_path ( ) ) . unwrap_or_default ( ) } ,
101- vcpu : self . manifest . vcpu ,
102- memory : self . manifest . memory ,
103- disk_size : self . manifest . disk_size ,
104- ports : self
105- . manifest
106- . port_map
107- . iter ( )
108- . map ( |pm| pb:: PortMapping {
109- protocol : pm. protocol . as_str ( ) . into ( ) ,
110- host_address : pm. address . to_string ( ) ,
111- host_port : pm. from as u32 ,
112- vm_port : pm. to as u32 ,
113- } )
114- . collect ( ) ,
115- app_id : Some ( self . manifest . app_id . clone ( ) ) ,
116- hugepages : self . manifest . hugepages ,
117- pin_numa : self . manifest . pin_numa ,
118- gpus : self
119- . manifest
120- . gpus
121- . iter ( )
122- . map ( |gpu| pb:: GpuSpec {
123- product_id : gpu. product_id . clone ( ) ,
124- slot : gpu. slot . clone ( ) ,
125- } )
126- . collect ( ) ,
127- } ) ,
128- app_url : self . instance_id . as_ref ( ) . map ( |id| {
129- format ! (
130- "https://{id}-{}.{}:{}" ,
131- gw. agent_port, gw. base_domain, gw. port
132- )
133- } ) ,
98+ configuration : if brief {
99+ None
100+ } else {
101+ Some ( pb:: VmConfiguration {
102+ name : self . manifest . name . clone ( ) ,
103+ image : self . manifest . image . clone ( ) ,
104+ compose_file : {
105+ fs:: read_to_string ( workdir. app_compose_path ( ) ) . unwrap_or_default ( )
106+ } ,
107+ encrypted_env : { fs:: read ( workdir. encrypted_env_path ( ) ) . unwrap_or_default ( ) } ,
108+ user_config : {
109+ fs:: read_to_string ( workdir. user_config_path ( ) ) . unwrap_or_default ( )
110+ } ,
111+ vcpu : self . manifest . vcpu ,
112+ memory : self . manifest . memory ,
113+ disk_size : self . manifest . disk_size ,
114+ ports : self
115+ . manifest
116+ . port_map
117+ . iter ( )
118+ . map ( |pm| pb:: PortMapping {
119+ protocol : pm. protocol . as_str ( ) . into ( ) ,
120+ host_address : pm. address . to_string ( ) ,
121+ host_port : pm. from as u32 ,
122+ vm_port : pm. to as u32 ,
123+ } )
124+ . collect ( ) ,
125+ app_id : Some ( self . manifest . app_id . clone ( ) ) ,
126+ hugepages : self . manifest . hugepages ,
127+ pin_numa : self . manifest . pin_numa ,
128+ gpus : self
129+ . manifest
130+ . gpus
131+ . iter ( )
132+ . map ( |gpu| pb:: GpuSpec {
133+ product_id : gpu. product_id . clone ( ) ,
134+ slot : gpu. slot . clone ( ) ,
135+ } )
136+ . collect ( ) ,
137+ } )
138+ } ,
139+ app_url : self
140+ . gateway_enabled
141+ . then_some ( self . instance_id . as_ref ( ) )
142+ . flatten ( )
143+ . map ( |id| {
144+ format ! (
145+ "https://{id}-{}.{}:{}" ,
146+ gw. agent_port, gw. base_domain, gw. port
147+ )
148+ } ) ,
134149 app_id : self . manifest . app_id . clone ( ) ,
135150 instance_id : self . instance_id . as_deref ( ) . map ( Into :: into) ,
136151 exited_at : self . exited_at . clone ( ) ,
@@ -178,6 +193,7 @@ impl VmState {
178193 boot_error : self . state . boot_error . clone ( ) ,
179194 shutdown_progress : self . state . shutdown_progress . clone ( ) ,
180195 image_version : self . config . image . info . version . clone ( ) ,
196+ gateway_enabled : self . config . gateway_enabled ,
181197 }
182198 }
183199}
@@ -527,4 +543,10 @@ impl VmWorkDir {
527543 let info: InstanceInfo = serde_json:: from_slice ( & fs:: read ( & info_file) ?) ?;
528544 Ok ( info)
529545 }
546+
547+ pub fn app_compose ( & self ) -> Result < AppCompose > {
548+ let compose_file = self . app_compose_path ( ) ;
549+ let compose: AppCompose = serde_json:: from_str ( & fs:: read_to_string ( compose_file) ?) ?;
550+ Ok ( compose)
551+ }
530552}
0 commit comments