Skip to content

Commit

Permalink
Initial static blazor webassembly deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Jan 15, 2024
1 parent 1fcb3a0 commit 7d44216
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 17 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/todo-sample.cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- name: Enable pre rendering
run: sed -i 's/public static readonly bool PrerenderEnabled = false;/public static readonly bool PrerenderEnabled = true;/g' TodoSample/src/Client/TodoSample.Client.Core/Services/AppRenderMode.cs

- name: Changes for static-todo.bitplatform.dev - Part 1
run: sed -i 's/http://localhost:4030/https://static-todo.bitplatform.dev/g' TodoSample/src/TodoSample.Server/Startup/Middlewares.cs

- name: Generate CSS/JS files
run: dotnet build TodoSample/src/Client/TodoSample.Client.Core/TodoSample.Client.Core.csproj -t:BeforeBuildTasks --no-restore

Expand All @@ -65,6 +68,18 @@ jobs:
name: server-bundle
path: ${{env.DOTNET_ROOT}}/server

- name: Changes for static-todo.bitplatform.dev - Part 2
run: sed -i 's/public static readonly bool PrerenderEnabled = true;/public static readonly bool PrerenderEnabled = false;/g' TodoSample/src/Client/TodoSample.Client.Core/Services/AppRenderMode.cs

- name: Publish static todo
run: dotnet publish TodoSample/src/Client/TodoSample.Client.Web/TodoSample.Client.Web.csproj -c Release -p:BlazorWebAssemblyStatic=true -o ${{env.DOTNET_ROOT}}/static

- name: Upload static artifact
uses: actions/upload-artifact@v3
with:
name: static-bundle
path: ${{env.DOTNET_ROOT}}/static

deploy_api_blazor:
name: deploy api + blazor
needs: build_api_blazor
Expand Down Expand Up @@ -100,6 +115,22 @@ jobs:
publish-profile: ${{ secrets.TODO_AZURE_APP_SERVICE_PUBLISH_PROFILE }}
package: .

- name: Retrieve static bundle
uses: actions/download-artifact@v2
with:
name: server-static
path: ./static

- name: Deploy to Azure Static pages
id: deploy-to-static-pages
uses: Azure/static-web-apps-deploy@v1
with:
app-name: 'todo'
slot-name: 'production'
azure_static_web_apps_api_token: ${{ secrets.TODO_STATIC_AZURE_STATIC_PAGES_TOKEN }}
package: ./static
action: "upload"

- name: Purge cache
uses: jakejarvis/cloudflare-purge-action@master
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
content: var(--bit-bswup-percent-text, "");
}
/* If you want the update to be applied after the user approves the new Pwa version and not automatically,
set AutoReload parameter of BswupProgress to true and uncomment the commented codes in this file: */
set AutoReload parameter of BswupProgress to false and uncomment the commented codes in this file: */
/*
#bit-bswup-reload {
top: 38px;
Expand Down
3 changes: 2 additions & 1 deletion src/Templates/Boilerplate/Bit.Boilerplate/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,5 @@ custom.aprof

/src/Client/Boilerplate.Client.Core/wwwroot/scripts/app*.js

/src/Boilerplate.Server/*.db*
/src/Boilerplate.Server/*.db*
.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

Boilerplate.Server.Startup.Middlewares.Use(app, builder.Environment, builder.Configuration);

app.Run();
await app.RunAsync();
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void Use(WebApplication app, IHostEnvironment env, IConfiguration
}
});

app.UseCors(options => options.WithOrigins("https://0.0.0.0" /*BlazorHybrid*/, "app://0.0.0.0" /*BlazorHybrid*/)
app.UseCors(options => options.WithOrigins("https://0.0.0.0" /*BlazorHybrid*/, "app://0.0.0.0" /*BlazorHybrid*/, "http://localhost:4030" /*BlazorWebAssemblyStatic*/)
.AllowAnyHeader().AllowAnyMethod());

app.UseAuthentication();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<!--If you don't need to use the time zone and your app is in WASM format, you can reduce the output size of the app by disabling the time zone.-->
<BlazorEnableTimeZoneSupport>true</BlazorEnableTimeZoneSupport>
<BlazorWebAssemblyPreserveCollationData>false</BlazorWebAssemblyPreserveCollationData>
<!--/-:msbuild-conditional:noEmit -->
<!-- To change MultilingualEnabled's value, checkout Directory.Build.props -->
<InvariantGlobalization Condition="'$(MultilingualEnabled)' == 'false'">true</InvariantGlobalization>
<HybridGlobalization Condition="'$(MultilingualEnabled)' == 'true'">true</HybridGlobalization>
Expand All @@ -17,10 +16,21 @@
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<!--/+:msbuild-conditional:noEmit -->
<WasmStripILAfterAOT Condition=" '$(offlineDb)' == 'false'">true</WasmStripILAfterAOT>
<!--/-:msbuild-conditional:noEmit -->
</PropertyGroup>

