Make Dockerfile support fast crossbuilds

This commit is contained in:
Laura Hausmann 2024-01-08 18:32:33 +01:00
parent fbb0ccb5a1
commit 3dcc255965
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -1,4 +1,4 @@
FROM alpine:3.18 AS frontend FROM --platform=$BUILDPLATFORM alpine:3.18 AS frontend
WORKDIR /frontend WORKDIR /frontend
RUN apk add --no-cache --no-progress nodejs-current npm RUN apk add --no-cache --no-progress nodejs-current npm
@ -15,21 +15,21 @@ RUN yarn --immutable && yarn build
#TODO: why is a second yarn pass required here? #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 backend
ARG TARGETARCH
WORKDIR /backend WORKDIR /backend
# copy csproj and restore as distinct layers # copy csproj and restore as distinct layers
COPY Iceshrimp.Backend/*.csproj . COPY Iceshrimp.Backend/*.csproj .
RUN dotnet restore -a amd64 #TODO: make this configurable but defaulting to the current architecture RUN dotnet restore -a $TARGETARCH
# copy and build backend # copy and build backend
COPY Iceshrimp.Backend/. . COPY Iceshrimp.Backend/. .
RUN dotnet publish --no-restore -a amd64 -o /app #TODO: make this configurable but defaulting to the current architecture RUN dotnet publish --no-restore -a $TARGETARCH -o /app
# Enable globalization and time zones: # Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image # final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine-composite FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine-composite
EXPOSE 8080
WORKDIR /app WORKDIR /app
COPY --from=backend /app . COPY --from=backend /app .
COPY --from=frontend /frontend/dist ./wwwroot COPY --from=frontend /frontend/dist ./wwwroot