From 7d442169760bb1c415f890d6a6c546a78d205dc2 Mon Sep 17 00:00:00 2001 From: Yaser Moradi Date: Mon, 15 Jan 2024 23:37:35 +0100 Subject: [PATCH] Initial static blazor webassembly deployment --- .github/workflows/todo-sample.cd.yml | 31 +++++ .../Components/AppBswupProgressBar.razor | 2 +- .../Boilerplate/Bit.Boilerplate/.gitignore | 3 +- .../src/Boilerplate.Server/Program.cs | 2 +- .../Boilerplate.Server/Startup/Middlewares.cs | 2 +- .../Boilerplate.Client.Web.csproj | 19 ++- .../Components/AppBswupProgressBar.razor | 2 +- .../Client/Boilerplate.Client.Web/Program.cs | 11 +- .../Properties/launchSettings.json | 15 +++ .../Boilerplate.Client.Web/wwwroot/index.html | 110 ++++++++++++++++++ .../wwwroot/service-worker.js | 45 ++++++- .../Bit.Boilerplate/src/Directory.Build.props | 9 +- 12 files changed, 234 insertions(+), 17 deletions(-) create mode 100644 src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Properties/launchSettings.json create mode 100644 src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html diff --git a/.github/workflows/todo-sample.cd.yml b/.github/workflows/todo-sample.cd.yml index 9e15eb5796..a93f25b839 100644 --- a/.github/workflows/todo-sample.cd.yml +++ b/.github/workflows/todo-sample.cd.yml @@ -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 @@ -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 @@ -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: diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Web/Components/AppBswupProgressBar.razor b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Web/Components/AppBswupProgressBar.razor index b494b59b7b..1b46bed028 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Web/Components/AppBswupProgressBar.razor +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Web/Components/AppBswupProgressBar.razor @@ -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; diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/.gitignore b/src/Templates/Boilerplate/Bit.Boilerplate/.gitignore index 9a3e897c1d..5b1a736062 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/.gitignore +++ b/src/Templates/Boilerplate/Bit.Boilerplate/.gitignore @@ -231,4 +231,5 @@ custom.aprof /src/Client/Boilerplate.Client.Core/wwwroot/scripts/app*.js -/src/Boilerplate.Server/*.db* \ No newline at end of file +/src/Boilerplate.Server/*.db* +.env \ No newline at end of file diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Program.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Program.cs index 4a370a7e8a..6b98bd92f1 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Program.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Program.cs @@ -15,4 +15,4 @@ Boilerplate.Server.Startup.Middlewares.Use(app, builder.Environment, builder.Configuration); -app.Run(); +await app.RunAsync(); diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Startup/Middlewares.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Startup/Middlewares.cs index 04ff3382fe..23b5520804 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Startup/Middlewares.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Boilerplate.Server/Startup/Middlewares.cs @@ -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(); diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Boilerplate.Client.Web.csproj b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Boilerplate.Client.Web.csproj index 0e8df5e5ce..874f89faa2 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Boilerplate.Client.Web.csproj +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Boilerplate.Client.Web.csproj @@ -1,11 +1,10 @@  - + net8.0 true false - true true @@ -17,10 +16,21 @@ Default true + - + + + + + + + + + + + @@ -39,6 +49,7 @@ + @@ -49,5 +60,5 @@ - + diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Components/AppBswupProgressBar.razor b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Components/AppBswupProgressBar.razor index e3e2aafd8d..f66ab0e6e3 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Components/AppBswupProgressBar.razor +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Components/AppBswupProgressBar.razor @@ -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; diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs index 7f8876f3bb..179f644020 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Program.cs @@ -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("#app-container"); +builder.RootComponents.Add("head::after"); +#endif + builder.Configuration.AddClientConfigurations(); Uri.TryCreate(builder.Configuration.GetApiServerAddress(), UriKind.RelativeOrAbsolute, out var apiServerAddress); diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Properties/launchSettings.json b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Properties/launchSettings.json new file mode 100644 index 0000000000..8ce767d1ea --- /dev/null +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/Properties/launchSettings.json @@ -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" +} \ No newline at end of file diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html new file mode 100644 index 0000000000..840b23ab98 --- /dev/null +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/index.html @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + +
+
+
+ + + + + + + + + + + diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/service-worker.js b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/service-worker.js index 0c4fa6ba58..264b97e079 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/service-worker.js +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Web/wwwroot/service-worker.js @@ -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', () => { }); \ No newline at end of file +// 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'); \ No newline at end of file diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Build.props b/src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Build.props index e10a70dee3..427c969d88 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Build.props +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Build.props @@ -11,10 +11,10 @@ en-US true - $(DefineConstants);MultilingualEnabled - false - $(DefineConstants);PwaEnabled + true + + true 14.0 14.0 @@ -26,6 +26,9 @@ $(DefineConstants);iOS $(DefineConstants);Windows $(DefineConstants);Mac + $(DefineConstants);MultilingualEnabled + $(DefineConstants);BlazorWebAssemblyStatic + $(DefineConstants);PwaEnabled