Skip to content

Commit

Permalink
Improved logging and stop the Renamedlls task if recompression fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
stavroskasidis committed Nov 23, 2022
1 parent f2e716c commit bc08434
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 33 deletions.
25 changes: 25 additions & 0 deletions sampleapps/BlazorHostedSampleApp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="BlazorWasmAntivirusProtection" Version="2.2.1-test" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\BlazorHostedSampleApp.Shared.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
$(RestoreAdditionalProjectSources);
$(MSBuildThisFileDirectory)../../../artifacts/nuget
</RestoreAdditionalProjectSources>
<UserSecretsId>ab18ecad-eb5a-4dc2-bcd9-12a62054d7f0</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!--<DisableRenamingDlls>true</DisableRenamingDlls>-->
<!--<RenameDllsTo>blazor</RenameDllsTo>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.0" />
<PackageReference Include="BlazorWasmAntivirusProtection" Version="2.2.1-test" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions sampleapps/BlazorHostedSampleApp/Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Server/BlazorHostedSampleApp.Server.csproj", "Server/"]
COPY ["Client/BlazorHostedSampleApp.Client.csproj", "Client/"]
COPY ["Shared/BlazorHostedSampleApp.Shared.csproj", "Shared/"]
RUN dotnet restore "Server/BlazorHostedSampleApp.Server.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "BlazorHostedSampleApp.Server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BlazorHostedSampleApp.Server.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BlazorHostedSampleApp.Server.dll"]
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55913",
"sslPort": 44338
}
"profiles": {
"BlazorHostedSampleApp.Server": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7107;http://localhost:5266"
},
"profiles": {
"BlazorHostedSampleApp.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7107;http://localhost:5266",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55913",
"sslPort": 44338
}
}
}
30 changes: 24 additions & 6 deletions src/BlazorWasmAntivirusProtection.Tasks/RenameDlls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ public override bool Execute()
if (File.Exists(bootJsonGzPath) && BlazorEnableCompression)
{
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Recompressing \"{bootJsonGzPath}\"");
GZipCompress(bootJsonPath, bootJsonGzPath);
if(!GZipCompress(bootJsonPath, bootJsonGzPath))
{
return false;
}
}
if (File.Exists(bootJsonBrPath) && BlazorEnableCompression)
{
Log.LogMessage(MessageImportance.High, $"BlazorWasmAntivirusProtection: Recompressing \"{bootJsonBrPath}\"");
BrotliCompress(bootJsonPath, bootJsonBrPath);
if(!BrotliCompress(bootJsonPath, bootJsonBrPath))
{
return false;
}
}
}

Expand All @@ -95,7 +101,7 @@ public override bool Execute()
return true;
}

private void GZipCompress(string bootJsonPath, string bootJsonGzPath)
private bool GZipCompress(string bootJsonPath, string bootJsonGzPath)
{
try
{
Expand All @@ -107,11 +113,17 @@ private void GZipCompress(string bootJsonPath, string bootJsonGzPath)
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
if (File.Exists(bootJsonGzPath))
{
File.Delete(bootJsonGzPath);
}
Log.LogErrorFromException(ex, true, true, null);
return false;
}
return true;
}

private void BrotliCompress(string bootJsonPath, string bootJsonBrPath)
private bool BrotliCompress(string bootJsonPath, string bootJsonBrPath)
{
try
{
Expand All @@ -128,8 +140,14 @@ private void BrotliCompress(string bootJsonPath, string bootJsonBrPath)
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
if (File.Exists(bootJsonBrPath))
{
File.Delete(bootJsonBrPath);
}
Log.LogErrorFromException(ex, true, true, null);
return false;
}
return true;
}

string ComputeSha256Hash(string rawData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/stavroskasidis/BlazorWasmAntivirusProtection</PackageProjectUrl>
<Description>This package attempts to guard against false positives from antiviruses that flag Blazor Wasm as malware</Description>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>2.2.1</Version>
<Version>2.2.2</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
</PropertyGroup>

Expand Down

0 comments on commit bc08434

Please sign in to comment.