<ItemGroup Condition=" '$(PwaEnabled)' == 'true' ">
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.js" />
</ItemGroup>

<ItemGroup Condition=" '$(BlazorWebAssemblyStatic)' == 'true' ">
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(BlazorWebAssemblyStatic)' == 'false' ">
<Content Remove="wwwroot\index.html" />
<None Remove="Properties\launchSettings.json" />
</ItemGroup>

<ItemGroup>
Expand All @@ -39,6 +49,7 @@
<ProjectReference Include="..\Boilerplate.Client.Core\Boilerplate.Client.Core.csproj" />

<Using Include="Microsoft.JSInterop" />
<Using Include="Boilerplate.Client.Core" />
<Using Include="Boilerplate.Client.Core.Services.Contracts" />
<Using Include="Boilerplate.Client.Core.Services" />
<Using Include="Boilerplate.Client.Core.Components.Layout" />
Expand All @@ -49,5 +60,5 @@
<BlazorWebAssemblyLazyLoad Include="Newtonsoft.Json.wasm" />
</ItemGroup>
<!--/-:msbuild-conditional:noEmit -->

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
content: var(--bit-bswup-percent-text, "");
}
/* If you want the update to be applied after the user approves the new Pwa version and not automatically,
set AutoReload parameter of BswupProgress to true and uncomment the commented codes in this file: */
set AutoReload parameter of BswupProgress to false and uncomment the commented codes in this file: */
/*
#bit-bswup-reload {
top: 38px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
//-:cnd:noEmit
#if BlazorWebAssemblyStatic
using Microsoft.AspNetCore.Components.Web;
#endif
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

#if BlazorWebAssemblyStatic
builder.RootComponents.Add<Routes>("#app-container");
builder.RootComponents.Add<HeadOutlet>("head::after");
#endif

builder.Configuration.AddClientConfigurations();

Uri.TryCreate(builder.Configuration.GetApiServerAddress(), UriKind.RelativeOrAbsolute, out var apiServerAddress);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"profiles": {
"Boilerplate.Web(BlazorWebAssembly)": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:4030",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
},
"$schema": "http://json.schemastore.org/launchsettings.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html bit-theme="dark">
<head>
<base href="/">
<meta charset="utf-8">
<meta name="theme-color">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="The Boilerplate is built with ASP.NET Core, Identity, Web API, EF Core and Blazor.">
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="images/icons/bit-icon-512.png" rel="apple-touch-icon" sizes="512x512" />
<link href="manifest.json" rel="manifest" />
</head>
<body class="bit-css-clr-bg-primary bit-css-clr-fg-primary bit-blazor-web">
<link href="_content/Bit.BlazorUI/styles/bit.blazorui.css" rel="stylesheet" />
<link href="_content/Bit.BlazorUI.Icons/styles/bit.blazorui.icons.css" rel="stylesheet" />
<link href="_content/Bit.BlazorUI.Assets/styles/bit.blazorui.assets.css" rel="stylesheet" />
<!--#if (sample == "Admin") -->
<link href="_content/Bit.BlazorUI.Extras/styles/bit.blazorui.extras.css" rel="stylesheet" />
<!--#endif -->
<link href="_content/Boilerplate.Client.Core/styles/app.css" rel="stylesheet" />
<link href="_content/Boilerplate.Client.Core/Boilerplate.Client.Core.bundle.scp.css" rel="stylesheet" />
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script src="_content/Bit.Bswup/bit-bswup.js" blazorScript="_framework/blazor.webassembly.js"></script>
<script src="_content/Bit.Bswup/bit-bswup.progress.js"></script>
<style>
#bit-bswup {
top: 2px;
left: 50%;
display: none;
position: fixed;
z-index: 999999999;
text-align: center;
transform: translateX(-50%);
font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
}

#bit-bswup .bswup-container {
width: 3rem;
height: 3rem;
display: block;
position: relative;
}

#bit-bswup .bswup-container circle {
fill: none;
stroke: #e0e0e0;
stroke-width: 0.2rem;
transform-origin: 50% 50%;
transform: rotate(-90deg);
}

#bit-bswup .bswup-container circle:last-child {
stroke: #1b6ec2;
transition: stroke-dasharray 0.05s ease-in-out;
stroke-dasharray: calc(3.141 * var(--bit-bswup-percent, 0%) * 0.8), 500%;
}

#bit-bswup .bswup-progress-text {
top: 50%;
left: 50%;
font-size: 12px;
position: absolute;
text-align: center;
font-weight: normal;
transform: translate(-50%, -50%);
}

#bit-bswup .bswup-progress-text::after {
content: var(--bit-bswup-percent-text, "");
}

/* If you want the update to be applied after the user approves the new Pwa version and not automatically,
set first parameter of startBswupProgress (AutoReload) to false and uncomment the following code: */
/*
#bit-bswup-reload {
top: 38px;
left: 50%;
display: none;
cursor: pointer;
position: fixed;
padding: 4px 8px;
z-index: 999999999;
border-radius: 2px;
transform: translateX(-50%);
}
*/
</style>
<div>
<div id="app-container">
<div id="bit-bswup">
<div class="bswup-progress-text"></div>
<svg class="bswup-container">
<circle r="40%" cx="50%" cy="50%"></circle>
<circle r="40%" cx="50%" cy="50%"></circle>
</svg>
<img style="display: none" src onerror="startBswupProgress(true, false, false, '#app-container', false, '')" />
</div>
</div>
</div>
<script src="_content/Bit.Butil/bit-butil.js"></script>
<!--#if (offlineDb == true) -->
<script src="_content/Bit.Besql/bit-besql.js"></script>
<!--#endif -->
<script src="_content/Bit.BlazorUI/scripts/bit.blazorui.js"></script>
<script src="_content/Boilerplate.Client.Core/scripts/app.js"></script>
<!--#if (sample == "Admin") -->
<script src="_content/Bit.BlazorUI.Extras/scripts/bit.blazorui.extras.js"></script>
<!--#endif -->
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
// In development, always fetch from the network and do not enable offline support.
// This is because caching would make development more difficult (changes would not
// be reflected on the first load after each change).
self.addEventListener('fetch', () => { });
// bit version: 8.7.2-pre-01
// https://github.com/bitfoundation/bitplatform/tree/develop/src/Bswup

