Skip to content

Commit f893633

Browse files
committed
Image generation code is merged in from obsolete App Image Generator service
1 parent 5ccee4f commit f893633

21 files changed

Lines changed: 1094 additions & 704 deletions

.vscode/launch.json

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
11
{
2-
// VS Code debugger launch file. When you press F5 in VS Code,
3-
// this debugger configuration will launch.
4-
"version": "0.2.0",
5-
"configurations": [
6-
{
7-
"name": "launch.backend",
8-
"type": "coreclr",
9-
"request": "launch",
10-
"preLaunchTask": "tasks.build-backend",
11-
"postDebugTask": "tasks.stop-debugging",
12-
"program": "${workspaceFolder}/apps/pwabuilder/bin/Debug/net9.0/PWABuilder.dll",
13-
"serverReadyAction": {
14-
"action": "startDebugging",
15-
"name": "launch.edge",
16-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
17-
},
18-
"cwd": "${workspaceFolder}/apps/pwabuilder",
19-
"env": {
20-
"LIGHTHOUSE_WORKDIR": "./node-scripts",
21-
"NODE_BIN": "C:/Program Files/nodejs/node.exe"
22-
}
23-
},
24-
{
25-
"name": "launch.edge",
26-
"url": "https://localhost:7217",
27-
"request": "launch",
28-
"type": "msedge",
29-
"webRoot": "${workspaceFolder}/apps/pwabuilder/Frontend",
30-
"sourceMaps": true,
31-
"trace": true,
32-
"preLaunchTask": "tasks.launch-vite",
33-
"postDebugTask": "tasks.stop-debugging"
34-
},
35-
{
36-
"name": "Attach: Google Play Service",
37-
"type": "node",
38-
"request": "attach",
39-
"preLaunchTask": "tasks.google-play:dev",
40-
"env": {
41-
"NODE_ENV": "test"
42-
},
43-
"port": 5858,
44-
"skipFiles": [
45-
"<node_internals>/**"
46-
],
47-
"localRoot": "${workspaceFolder}/apps/pwabuilder-google-play",
48-
"remoteRoot": "${workspaceFolder}/apps/pwabuilder-google-play"
49-
},
50-
{
51-
"name": "launch.microsoft-package-generator",
52-
"type": "coreclr",
53-
"request": "launch",
54-
"preLaunchTask": "tasks.build-microsoft-package-generator",
55-
"postDebugTask": "tasks.stop-debugging",
56-
"program": "${workspaceFolder}/apps/pwabuilder-microsoft-store/bin/Debug/net9.0/PWABuilder.MicrosoftStore.dll",
57-
"args": [],
58-
"cwd": "${workspaceFolder}/apps/pwabuilder-microsoft-store",
59-
"stopAtEntry": false,
60-
"env": {
61-
"ASPNETCORE_ENVIRONMENT": "Development"
62-
}
63-
},
64-
],
65-
"compounds": [
66-
{
67-
"name": "Launch All PWABuilder (Local)",
68-
"configurations": [
69-
"launch.backend",
70-
"launch.microsoft-package-generator",
71-
"Attach: Google Play Service"
72-
]
73-
}
74-
]
2+
// VS Code debugger launch file. When you press F5 in VS Code,
3+
// this debugger configuration will launch.
4+
"version": "0.2.0",
5+
"configurations": [
6+
{
7+
"name": "launch.backend",
8+
"type": "coreclr",
9+
"request": "launch",
10+
"preLaunchTask": "tasks.build-backend",
11+
"postDebugTask": "tasks.stop-debugging",
12+
"program": "${workspaceFolder}/apps/pwabuilder/bin/Debug/net10.0/PWABuilder.dll",
13+
"serverReadyAction": {
14+
"action": "startDebugging",
15+
"name": "launch.edge",
16+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
17+
},
18+
"cwd": "${workspaceFolder}/apps/pwabuilder",
19+
"env": {
20+
"LIGHTHOUSE_WORKDIR": "./node-scripts",
21+
"NODE_BIN": "C:/Program Files/nodejs/node.exe"
22+
}
23+
},
24+
{
25+
"name": "launch.edge",
26+
"url": "https://localhost:7217",
27+
"request": "launch",
28+
"type": "msedge",
29+
"webRoot": "${workspaceFolder}/apps/pwabuilder/Frontend",
30+
"sourceMaps": true,
31+
"trace": true,
32+
"preLaunchTask": "tasks.launch-vite",
33+
"postDebugTask": "tasks.stop-debugging"
34+
},
35+
{
36+
"name": "Attach: Google Play Service",
37+
"type": "node",
38+
"request": "attach",
39+
"preLaunchTask": "tasks.google-play:dev",
40+
"env": {
41+
"NODE_ENV": "test"
42+
},
43+
"port": 5858,
44+
"skipFiles": [
45+
"<node_internals>/**"
46+
],
47+
"localRoot": "${workspaceFolder}/apps/pwabuilder-google-play",
48+
"remoteRoot": "${workspaceFolder}/apps/pwabuilder-google-play"
49+
},
50+
{
51+
"name": "launch.microsoft-package-generator",
52+
"type": "coreclr",
53+
"request": "launch",
54+
"preLaunchTask": "tasks.build-microsoft-package-generator",
55+
"postDebugTask": "tasks.stop-debugging",
56+
"program": "${workspaceFolder}/apps/pwabuilder-microsoft-store/bin/Debug/net10.0/PWABuilder.MicrosoftStore.dll",
57+
"args": [],
58+
"cwd": "${workspaceFolder}/apps/pwabuilder-microsoft-store",
59+
"stopAtEntry": false,
60+
"env": {
61+
"ASPNETCORE_ENVIRONMENT": "Development"
62+
}
63+
},
64+
],
65+
"compounds": [
66+
{
67+
"name": "Launch All PWABuilder (Local)",
68+
"configurations": [
69+
"launch.backend",
70+
"launch.microsoft-package-generator",
71+
"Attach: Google Play Service"
72+
]
73+
}
74+
]
7575
}

