Add support for running as docker container
This commit is contained in:
parent
967c16b6bf
commit
b32ac7ba6f
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY . ./
|
||||||
|
WORKDIR Groceries
|
||||||
|
RUN dotnet restore
|
||||||
|
RUN dotnet publish --no-restore --output /out
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
|
||||||
|
WORKDIR /groceries
|
||||||
|
COPY --from=build /out .
|
||||||
|
COPY --from=build /src/Groceries/config.ini /config/
|
||||||
|
VOLUME /config
|
||||||
|
ENV DOTNET_ENABLEDIAGNOSTICS=0
|
||||||
|
ENTRYPOINT ["./Groceries", "--data", "/config"]
|
@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
.gitignore = .gitignore
|
.gitignore = .gitignore
|
||||||
|
Dockerfile = Dockerfile
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<WarningsAsErrors>nullable</WarningsAsErrors>
|
<WarningsAsErrors>nullable</WarningsAsErrors>
|
||||||
<AnalysisMode>recommended</AnalysisMode>
|
<AnalysisMode>recommended</AnalysisMode>
|
||||||
|
|
||||||
|
<PublishRelease>true</PublishRelease>
|
||||||
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -18,8 +21,4 @@
|
|||||||
<ProjectReference Include="..\Groceries.Data\Groceries.Data.csproj" />
|
<ProjectReference Include="..\Groceries.Data\Groceries.Data.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="config.ini" CopyToOutputDirectory="PreserveNewest" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
using Groceries.Common;
|
using Groceries.Common;
|
||||||
using Groceries.Data;
|
using Groceries.Data;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
using Microsoft.AspNetCore.Mvc.Razor;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
var env = builder.Environment;
|
||||||
|
|
||||||
|
var dataDir = builder.Configuration.GetValue<string>("data") ?? env.ContentRootPath;
|
||||||
|
|
||||||
builder.Configuration
|
builder.Configuration
|
||||||
.AddIniFile("config.ini", optional: true, reloadOnChange: true)
|
.AddIniFile(Path.Combine(dataDir, "config.ini"), optional: true, reloadOnChange: true)
|
||||||
.AddIniFile($"config_{builder.Environment.EnvironmentName}.ini", optional: true, reloadOnChange: true);
|
.AddIniFile(Path.Combine(dataDir, $"config_{env.EnvironmentName}.ini"), optional: true, reloadOnChange: true);
|
||||||
|
|
||||||
|
var dataProtection = builder.Services.AddDataProtection();
|
||||||
|
if (env.IsProduction())
|
||||||
|
{
|
||||||
|
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(dataDir, "keys")));
|
||||||
|
}
|
||||||
|
|
||||||
var mvc = builder.Services
|
var mvc = builder.Services
|
||||||
.AddControllersWithViews()
|
.AddControllersWithViews()
|
||||||
@ -20,7 +30,7 @@ var mvc = builder.Services
|
|||||||
})
|
})
|
||||||
.AddSessionStateTempDataProvider();
|
.AddSessionStateTempDataProvider();
|
||||||
|
|
||||||
if (builder.Environment.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
mvc.AddRazorRuntimeCompilation();
|
mvc.AddRazorRuntimeCompilation();
|
||||||
}
|
}
|
||||||
@ -31,8 +41,8 @@ builder.Services.AddSession();
|
|||||||
builder.Services.AddSingleton<IActionResultExecutor<TurboStreamResult>, TurboStreamResultExecutor>();
|
builder.Services.AddSingleton<IActionResultExecutor<TurboStreamResult>, TurboStreamResultExecutor>();
|
||||||
|
|
||||||
builder.Services.AddDbContextPool<AppDbContext>(options => options
|
builder.Services.AddDbContextPool<AppDbContext>(options => options
|
||||||
.EnableDetailedErrors(builder.Environment.IsDevelopment())
|
.EnableDetailedErrors(env.IsDevelopment())
|
||||||
.EnableSensitiveDataLogging(builder.Environment.IsDevelopment())
|
.EnableSensitiveDataLogging(env.IsDevelopment())
|
||||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||||
.UseSnakeCaseNamingConvention()
|
.UseSnakeCaseNamingConvention()
|
||||||
.UseNpgsql(builder.Configuration["Database"]!));
|
.UseNpgsql(builder.Configuration["Database"]!));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user