Skip to content

Commit aeaabfd

Browse files
committed
More fixes for docker file
1 parent e246107 commit aeaabfd

3 files changed

Lines changed: 151 additions & 115 deletions

File tree

apps/pwabuilder-microsoft-store/Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ RUN powershell -Command \
88
Start-Process -FilePath 'dotnet-sdk-installer.exe' -ArgumentList '/quiet' -Wait; \
99
Remove-Item 'dotnet-sdk-installer.exe'"
1010

11-
# Install Windows SDK (needed for MSIX packaging tools)
12-
# Find latest SDK versions here: https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/
13-
RUN powershell -Command \
14-
"$ProgressPreference = 'SilentlyContinue'; \
15-
Invoke-WebRequest -Uri 'https://go.microsoft.com/fwlink/?linkid=2327008' -OutFile 'winsdksetup.exe'; \
16-
Start-Process -FilePath 'winsdksetup.exe' -ArgumentList '/quiet', '/features', 'OptionId.WindowsDesktopDebuggers', 'OptionId.WindowsDesktopSoftwareDevelopmentKit', 'OptionId.WindowsSoftwareLogoToolkit' -Wait; \
17-
Remove-Item 'winsdksetup.exe'"
11+
RUN ["powershell.exe", "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser"]
1812

19-
# Add Windows SDK tools to PATH
20-
RUN setx PATH "%PATH%;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.4654\\x64"
13+
# Install Windows SDK (needed for MSIX packaging tools)
14+
RUN powershell Invoke-WebRequest https://go.microsoft.com/fwlink/?linkid=2120843 -OutFile ./downloadsdk.exe
15+
RUN ["powershell.exe", "Start-Process -Wait -FilePath ./downloadsdk.exe -ArgumentList '/quiet /norestart /log log.txt'"]
16+
RUN ["powershell.exe", "Get-Content log.txt"]
2117

2218
WORKDIR /app
2319
EXPOSE 5000
Lines changed: 145 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Net.Http;
45
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
@@ -10,126 +11,165 @@
1011
using PWABuilder.MicrosoftStore.Models;
1112
using PWABuilder.MicrosoftStore.Services;
1213

13-
namespace PWABuilder.MicrosoftStore
14+
namespace PWABuilder.MicrosoftStore;
15+
16+
public class Startup
1417
{
15-
public class Startup
18+
readonly string AllowedOriginsPolicyName = "allowedOrigins";
19+
20+
public Startup(IConfiguration configuration)
1621
{
17-
readonly string AllowedOriginsPolicyName = "allowedOrigins";
22+
Configuration = configuration;
23+
}
1824

19-
public Startup(IConfiguration configuration)
25+
public IConfiguration Configuration { get; }
26+
27+
// This method gets called by the runtime. Use this method to add services to the container.
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
31+
32+
// Validate Windows SDK directory exists
33+
ValidateWindowsSdkDirectory();
34+
35+
services.AddCors(options =>
2036
{
21-
Configuration = configuration;
22-
}
37+
options.AddPolicy(
38+
name: AllowedOriginsPolicyName,
39+
builder =>
40+
builder
41+
.SetIsOriginAllowed(CheckAllowedOriginCors)
42+
.AllowAnyHeader()
43+
.AllowAnyMethod()
44+
);
45+
});
2346

24-
public IConfiguration Configuration { get; }
47+
var appSettings = Configuration.GetSection("AppSettings");
48+
var aiOptions = setUpAppInsights(appSettings);
2549

26-
// This method gets called by the runtime. Use this method to add services to the container.
27-
public void ConfigureServices(IServiceCollection services)
28-
{
29-
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
30-
services.AddCors(options =>
31-
{
32-
options.AddPolicy(
33-
name: AllowedOriginsPolicyName,
34-
builder =>
35-
builder
36-
.SetIsOriginAllowed(CheckAllowedOriginCors)
37-
.AllowAnyHeader()
38-
.AllowAnyMethod()
39-
);
40-
});
50+
services.AddTransient<PwaBuilderWrapper>();
51+
services.AddTransient<WindowsAppPackageCreator>();
52+
services.AddTransient<WindowsAppPackageInspector>();
53+
services.AddTransient<WindowsAppPackageUpdater>();
54+
services.AddTransient<WindowsAppPackageBundler>();
55+
services.AddTransient<WindowsActionsService>();
56+
services.AddTransient<LooseLayoutPackager>();
57+
services.AddTransient<SpartanWindowsPackageCreator>();
58+
services.AddTransient<ModernWindowsPackageCreator>();
59+
services.AddTransient<ClassicWindowsPackageCreator>();
60+
services.AddTransient<ImageGenerator>();
61+
services.AddTransient<WebManifestFinder>();
62+
services.AddTransient<MakePriWrapper>();
63+
services.AddTransient<MakeAppxWrapper>();
64+
services.AddTransient<TempDirectory>();
65+
services.AddTransient<Analytics>();
66+
services.AddSingleton<ZombieProcessKiller>();
67+
services.AddTransient<ProcessRunner>();
68+
services.AddApplicationInsightsTelemetry(aiOptions);
69+
services.AddHttpClient();
70+
services
71+
.AddHttpClient(
72+
"NoRedirectClient",
73+
client =>
74+
{
75+
client.AddLatestEdgeUserAgent();
76+
}
77+
)
78+
.ConfigurePrimaryHttpMessageHandler(() =>
79+
new HttpClientHandler { AllowAutoRedirect = false }
80+
);
4181

42-
var appSettings = Configuration.GetSection("AppSettings");
43-
var aiOptions = setUpAppInsights(appSettings);
82+
services.AddControllers();
83+
}
4484