Dockerfile.production

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official ASP.NET Core runtime as the base image
2-
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
2+
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
33

44
# Install dependencies for Puppeteer (runtime only, no Node.js needed here)
55
# Install Chrome version 130.0.6723.116 which is compatible with PuppeteerSharp 20.2.x
@@ -37,7 +37,7 @@ ENV ASPNETCORE_ENVIRONMENT=Production
3737

3838

3939
# Use the SDK image to build the application
40-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
40+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
4141

4242
# Install Node.js in build stage
4343
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
@@ -76,7 +76,7 @@ FROM build AS publish
7676
RUN dotnet publish "PWABuilder.csproj" -c Release -o /app/publish /p:UseAppHost=false
7777

7878
# Final stage/image
79-
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
79+
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
8080

8181
# Chrome for Testing: please review all the latest versions here:
8282
# https://googlechromelabs.github.io/chrome-for-testing/

apps/pwabuilder-microsoft-store/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Use Windows Server as the base image - using latest 2022 LTSC build for GitHub Actions compatibility
22
FROM mcr.microsoft.com/windows/server:ltsc2022-KB5070884
33

4-
# Install .NET 9.0 SDK (includes runtime)
4+
# Install .NET 10.0 SDK (includes runtime)
55
RUN powershell -Command \
66
"$ProgressPreference = 'SilentlyContinue'; \
7-
Invoke-WebRequest -Uri 'https://dotnetcli.azureedge.net/dotnet/Sdk/9.0.100/dotnet-sdk-9.0.100-win-x64.exe' -OutFile 'dotnet-sdk-installer.exe'; \
7+
Invoke-WebRequest -Uri 'https://dotnetcli.azureedge.net/dotnet/Sdk/10.0.100/dotnet-sdk-10.0.100-win-x64.exe' -OutFile 'dotnet-sdk-installer.exe'; \
88
Start-Process -FilePath 'dotnet-sdk-installer.exe' -ArgumentList '/quiet' -Wait; \
99
Remove-Item 'dotnet-sdk-installer.exe'"
1010

