From c79f03f6894490dc3abdec2429cf4f3bc480d869 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 1 Apr 2024 01:38:01 +0200 Subject: [PATCH] [docker] Update Dockerfile --- Dockerfile | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 145a0133..71aeb5f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,21 @@ -FROM --platform=$BUILDPLATFORM alpine:3.18 AS frontend -WORKDIR /frontend - -RUN apk add --no-cache --no-progress nodejs-current npm - -# copy frontend package.json and yarn.lock -COPY Iceshrimp.Frontend/package.json Iceshrimp.Frontend/yarn.lock . - -# Configure corepack and install dev mode dependencies for compilation -RUN corepack enable && corepack prepare --activate && yarn --immutable - -# copy and build frontend -COPY Iceshrimp.Frontend/. . -RUN yarn --immutable && yarn build -#TODO: why is a second yarn pass required here? - -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS backend +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS builder ARG TARGETARCH WORKDIR /src -# copy csproj and restore as distinct layers -RUN mkdir Iceshrimp.Backend Iceshrimp.Parsing +# copy csproj/fsproj and restore as distinct layers +RUN mkdir Iceshrimp.Backend Iceshrimp.Parsing Iceshrimp.Frontend COPY Iceshrimp.Backend/*.csproj /src/Iceshrimp.Backend COPY Iceshrimp.Parsing/*.fsproj /src/Iceshrimp.Parsing +COPY Iceshrimp.Frontend/*.csproj /src/Iceshrimp.Frontend WORKDIR /src/Iceshrimp.Backend RUN dotnet restore -a $TARGETARCH -# copy backend files +# copy build files COPY Iceshrimp.Backend/. /src/Iceshrimp.Backend COPY Iceshrimp.Parsing/. /src/Iceshrimp.Parsing +COPY Iceshrimp.Frontend/. /src/Iceshrimp.Frontend -# it's faster if we copy this later because we can parallelize it with buildkit, but the build fails if this file doesn't exist -RUN mkdir -p ./wwwroot/.vite/ && touch ./wwwroot/.vite/manifest.json - -# build backend +# build RUN dotnet publish --no-restore -a $TARGETARCH -o /app # Enable globalization and time zones: @@ -40,6 +23,5 @@ RUN dotnet publish --no-restore -a $TARGETARCH -o /app # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine-composite WORKDIR /app -COPY --from=backend /app . -COPY --from=frontend /frontend/dist ./wwwroot +COPY --from=builder /app . ENTRYPOINT ["./Iceshrimp.Backend", "--environment", "Production", "--migrate-and-start"]