website/Dockerfile

75 lines
2.5 KiB
Docker

#syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
RUN apt-get update && apt-get install -y \
curl \
gnupg2 \
libatomic1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# install nodejs
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
ENV NODE_MAJOR=20
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install nodejs -y --no-install-recommends && rm -rf /var/lib/apt/lists/* && apt-get clean
# update npm and install pnpm
RUN npm install -g npm && npm install -g pnpm && npm cache clean --force
# install wasm-tools workload
RUN dotnet workload install wasm-tools
WORKDIR /app
# install dotnet tools
COPY --link .config/dotnet-tools.json .config/
RUN dotnet tool restore
# restore libman dependencies
COPY --link src/NSeguin.Dev.Web/libman.json ./src/NSeguin.Dev.Web/
RUN cd src/NSeguin.Dev.Web && dotnet libman restore
# copy and restore dotnet solution
COPY --link *.sln .
COPY --link global.json ./
COPY --link nuget.config ./
COPY --link targets/*.targets ./targets/
COPY --link targets/*.props ./targets/
COPY --link Directory.Build.props .
COPY --link Directory.Build.targets .
COPY --link Directory.Packages.props .
COPY --link src/NSeguin.Dev.Web/*.csproj ./src/NSeguin.Dev.Web/
COPY --link src/NSeguin.Dev.Web.Client/*.csproj ./src/NSeguin.Dev.Web.Client/
COPY --link src/NSeguin.Dev.Web.Common/*.csproj ./src/NSeguin.Dev.Web.Common/
COPY --link src/NSeguin.Dev.Web.HeroIcons.SourceGenerator/*.csproj ./src/NSeguin.Dev.Web.HeroIcons.SourceGenerator/
COPY --link src/NSeguin.Dev.Web/package.json ./src/NSeguin.Dev.Web/
COPY --link src/NSeguin.Dev.Web/pnpm-lock.yaml ./src/NSeguin.Dev.Web/
COPY --link src/NSeguin.Dev.Web/tailwind.config.ts ./src/NSeguin.Dev.Web/
RUN cd src/NSeguin.Dev.Web && pnpm install --frozen-lockfile
RUN dotnet restore --configfile nuget.config --locked-mode --force-evaluate
# copy everything else and build solution
COPY --link ./ .
ENV NODE_ENV=production
ENV CI=true
ENV SkipNodeBuild=true
RUN cd src/NSeguin.Dev.Web && pnpm run css:build
RUN dotnet publish -c Release -o publish /p:RestoreLockedMode=true src/NSeguin.Dev.Web/NSeguin.Dev.Web.csproj
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
# authenticate with Azure CLI
RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "NSeguin.Dev.Web.dll"]