1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT License.
3+
4+ namespace VirtualClient . Contracts
5+ {
6+ using System ;
7+ using System . Collections . Generic ;
8+ using System . Runtime . InteropServices ;
9+
10+ /// <summary>
11+ /// Tracks whether execution is happening inside a container context
12+ /// and provides the effective platform for component execution.
13+ /// </summary>
14+ public class ContainerExecutionContext
15+ {
16+ private static ContainerExecutionContext current ;
17+
18+ /// <summary>
19+ /// Gets or sets the current container execution context.
20+ /// </summary>
21+ public static ContainerExecutionContext Current
22+ {
23+ get => current ??= new ContainerExecutionContext ( ) ;
24+ set => current = value ;
25+ }
26+
27+ /// <summary>
28+ /// True if running with container mode enabled (--image was passed).
29+ /// </summary>
30+ public bool IsContainerMode { get ; set ; }
31+
32+ /// <summary>
33+ /// The container image being used.
34+ /// </summary>
35+ public string Image { get ; set ; }
36+
37+ /// <summary>
38+ /// The platform inside the container (typically Linux).
39+ /// </summary>
40+ public PlatformID ContainerPlatform { get ; set ; } = PlatformID . Unix ;
41+
42+ /// <summary>
43+ /// The CPU architecture inside the container.
44+ /// </summary>
45+ public Architecture ContainerArchitecture { get ; set ; } = Architecture . X64 ;
46+
47+ /// <summary>
48+ /// Gets the effective platform - container platform if in container mode,
49+ /// otherwise the host platform.
50+ /// </summary>
51+ public PlatformID EffectivePlatform => this . IsContainerMode
52+ ? this . ContainerPlatform
53+ : Environment . OSVersion . Platform ;
54+
55+ /// <summary>
56+ /// Gets the effective architecture.
57+ /// </summary>
58+ public Architecture EffectiveArchitecture => this . IsContainerMode
59+ ? this . ContainerArchitecture
60+ : RuntimeInformation . ProcessArchitecture ;
61+
62+ /// <summary>
63+ /// Container configuration from profile.
64+ /// </summary>
65+ public ContainerConfiguration Configuration { get ; set ; }
66+ }
67+
68+ /// <summary>
69+ /// Container configuration from profile's Container section.
70+ /// </summary>
71+ public class ContainerConfiguration
72+ {
73+ /// <summary>
74+ /// Default image (can be overridden by --image CLI).
75+ /// </summary>
76+ public string Image { get ; set ; }
77+
78+ /// <summary>
79+ /// Standard mount configuration.
80+ /// </summary>
81+ public ContainerMountConfig Mounts { get ; set ; } = new ContainerMountConfig ( ) ;
82+
83+ /// <summary>
84+ /// Working directory inside container.
85+ /// </summary>
86+ public string WorkingDirectory { get ; set ; } = "/vc" ;
87+
88+ /// <summary>
89+ /// Environment variables to pass to container.
90+ /// </summary>
91+ public IDictionary < string , string > EnvironmentVariables { get ; set ; }
92+
93+ /// <summary>
94+ /// Additional mount paths beyond the defaults.
95+ /// </summary>
96+ public IList < string > AdditionalMounts { get ; set ; }
97+
98+ /// <summary>
99+ /// Pull policy: Always, IfNotPresent, Never.
100+ /// </summary>
101+ public string PullPolicy { get ; set ; } = "IfNotPresent" ;
102+ }
103+
104+ /// <summary>
105+ /// Standard VC directory mounts configuration.
106+ /// </summary>
107+ public class ContainerMountConfig
108+ {
109+ /// <summary>
110+ /// Mount the packages directory (/vc/packages).
111+ /// </summary>
112+ public bool Packages { get ; set ; } = true ;
113+
114+ /// <summary>
115+ /// Mount the logs directory (/vc/logs).
116+ /// </summary>
117+ public bool Logs { get ; set ; } = true ;
118+
119+ /// <summary>
120+ /// Mount the state directory (/vc/state).
121+ /// </summary>
122+ public bool State { get ; set ; } = true ;
123+
124+ /// <summary>
125+ /// Mount the temp directory (/vc/temp).
126+ /// </summary>
127+ public bool Temp { get ; set ; } = true ;
128+ }
129+ }
0 commit comments