Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src/Turnierplan.App/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base

# Where are the files stored in the container? This folder should be mapped as a volume
ARG DATA_DIRECTORY=/var/turnierplan
RUN mkdir "$DATA_DIRECTORY" && chown "$APP_UID" "$DATA_DIRECTORY"
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release

# Copy the source files and build the solution.
WORKDIR /src
COPY . .
WORKDIR "/src/Turnierplan.App"
RUN dotnet build "./Turnierplan.App.csproj" -c "$BUILD_CONFIGURATION" -o /app/build
RUN dotnet build "./Turnierplan.App.csproj" -c Release -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release

# Install nodejs, this is required for the client app build which is part of the dotnet publish.
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && apt-get install -y nodejs

# By specifying the publish runtime 'linux-x64', no unnecessary native libraries are included in the image
RUN dotnet publish "./Turnierplan.App.csproj" -c "$BUILD_CONFIGURATION" --runtime linux-x64 -o /app/publish /p:UseAppHost=false
# Publish the solution. By specifying the publish runtime 'linux-x64', no unnecessary native libraries are included in the image
RUN dotnet publish "./Turnierplan.App.csproj" -c Release --runtime linux-x64 -o /app/publish /p:UseAppHost=false

FROM base AS final

# Since .NET 8, the official container image no longer includes the 'Kerberos' package. Since Npgsql 10.0, an
# error is shown upon startup if that package is not installed. Because of this, we install the package manually.
# The official documentation states you have to install the 'libkrb5-3' package:
# - https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/krb5-libs-package
# However, this seems to have no effect. By digging in the 'dotnet-docker' repository, you can find the Dockerfile
# used for the .NET 6 images which states the 'libgssapi-krb5-2' package which is installed below.
# - source: https://github.com/dotnet/dotnet-docker/blob/0a4258cc250885be5162d01f178bff5c856291f4/src/runtime-deps/6.0/jammy/amd64/Dockerfile
RUN apt-get update \
&& apt-get -y install libgssapi-krb5-2 \
&& rm -rf /var/lib/apt/lists/*

# Prepare the directory used by the turnierplan.NET application
RUN mkdir "$DATA_DIRECTORY" && chown "$APP_UID" "$DATA_DIRECTORY"

# Miscellaneous configurations
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# Copy the publish output i.e. the application binaries and the static web assets including the client application
COPY --from=publish /app/publish .

# Set the environment variables based on the data directory
ENV Identity__StoragePath=$DATA_DIRECTORY/identity
ENV ImageStorage__StoragePath=$DATA_DIRECTORY/images

# Entrypoint is the DLL of the Turnierplan.App project
ENTRYPOINT ["dotnet", "Turnierplan.App.dll"]
Loading