apps/pwabuilder-microsoft-store/PWABuilder.MicrosoftStore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
55
<nullable>enable</nullable>
66
<Company>Microsoft</Company>
Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
{
2-
"Logging": {
3-
"LogLevel": {
4-
"Default": "Information",
5-
"Microsoft": "Warning",
6-
"Microsoft.Hosting.Lifetime": "Information"
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AppSettings": {
10+
"PwaBuilderPath": "bin\\Debug\\net10.0\\Resources\\cli\\pwabuilder\\pwa_builder.exe",
11+
"PwaInstallerPath": "bin\\Debug\\net10.0\\Resources\\cli\\pwainstaller\\pwainstaller.exe",
12+
"InstallScriptPath": "bin\\Debug\\net10.0\\Resources\\install.ps1",
13+
"ClassicWindowsAppPackagePath": "bin\\Debug\\net10.0\\Resources\\ClassicWindowsAppPackage.appx",
14+
"SpartanWindowsAppPackagePath": "bin\\Debug\\net10.0\\Resources\\SpartanWindowsAppPackage.appx",
15+
"SpartanInstallScriptPath": "bin\\Debug\\net10.0\\Resources\\install-edgehtml.ps1",
16+
"SpartanReadmePath": "bin\\Debug\\net10.0\\Resources\\next-steps-edgehtml.html",
17+
"StoreSupportedLanguagesPath": "bin\\Debug\\net10.0\\Resources\\store-supported-languages.txt",
18+
"PriPath": "bin\\Debug\\net10.0\\Resources\\resources.pri",
19+
"ReadmePath": "bin\\Debug\\net10.0\\Resources\\next-steps.html",
20+
"OutputDirectory": "%temp%",
21+
"WindowsSdkDirectory": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64",
22+
"UrlLoggerService": "",
23+
"ImageGeneratorApiUrl": "https://appimagegenerator-prod.azurewebsites.net/api/image",
24+
"ApplicationInsightsConnectionString": ""
725
}
8-
},
9-
"AppSettings": {
10-
"PwaBuilderPath": "bin\\Debug\\net9.0\\Resources\\cli\\pwabuilder\\pwa_builder.exe",
11-
"PwaInstallerPath": "bin\\Debug\\net9.0\\Resources\\cli\\pwainstaller\\pwainstaller.exe",
12-
"InstallScriptPath": "bin\\Debug\\net9.0\\Resources\\install.ps1",
13-
"ClassicWindowsAppPackagePath": "bin\\Debug\\net9.0\\Resources\\ClassicWindowsAppPackage.appx",
14-
"SpartanWindowsAppPackagePath": "bin\\Debug\\net9.0\\Resources\\SpartanWindowsAppPackage.appx",
15-
"SpartanInstallScriptPath": "bin\\Debug\\net9.0\\Resources\\install-edgehtml.ps1",
16-
"SpartanReadmePath": "bin\\Debug\\net9.0\\Resources\\next-steps-edgehtml.html",
17-
"StoreSupportedLanguagesPath": "bin\\Debug\\net9.0\\Resources\\store-supported-languages.txt",
18-
"PriPath": "bin\\Debug\\net9.0\\Resources\\resources.pri",
19-
"ReadmePath": "bin\\Debug\\net9.0\\Resources\\next-steps.html",
20-
"OutputDirectory": "%temp%",
21-
"WindowsSdkDirectory": "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64",
22-
"UrlLoggerService": "",
23-
"ImageGeneratorApiUrl": "https://appimagegenerator-prod.azurewebsites.net/api/image",
24-
"ApplicationInsightsConnectionString": ""
25-
26-
}
27-
}
26+
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"version": "0.2.0",
3-
"configurations": [
4-
{
5-
"name": "launch.backend",
6-
"type": "coreclr",
7-
"request": "launch",
8-
"preLaunchTask": "tasks.build-backend",
9-
"postDebugTask": "tasks.stop-debugging",
10-
"program": "${workspaceFolder}/bin/Debug/net9.0/PWABuilder.dll",
11-
"serverReadyAction": {
12-
"action": "startDebugging",
13-
"name": "launch.edge",
14-
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
15-
}
16-
},
17-
{
18-
"name": "launch.edge",
19-
"url": "https://localhost:7217",
20-
"request": "launch",
21-
"type": "msedge",
22-
"webRoot": "${workspaceFolder}/frontend",
23-
"sourceMaps": true,
24-
"trace": true,
25-
"preLaunchTask": "tasks.launch-vite",
26-
"postDebugTask": "tasks.stop-debugging"
27-
}
28-
]
29-
}
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "launch.backend",
6+
"type": "coreclr",
7+
"request": "launch",
8+
"preLaunchTask": "tasks.build-backend",
9+
"postDebugTask": "tasks.stop-debugging",
10+
"program": "${workspaceFolder}/bin/Debug/net10.0/PWABuilder.dll",
11+
"serverReadyAction": {
12+
"action": "startDebugging",
13+
"name": "launch.edge",
14+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
15+
}
16+
},
17+
{
18+
"name": "launch.edge",
19+
"url": "https://localhost:7217",
20+
"request": "launch",
21+
"type": "msedge",
22+
"webRoot": "${workspaceFolder}/frontend",
23+
"sourceMaps": true,
24+
"trace": true,
25+
"preLaunchTask": "tasks.launch-vite",
26+
"postDebugTask": "tasks.stop-debugging"
27+
}
28+
]
29+
}

