FROM mcr.microsoft.com/dotnet/sdk:9.0@sha256:3fcf6f1e809c0553f9feb222369f58749af314af6f063f389cbd2f913b4ad556 AS build
WORKDIR /App

RUN apt-get update && apt-get install -y --no-install-recommends g++ ninja-build
RUN wget -qO- "https://cmake.org/files/v3.31/cmake-3.31.0-linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

# Copy everything
COPY . ./

# Build HoshiServerNative
RUN cd Hoshi.Client && mkdir build && cd build && cmake -G Ninja -DBUILD_MOD=OFF -DBUILD_TESTER=OFF .. && cmake --build .

# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish Hoshi.GameServer -c "Release_1.08" -o out
# Copy HoshiServerNative
RUN cp Hoshi.Client/build/libHoshiServerNative.so out/libHoshiServerNative.so
# Copy config
RUN cp Hoshi.Common/config-* out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:9.0@sha256:b4bea3a52a0a77317fa93c5bbdb076623f81e3e2f201078d89914da71318b5d8
WORKDIR /App
COPY --from=build /App/Data Data
COPY --from=build /App/out .
ENTRYPOINT ["dotnet", "Hoshi.GameServer.dll"]
