######################
##  Build Frontend  ##
######################

FROM node:alpine AS build-frontend
WORKDIR /src

# Install the angular CLI
RUN npm install -g @angular/cli

# Copy the package.json into this build step
COPY  ./src/MistoxWebsite.Client/package.json ./

# Pull dependencies
RUN npm install

# Copy the rest of the frontend over
COPY ./src/MistoxWebsite.Client/ ./

# Compile the source
RUN ng build

#####################
##  Build Backend  ##
#####################

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-backend
WORKDIR /src

# Copy the csproj
COPY ./src/MistoxWebsite.Server/MistoxWebsite.Server.csproj ./

# Restore the Server
RUN dotnet restore './MistoxWebsite.Server.csproj'

# Copy the rest of the backend over
COPY ./src/MistoxWebsite.Server/ ./

# Build the source
RUN dotnet publish './MistoxWebsite.Server.csproj' -c Release -o /app/publish

################
##  Publish   ##
################

FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app

ENV ASPNETCORE_HTTP_PORTS=5000
ENV StripeKey=null
ENV MySQLServer=null
ENV MySQLUser=null
ENV MySQLPass=null
ENV MySQLDatabase=Mistox

EXPOSE 5000

# Copy in the server
COPY --from=build-backend /app/publish ./

# Copy in the client
COPY --from=build-frontend /debug/wwwroot ./wwwroot/

ENTRYPOINT ["dotnet", "MistoxWebsite.Server.dll", "--url", "http://localhost:5000"]