@@ -22,10 +22,42 @@ public static IResourceBuilder<DevProxyExecutableResource> AddDevProxyExecutable
2222 {
2323 var resource = new DevProxyExecutableResource ( name ) ;
2424
25- return builder . AddResource ( resource )
25+ var resourceBuilder = builder . AddResource ( resource )
2626 . WithArgs ( "--as-system-proxy" , "false" )
2727 . WithHttpEndpoint ( targetPort : 8000 , name : DevProxyResource . ProxyEndpointName )
2828 . WithHttpEndpoint ( targetPort : 8897 , name : DevProxyResource . ApiEndpointName ) ;
29+
30+ return resourceBuilder ;
31+ }
32+
33+ /// <summary>
34+ /// Configures the DevProxy executable to use a specific configuration file.
35+ /// </summary>
36+ /// <param name="builder">The resource builder for the DevProxy executable resource.</param>
37+ /// <param name="configFile">The path to the configuration file.</param>
38+ /// <returns>The resource builder for method chaining.</returns>
39+ public static IResourceBuilder < DevProxyExecutableResource > WithConfigFile (
40+ this IResourceBuilder < DevProxyExecutableResource > builder ,
41+ string configFile )
42+ {
43+ return builder . WithArgs ( "-c" , Path . GetFullPath ( configFile , builder . ApplicationBuilder . AppHostDirectory ) ) ;
44+ }
45+
46+ /// <summary>
47+ /// Configures the DevProxy executable to watch specific URLs.
48+ /// </summary>
49+ /// <param name="builder">The resource builder for the DevProxy executable resource.</param>
50+ /// <param name="urlsToWatch">The collection of URLs to watch.</param>
51+ /// <returns>The resource builder for method chaining.</returns>
52+ public static IResourceBuilder < DevProxyExecutableResource > WithUrlsToWatch (
53+ this IResourceBuilder < DevProxyExecutableResource > builder ,
54+ Func < IEnumerable < string > > urlsToWatch )
55+ {
56+ return builder . WithArgs ( context =>
57+ {
58+ context . Args . Add ( "-u" ) ;
59+ context . Args . Add ( string . Join ( " " , urlsToWatch ( ) ) ) ;
60+ } ) ;
2961 }
3062
3163 /// <summary>
@@ -40,20 +72,94 @@ public static IResourceBuilder<DevProxyContainerResource> AddDevProxyContainer(
4072 {
4173 var resource = new DevProxyContainerResource ( name ) ;
4274
43- return builder . AddResource ( resource )
75+ var resourceBuilder = builder . AddResource ( resource )
4476 . WithImage ( DevProxyContainerImageTags . Image )
4577 . WithImageRegistry ( DevProxyContainerImageTags . Registry )
4678 . WithImageTag ( DevProxyContainerImageTags . Tag )
4779 . WithHttpEndpoint ( targetPort : 8000 , name : DevProxyResource . ProxyEndpointName )
4880 . WithHttpEndpoint ( targetPort : 8897 , name : DevProxyResource . ApiEndpointName ) ;
81+
82+ return resourceBuilder ;
83+ }
84+
85+ /// <summary>
86+ /// Configures the DevProxy container to mount a certificate folder.
87+ /// </summary>
88+ /// <param name="builder">The resource builder for the DevProxy container resource.</param>
89+ /// <param name="certFolder">The path to the certificate folder on the host.</param>
90+ /// <returns>The resource builder for method chaining.</returns>
91+ public static IResourceBuilder < DevProxyContainerResource > WithCertFolder (
92+ this IResourceBuilder < DevProxyContainerResource > builder ,
93+ string certFolder )
94+ {
95+ return builder . WithBindMount (
96+ Path . GetFullPath ( certFolder , builder . ApplicationBuilder . AppHostDirectory ) ,
97+ "/home/devproxy/.config/dev-proxy/rootCert" ) ;
98+ }
99+
100+ /// <summary>
101+ /// Configures the DevProxy executable to use a specific configuration file.
102+ /// </summary>
103+ /// <param name="builder">The resource builder for the DevProxy executable resource.</param>
104+ /// <param name="configFile">The path to the configuration file.</param>
105+ /// <returns>The resource builder for method chaining.</returns>
106+ public static IResourceBuilder < DevProxyContainerResource > WithConfigFile (
107+ this IResourceBuilder < DevProxyContainerResource > builder ,
108+ string configFile )
109+ {
110+ return builder . WithArgs ( "-c" , configFile ) ;
111+ }
112+
113+ /// <summary>
114+ /// Configures the DevProxy container to mount a configuration folder.
115+ /// </summary>
116+ /// <param name="builder">The resource builder for the DevProxy container resource.</param>
117+ /// <param name="configFolder">The path to the configuration folder on the host.</param>
118+ /// <returns>The resource builder for method chaining.</returns>
119+ public static IResourceBuilder < DevProxyContainerResource > WithConfigFolder (
120+ this IResourceBuilder < DevProxyContainerResource > builder ,
121+ string configFolder )
122+ {
123+ return builder . WithBindMount (
124+ Path . GetFullPath ( configFolder , builder . ApplicationBuilder . AppHostDirectory ) ,
125+ "/config" ) ;
126+ }
127+
128+ /// <summary>
129+ /// Configures the DevProxy container to watch specific URLs.
130+ /// </summary>
131+ /// <param name="builder">The resource builder for the DevProxy container resource.</param>
132+ /// <param name="urlsToWatch">The collection of URLs to watch.</param>
133+ /// <returns>The resource builder for method chaining.</returns>
134+ public static IResourceBuilder < DevProxyContainerResource > WithUrlsToWatch (
135+ this IResourceBuilder < DevProxyContainerResource > builder ,
136+ Func < IEnumerable < string > > urlsToWatch )
137+ {
138+ return builder . WithArgs ( context =>
139+ {
140+ context . Args . Add ( "-u" ) ;
141+ context . Args . Add ( string . Join ( " " , urlsToWatch ( ) ) ) ;
142+ } ) ;
49143 }
50144}
51145
146+ /// <summary>
147+ /// Contains container image tags and registry information for DevProxy.
148+ /// </summary>
52149internal static class DevProxyContainerImageTags
53150{
151+ /// <summary>
152+ /// The container registry hosting the DevProxy image.
153+ /// </summary>
54154 internal const string Registry = "ghcr.io" ;
55155
156+ /// <summary>
157+ /// The DevProxy container image name.
158+ /// </summary>
56159 internal const string Image = "dotnet/dev-proxy" ;
57160
161+ /// <summary>
162+ /// The DevProxy container image tag.
163+ /// </summary>
58164 internal const string Tag = "latest" ;
59165}
0 commit comments