Skip to content

Commit af81304

Browse files
deallocWannes Gennar
andauthored
.NET 10 (#153)
* chore: upgrade to .NET 10 * feat: add security headers * chore: update docker build * chore: set permissions for workflow * chore: update Dockerfile * chore: fix docker build #2 --------- Co-authored-by: Wannes Gennar <dealloc@Wannes-MacBookPro.local>
1 parent 3a3c00a commit af81304

13 files changed

Lines changed: 66 additions & 36 deletions

File tree

.github/workflows/dotnet.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
pull_request:
99
branches: [ "master" ]
1010

11+
permissions:
12+
contents: read
13+
actions: write
14+
1115
jobs:
1216
build:
1317

@@ -18,7 +22,7 @@ jobs:
1822
- name: Setup .NET
1923
uses: actions/setup-dotnet@v4
2024
with:
21-
dotnet-version: 9.0.x
25+
dotnet-version: 10.0.x
2226
- name: download JSON submodule
2327
run: git submodule update --init ./src/Helldivers-2-Models/json
2428
- name: Restore dependencies
@@ -36,3 +40,22 @@ jobs:
3640
retention-days: 5
3741
name: openapi-schemas
3842
path: docs/openapi/
43+
44+
docker-build:
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
with:
50+
submodules: true
51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
- name: Build Docker image
54+
uses: docker/build-push-action@v6
55+
with:
56+
context: .
57+
file: ./src/Helldivers-2-API/Dockerfile
58+
push: false
59+
tags: helldivers-api:test
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

.github/workflows/pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Setup .NET
3232
uses: actions/setup-dotnet@v4
3333
with:
34-
dotnet-version: 9.0.x
34+
dotnet-version: 10.0.x
3535
- name: Generate OpenAPI JSON files
3636
run: dotnet build -c Debug
3737
- name: Copy README

.github/workflows/sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup .NET
2424
uses: actions/setup-dotnet@v4
2525
with:
26-
dotnet-version: '9.0.x'
26+
dotnet-version: '10.0.x'
2727

2828
- name: Download JSON submodule
2929
run: git submodule update --init ./src/Helldivers-2-Models/json

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Nullable>enable</Nullable>
44
<ImplicitUsings>enable</ImplicitUsings>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
</PropertyGroup>
88

src/Helldivers-2-API/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine-extra AS base
1+
FROM mcr.microsoft.com/dotnet/runtime-deps:10.0-alpine-extra AS base
22
USER $APP_UID
33
WORKDIR /app
44

5-
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
6-
RUN apk add --upgrade --no-cache build-base clang zlib-dev
5+
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine-aot AS build
6+
RUN apk add --no-cache build-base clang lld llvm zlib-dev libstdc++
77
ARG BUILD_CONFIGURATION=Release
88
ARG BUILD_RUNTIME=linux-musl-x64
99
ARG OPENAPI=false
@@ -35,7 +35,9 @@ RUN dotnet build "Helldivers-2-API.csproj" --no-restore -r $BUILD_RUNTIME -c $BU
3535

3636
FROM build AS publish
3737
ARG BUILD_CONFIGURATION=Release
38-
RUN dotnet publish "Helldivers-2-API.csproj" /p:Version="$VERSION" --no-restore --self-contained -r $BUILD_RUNTIME -c $BUILD_CONFIGURATION -o /app/publish
38+
ARG BUILD_RUNTIME=linux-musl-x64
39+
ARG VERSION=0.0.0
40+
RUN dotnet publish "Helldivers-2-API.csproj" /p:Version="$VERSION" --self-contained -r $BUILD_RUNTIME -c $BUILD_CONFIGURATION -o /app/publish
3941

4042
FROM base AS final
4143
WORKDIR /app

src/Helldivers-2-API/Helldivers-2-API.csproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<PublishAot>true</PublishAot>
55
<RootNamespace>Helldivers.API</RootNamespace>
66
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
7-
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
87
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
8+
<PublishReadyToRun>true</PublishReadyToRun>
99
</PropertyGroup>
1010

1111
<!-- Only generate OpenAPI docs for DEBUG builds -->
@@ -23,8 +23,9 @@
2323

2424
<!-- Dependencies for all build configurations -->
2525
<ItemGroup>
26-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
27-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
26+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.0" />
28+
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="1.2.0" />
2829
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
2930
<ProjectReference Include="..\Helldivers-2-Models\Helldivers-2-Models.csproj" />
3031
<ProjectReference Include="..\Helldivers-2-Core\Helldivers-2-Core.csproj" />
@@ -36,12 +37,12 @@
3637

3738
<!-- Only include swagger dependencies in DEBUG builds -->
3839
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
39-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.6" />
40-
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.6">
40+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.0">
4142
<PrivateAssets>all</PrivateAssets>
4243
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4344
</PackageReference>
44-
<PackageReference Include="NSwag.AspNetCore" Version="14.4.0" />
45+
<PackageReference Include="NSwag.AspNetCore" Version="14.6.2" />
4546
</ItemGroup>
4647

4748
</Project>

src/Helldivers-2-API/OpenApi/TypeMappers/EnumStringTypeMapper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NJsonSchema;
1+
#if DEBUG
2+
using NJsonSchema;
23
using NJsonSchema.Generation.TypeMappers;
34
using System.Collections.ObjectModel;
45

@@ -34,3 +35,4 @@ public void GenerateSchema(JsonSchema schema, TypeMapperContext context)
3435
schema.ExtensionData ??= new Dictionary<string, object>()!;
3536
}
3637
}
38+
#endif

src/Helldivers-2-API/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
options.ForwardLimit = 999;
9292
options.OriginalForHeaderName = "Fly-Client-IP";
9393
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor;
94-
options.KnownNetworks.Add(new IPNetwork(IPAddress.Any, 0));
95-
options.KnownNetworks.Add(new IPNetwork(IPAddress.IPv6Any, 0));
94+
options.KnownIPNetworks.Add(new System.Net.IPNetwork(IPAddress.Any, 0));
95+
options.KnownIPNetworks.Add(new System.Net.IPNetwork(IPAddress.IPv6Any, 0));
9696
});
9797

9898
// This configuration is bound here so that source generators kick in.
@@ -219,6 +219,9 @@
219219
// Ensure web applications can access the API by setting CORS headers.
220220
app.UseCors();
221221

222+
// Add various security-related headers.
223+
app.UseSecurityHeaders();
224+
222225
// Make sure ASP.NET Core uses the correct addresses internally rather than Fly's proxy
223226
app.UseForwardedHeaders();
224227

src/Helldivers-2-CI/Helldivers-2-CI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<RootNamespace>Helldivers_2_CI</RootNamespace>
77
<GenerateDocumentationFile>false</GenerateDocumentationFile>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
1212
<ProjectReference Include="..\Helldivers-2-Sync\Helldivers-2-Sync.csproj" />
1313
</ItemGroup>
1414

src/Helldivers-2-Core/Helldivers-2-Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0"/>
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0"/>
1010
<ProjectReference Include="..\Helldivers-2-Models\Helldivers-2-Models.csproj"/>
1111
</ItemGroup>
1212

0 commit comments

Comments
 (0)