45-
services.AddTransient<PwaBuilderWrapper>();
46-
services.AddTransient<WindowsAppPackageCreator>();
47-
services.AddTransient<WindowsAppPackageInspector>();
48-
services.AddTransient<WindowsAppPackageUpdater>();
49-
services.AddTransient<WindowsAppPackageBundler>();
50-
services.AddTransient<WindowsActionsService>();
51-
services.AddTransient<LooseLayoutPackager>();
52-
services.AddTransient<SpartanWindowsPackageCreator>();
53-
services.AddTransient<ModernWindowsPackageCreator>();
54-
services.AddTransient<ClassicWindowsPackageCreator>();
55-
services.AddTransient<ImageGenerator>();
56-
services.AddTransient<WebManifestFinder>();
57-
services.AddTransient<MakePriWrapper>();
58-
services.AddTransient<MakeAppxWrapper>();
59-
services.AddTransient<TempDirectory>();
60-
services.AddTransient<Analytics>();
61-
services.AddSingleton<ZombieProcessKiller>();
62-
services.AddTransient<ProcessRunner>();
63-
services.AddApplicationInsightsTelemetry(aiOptions);
64-
services.AddHttpClient();
65-
services
66-
.AddHttpClient(
67-
"NoRedirectClient",
68-
client =>
69-
{
70-
client.AddLatestEdgeUserAgent();
71-
}
72-
)
73-
.ConfigurePrimaryHttpMessageHandler(() =>
74-
new HttpClientHandler { AllowAutoRedirect = false }
75-
);
85+
static ApplicationInsightsServiceOptions setUpAppInsights(IConfigurationSection appSettings)
86+
{
87+
var connectionString = appSettings["ApplicationInsightsConnectionString"];
88+
var aiOptions = new ApplicationInsightsServiceOptions();
89+
aiOptions.EnableRequestTrackingTelemetryModule = false;
90+
aiOptions.EnableDependencyTrackingTelemetryModule = true;
91+
aiOptions.EnableHeartbeat = false;
92+
aiOptions.EnableAzureInstanceMetadataTelemetryModule = false;
93+
aiOptions.EnableActiveTelemetryConfigurationSetup = false;
94+
aiOptions.EnableAdaptiveSampling = false;
95+
aiOptions.EnableAppServicesHeartbeatTelemetryModule = false;
96+
aiOptions.EnableAuthenticationTrackingJavaScript = false;
97+
aiOptions.ConnectionString = connectionString;
98+
return aiOptions;
99+
}
76100

77-
services.AddControllers();
78-
}
101+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
102+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
103+
{
104+
app.UseDeveloperExceptionPage();
105+
app.UseHttpsRedirection();
106+
app.UseStaticFiles();
107+
app.UseRouting();
108+
app.UseCors(AllowedOriginsPolicyName);
109+
app.UseAuthorization();
110+
app.UseEndpoints(endpoints =>
111+
{
112+
endpoints.MapControllers();
113+
});
114+
}
79115