apps/pwabuilder/Controllers/ImagesController.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Drawing;
2+
using System.Text.Json;
13
using Microsoft.AspNetCore.Mvc;
24
using PuppeteerSharp;
35
using PWABuilder.Common;
@@ -10,14 +12,12 @@ namespace PWABuilder.Controllers;
1012
[Route("api/[controller]")]
1113
public class ImagesController : ControllerBase
1214
{
13-
private readonly IRedisCache analysisDb;
1415
private readonly HttpClient http;
1516
private readonly ILogger<ImagesController> logger;
1617
private const int maxSize = 1024 * 1024 * 5; // 5mb
1718

18-
public ImagesController(IRedisCache analysisDb, IHttpClientFactory httpClientFactory, ILogger<ImagesController> logger)
19+
public ImagesController(IHttpClientFactory httpClientFactory, ILogger<ImagesController> logger)
1920
{
20-
this.analysisDb = analysisDb;
2121
this.http = httpClientFactory.CreateClient(Constants.PwaBuilderAgentHttpClient);
2222
this.logger = logger;
2323
}
@@ -72,6 +72,28 @@ public async Task<IActionResult> GetSafeImageForAnalysis([FromQuery] string anal
7272
}
7373
}
7474

75+
/// <summary>
76+
/// Generates store images from a base image for one or more platforms.
77+
/// </summary>
78+
/// <param name="request">The image generation parameters including the base image file, padding, color, and target platforms.</param>
79+
/// <returns>The generated store images.</returns>
80+
[HttpPost("generateStoreImages")]
81+
[RequestFormLimits(MultipartBodyLengthLimit = 5 * 1024 * 1024)]
82+
[RequestSizeLimit(5 * 1024 * 1024)]
83+
public async Task<IActionResult> GenerateStoreImages([FromForm] StoreImageGenerationRequest request, [FromServices] StoreImageGenerationService imageGenerator, CancellationToken cancelToken)
84+
{
85+
try
86+
{
87+
var storeImagesZipStream = await imageGenerator.CreateStoreImagesZipAsync(request, cancelToken);
88+
return File(storeImagesZipStream, "application/zip", "appstore-images.zip");
89+
}
90+
catch (Exception imageGeneratorError)
91+
{
92+
logger.LogError(imageGeneratorError, "Error generating store images for image of size {size} for {platforms} with padding {padding} and color {color}.", request.BaseImage.Length, string.Join(", ", request.Platform), request.Padding, request.Color);
93+
return StatusCode(500, $"An error occurred while generating store images: {imageGeneratorError.Message}");
94+
}
95+
}
96+
7597
private async Task<HttpClientExtensions.LimitedReadStreamWithMediaType?> TryDownloadImageViaPuppeteer(string analysisId, Uri imageUrl, IPuppeteerService puppeteer, IRedisCache db)
7698
{
7799
try

0 commit comments

Comments
 (0)