# Elsa Custom Server — Docker image
# Multi-stage build so the final image only carries the ASP.NET runtime.

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /source

# Restore first for better layer caching.
COPY src/Elsa.CustomServer/Elsa.CustomServer.csproj src/Elsa.CustomServer/
COPY src/Elsa.Studio.Wasm/Elsa.Studio.Wasm.csproj src/Elsa.Studio.Wasm/
RUN dotnet restore src/Elsa.CustomServer/Elsa.CustomServer.csproj

# Then copy the rest and publish.
COPY src/ src/
RUN dotnet publish src/Elsa.CustomServer/Elsa.CustomServer.csproj \
    -c Release -o /app/publish --no-restore /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish ./

# Ensure the SQLite DB and any workflow blobs land on a writable path we can volume-mount.
RUN mkdir -p /app/App_Data && chmod 777 /app/App_Data
VOLUME ["/app/App_Data"]

# Kestrel binds to whatever HTTP_PORTS says; keep the container port fixed so Coolify
# can wire Traefik consistently.
ENV ASPNETCORE_URLS=http://+:8080
ENV HTTP_PORTS=8080

EXPOSE 8080
ENTRYPOINT ["dotnet", "Elsa.CustomServer.dll"]