80-
static ApplicationInsightsServiceOptions setUpAppInsights(IConfigurationSection appSettings)
116+
private bool CheckAllowedOriginCors(string origin)
117+
{
118+
//Add to this list if more domains call this service
119+
var allowedOrigins = new[]
81120
{
82-
var connectionString = appSettings["ApplicationInsightsConnectionString"];
83-
var aiOptions = new ApplicationInsightsServiceOptions();
84-
aiOptions.EnableRequestTrackingTelemetryModule = false;
85-
aiOptions.EnableDependencyTrackingTelemetryModule = true;
86-
aiOptions.EnableHeartbeat = false;
87-
aiOptions.EnableAzureInstanceMetadataTelemetryModule = false;
88-
aiOptions.EnableActiveTelemetryConfigurationSetup = false;
89-
aiOptions.EnableAdaptiveSampling = false;
90-
aiOptions.EnableAppServicesHeartbeatTelemetryModule = false;
91-
aiOptions.EnableAuthenticationTrackingJavaScript = false;
92-
aiOptions.ConnectionString = connectionString;
93-
return aiOptions;
94-
}
121+
"https://www.pwabuilder.com",
122+
"https://pwabuilder.com",
123+
"https://preview.pwabuilder.com",
124+
"https://localhost:3333",
125+
"https://localhost:3000",
126+
"http://localhost:3333",
127+
"http://localhost:3000",
128+
"https://localhost:8000",
129+
"http://localhost:8000",
130+
"https://localhost:7217",
131+
"http://localhost:5777",
132+
"https://nice-field-047c1420f.azurestaticapps.net",
133+
"https://partner.microsoft.com",
134+
"https://brave-grass-02c461d10.1.azurestaticapps.net",
135+
"https://pwabuilder-summer25-consolidation.azurewebsites.net",
136+
};
137+
return allowedOrigins.Any(o => origin.Contains(o, StringComparison.OrdinalIgnoreCase));
138+
}
95139

96-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
97-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
140+
/// <summary>
141+
/// Validates that the Windows SDK directory specified in AppSettings exists on disk.
142+
/// Throws an exception if the directory is not found.
143+
/// </summary>
144+
private void ValidateWindowsSdkDirectory()
145+
{
146+
var appSettings = Configuration.GetSection("AppSettings");
147+
var windowsSdkDirectory = appSettings["WindowsSdkDirectory"];
148+
149+
if (string.IsNullOrWhiteSpace(windowsSdkDirectory))
98150
{
99-
app.UseDeveloperExceptionPage();
100-
app.UseHttpsRedirection();
101-
app.UseStaticFiles();
102-
app.UseRouting();
103-
app.UseCors(AllowedOriginsPolicyName);
104-
app.UseAuthorization();
105-
app.UseEndpoints(endpoints =>
106-
{
107-
endpoints.MapControllers();
108-
});
151+
throw new InvalidOperationException(
152+
"WindowsSdkDirectory is not configured in AppSettings. " +
153+
"Please ensure the Windows SDK is installed and the correct path is specified in configuration.");
109154
}
110-
111-
private bool CheckAllowedOriginCors(string origin)
155+
156+
if (!Directory.Exists(windowsSdkDirectory))
157+
{
158+
throw new DirectoryNotFoundException(
159+
$"Windows SDK directory not found: '{windowsSdkDirectory}'. " +
160+
"Please ensure the Windows SDK is properly installed. " +
161+
"Expected tools like makeappx.exe should be available in this directory.");
162+
}
163+
164+
// Additional validation: check if makeappx.exe exists in the SDK directory
165+
var makeAppxPath = Path.Combine(windowsSdkDirectory, "makeappx.exe");
166+
if (!File.Exists(makeAppxPath))
112167
{
113-
//Add to this list if more domains call this service
114-
var allowedOrigins = new[]
115-
{
116-
"https://www.pwabuilder.com",
117-
"https://pwabuilder.com",
118-
"https://preview.pwabuilder.com",
119-
"https://localhost:3333",
120-
"https://localhost:3000",
121-
"http://localhost:3333",
122-
"http://localhost:3000",
123-
"https://localhost:8000",
124-
"http://localhost:8000",
125-
"https://localhost:7217",
126-
"http://localhost:5777",
127-
"https://nice-field-047c1420f.azurestaticapps.net",
128-
"https://partner.microsoft.com",
129-
"https://brave-grass-02c461d10.1.azurestaticapps.net",
130-
"https://pwabuilder-summer25-consolidation.azurewebsites.net",
131-
};
132-
return allowedOrigins.Any(o => origin.Contains(o, StringComparison.OrdinalIgnoreCase));
168+
throw new FileNotFoundException(
169+
$"Required tool 'makeappx.exe' not found in Windows SDK directory: '{windowsSdkDirectory}'. " +
170+
"Please ensure the Windows SDK is properly installed with MSIX packaging tools.");
133171
}
172+
173+
Console.WriteLine($"✓ Windows SDK validated successfully at: {windowsSdkDirectory}");
134174
}
135175
}

apps/pwabuilder-microsoft-store/appsettings.Production.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"PriPath": "Resources\\resources.pri",
2222
"ReadmePath": "Resources\\next-steps.html",
2323
"OutputDirectory": "%temp%",
24-
"WindowsSdkDirectory": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64",
24+
"WindowsSdkDirectory": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\x64",
2525
"UrlLoggerService": "",
2626
"ImageGeneratorApiUrl": "https://appimagegenerator-prod.azurewebsites.net/api/image",
2727
"ApplicationInsightsConnectionString": ""

0 commit comments

Comments
 (0)