Skip to content

Commit

Permalink
Configure WebApp dist reference in WebApp middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tjementum authored and raix committed Nov 16, 2023
1 parent 2a54c49 commit 8b595b6
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 94 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,33 @@ jobs:

- name: Install Node modules
working-directory: application/account-management/WebApp
run: bun install
run: bun install --frozen-lockfile

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x

- name: Restore .NET tools
working-directory: application
run: dotnet tool restore

- name: Restore Node modules
working-directory: application/account-management/WebApp
run: bun install --frozen-lockfile

- name: Restore .NET dependencies
run: dotnet restore application/PlatformPlatform.sln

- name: Build
run: dotnet build application/PlatformPlatform.sln --no-restore --configuration Release /p:Version=${{ steps.generate_version.outputs.version }}

- name: Publish Account Management API build
working-directory: application/account-management/Api
run: |
dotnet publish Api.csproj --no-restore --configuration Release --output ./publish --version-suffix ${{ steps.generate_version.outputs.version }}
echo "{name}=${{ steps.generate_version.outputs.version }}" >> $GITHUB_OUTPUT
test-with-code-coverage:
name: Test and Code Coverage
needs: build
Expand All @@ -65,6 +79,14 @@ jobs:
- name: Install Bun
uses: oven-sh/setup-bun@v1

- name: Restore .NET tools
working-directory: application
run: dotnet tool restore

- name: Restore Node modules
working-directory: application/account-management/WebApp
run: bun install --frozen-lockfile

- name: Install dotCover
run: dotnet tool install --global JetBrains.dotCover.GlobalTool

Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ bld/
[Oo]bj/
[Ll]og/
[Ll]ogs/
dist/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down Expand Up @@ -380,4 +379,7 @@ FodyWeavers.xsd
.DS_Store

# Generated files
**/*.generated.d.ts
**/*.generated.d.ts

# Frontend builds
dist/
2 changes: 1 addition & 1 deletion application/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,7 @@ indent_style = space
indent_size = 4
tab_width = 4

[*.{ts,tsx,js,jsx,json,.prettierrc,.eslintrc}]
[*.{ts,tsx,js,jsx,json,.prettierrc,.eslintrc,yml,Dockerfile}]
indent_style = space
indent_size = 2
tab_width = 2
Expand Down
20 changes: 4 additions & 16 deletions application/account-management/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,18 @@
<Content Update="appsettings.development.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
<Content Remove="dist\**"/>
</ItemGroup>

<ItemGroup>
<Compile Remove="dist\**"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Remove="dist\**"/>
</ItemGroup>

<ItemGroup>
<None Remove="dist\**"/>
</ItemGroup>

<Target Name="InstallDependencies" BeforeTargets="Build" Condition="$(Configuration)=='Debug'">
<!-- <Target Name="InstallDependencies" BeforeTargets="Build" Condition="$(Configuration)=='Debug'">
<Exec Command="dotnet tool restore"/>
<Exec Command="bun install" WorkingDirectory="$(ProjectDir)/../WebApp/"/>
</Target>
</Target> -->

<Target Name="CreateSwaggerJson" AfterTargets="Build" Condition="$(Configuration)=='Debug'">
<Target Name="CreateSwaggerJson" AfterTargets="Build">
<Exec Command="SWAGGER_GENERATOR=true dotnet swagger tofile --output $(OutputPath)swagger.json $(OutputPath)$(AssemblyName).dll v1" WorkingDirectory="$(ProjectDir)"/>
<Exec Command="bunx openapi-typescript@latest $(OutputPath)swagger.json -o ../WebApp/src/lib/api/api.generated.d.ts" WorkingDirectory="$(ProjectDir)"/>
<Exec Command="bunx prettier ../WebApp/src/lib/api/api.generated.d.ts --write" WorkingDirectory="$(ProjectDir)"/>
<Exec Command="bun run build" WorkingDirectory="$(ProjectDir)/../WebApp/"/>
</Target>

</Project>
21 changes: 19 additions & 2 deletions application/account-management/Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
ARG VERSION=1.0.0.0 # Use version 1.0.0.0 as default
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
# Use version 1.0.0.0 as default
ARG VERSION=1.0.0.0

SHELL ["/bin/bash", "-l", "-c"]
RUN apt-get update
RUN apt-get --no-install-recommends install zip unzip

RUN curl -fsSL https://bun.sh/install | bash

WORKDIR /src

# Copy all source code to /src
COPY ./ ./

# Set the working directory to the WebApp project
WORKDIR /src/account-management/WebApp
RUN bun install --freeze-lockfile

# Set the working directory to the API project
WORKDIR /src/account-management/Api
RUN dotnet tool restore
RUN dotnet restore
RUN dotnet publish -c Release -o /publish /p:Version="$VERSION"


# Runtime stage (start with a clean image and copy only published binairies)
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS runtime

WORKDIR /app/WebApp/dist
COPY --from=build /src/account-management/WebApp/dist ./

WORKDIR /app
COPY --from=build /publish ./

Expand Down
2 changes: 1 addition & 1 deletion application/account-management/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Add common configuration for all APIs like Swagger, HSTS, DeveloperExceptionPage, and run EF database migrations.
app.AddApiCoreConfiguration<AccountManagementDbContext>();
app.UseWebAppMiddleware();
app.UseWebAppMiddleware("WebApp");

app.MapTenantEndpoints();
app.MapUserEndpoints();
Expand Down
4 changes: 4 additions & 0 deletions application/account-management/Tests/Api/BaseApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.TestHost;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using PlatformPlatform.SharedKernel.ApiCore.Middleware;
using PlatformPlatform.SharedKernel.ApplicationCore.Validation;

namespace PlatformPlatform.AccountManagement.Tests.Api;
Expand All @@ -17,6 +18,9 @@ public abstract partial class BaseApiTests<TContext> : BaseTest<TContext> where

protected BaseApiTests()
{
Environment.SetEnvironmentVariable(WebAppMiddleware.PublicUrlKey, "https://localhost");
Environment.SetEnvironmentVariable(WebAppMiddleware.CdnUrlKey, "https://localhost");

_webApplicationFactory = new WebApplicationFactory<Program>().WithWebHostBuilder(builder =>
{
builder.ConfigureTestServices(services =>
Expand Down
2 changes: 1 addition & 1 deletion application/account-management/WebApp/rspack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import HtmlWebpackHarddiskPlugin from "html-webpack-harddisk-plugin";

const buildEnv: BuildEnv = {};

const outputPath = resolve(__dirname, "..", "Api", "dist");
const outputPath = resolve(__dirname, "dist");

const configuration: Configuration = {
context: __dirname,
Expand Down
4 changes: 3 additions & 1 deletion application/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"

services:
sql-server:
Expand Down Expand Up @@ -29,6 +29,8 @@ services:
ASPNETCORE_Kestrel__Certificates__Default__Path: "/https/localhost.pfx"
ASPNETCORE_Kestrel__Certificates__Default__Password: $CERTIFICATE_PASSWORD
ASPNETCORE_URLS: "https://+"
PUBLIC_URL: "https://localhost:8443"
CDN_URL: "https://localhost:8443"
volumes:
- ${HOME}/.aspnet/https:/https

Expand Down
10 changes: 3 additions & 7 deletions application/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2023.2.3",
"commands": [
"jb"
]
"commands": ["jb"]
},
"swashbuckle.aspnetcore.cli": {
"version": "6.5.0",
"commands": [
"swagger"
]
"commands": ["swagger"]
}
}
}
}
Loading

0 comments on commit 8b595b6

Please sign in to comment.