self.assetsInclude = [];
self.assetsExclude = [
/bit\.blazorui\.fluent\.css$/,
/bit\.blazorui\.fluent-dark\.css$/,
/bit\.blazorui\.fluent-light\.css$/,
/Client\.Web\.styles\.css$/ // In .NET 8, an inexistent CSS file is inadvertently included in the assets list under the name 'Boilerplate.Client.Web.styles.css.'
// Subsequently, during the download process of assets list files, bswup attempts to retrieve this non - existent CSS file along with others.
// It is imperative that we expunge this file from the assets list.
];
self.externalAssets = [
{
"url": "/"
},
{
"url": "_framework\/blazor.web.js"
},
{
"url": "_framework\/blazor.webassembly.js"
}
];

self.serverHandledUrls = [
/\/api\//,
/\/odata\//,
/\/jobs\//,
/\/core\//,
/\/signalr\//,
/\/healthchecks-ui/,
/\/healthz/,
/\/swagger/
];

self.defaultUrl = "/";
self.caseInsensitiveUrl = true;
self.noPrerenderQuery = 'no-prerender=true';
self.isPassive = self.disablePassiveFirstBoot = true;

self.importScripts('_content/Bit.Bswup/bit-bswup.sw.js');
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

<NeutralLanguage>en-US</NeutralLanguage>
<MultilingualEnabled>true</MultilingualEnabled>
<DefineConstants Condition=" '$(MultilingualEnabled)' == 'true' ">$(DefineConstants);MultilingualEnabled</DefineConstants>

<PwaEnabled>false</PwaEnabled>
<DefineConstants Condition=" '$(PwaEnabled)' == 'true' ">$(DefineConstants);PwaEnabled</DefineConstants>
<BlazorWebAssemblyStatic>true</BlazorWebAssemblyStatic>

<PwaEnabled Condition=" '$(BlazorWebAssemblyStatic)' == 'true' ">true</PwaEnabled>

<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-ios'))">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-mac'))">14.0</SupportedOSPlatformVersion>
Expand All @@ -26,6 +26,9 @@
<DefineConstants Condition=" $(TargetFramework.Contains('-ios')) ">$(DefineConstants);iOS</DefineConstants>
<DefineConstants Condition=" $(TargetFramework.Contains('-windows')) ">$(DefineConstants);Windows</DefineConstants>
<DefineConstants Condition=" $(TargetFramework.Contains('-mac')) ">$(DefineConstants);Mac</DefineConstants>
<DefineConstants Condition=" '$(MultilingualEnabled)' == 'true' ">$(DefineConstants);MultilingualEnabled</DefineConstants>
<DefineConstants Condition=" '$(BlazorWebAssemblyStatic)' == 'true' ">$(DefineConstants);BlazorWebAssemblyStatic</DefineConstants>
<DefineConstants Condition=" '$(PwaEnabled)' == 'true' ">$(DefineConstants);PwaEnabled</DefineConstants>
</PropertyGroup>
<!--/+:msbuild-conditional:noEmit -->

Expand Down

0 comments on commit 7d44216

Please sign in to comment.