|
1 | | -# Stage 1: Build frontend |
2 | | -FROM node:alpine AS frontend-build |
| 1 | +# syntax=docker/dockerfile:1.4 |
| 2 | + |
| 3 | +# -------- Stage 1: Build frontend -------- |
| 4 | +FROM --platform=$BUILDPLATFORM node:alpine AS frontend-build |
| 5 | + |
3 | 6 | WORKDIR /frontend |
4 | 7 | COPY ./frontend ./ |
| 8 | + |
5 | 9 | RUN npm install |
6 | 10 | RUN npm run build |
7 | 11 | RUN npm prune --omit=dev |
8 | 12 |
|
9 | | -# Stage 2: Build backend |
10 | | -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS backend-build |
| 13 | +# -------- Stage 2: Build backend -------- |
| 14 | +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0 AS backend-build |
| 15 | + |
11 | 16 | WORKDIR /backend |
12 | 17 | COPY ./backend ./ |
| 18 | + |
| 19 | +# Accept build-time architecture as ARG (e.g., x64 or arm64) |
| 20 | +ARG TARGETARCH |
13 | 21 | RUN dotnet restore |
14 | | -RUN dotnet publish -c Release -r linux-musl-x64 -o ./publish |
| 22 | +RUN dotnet publish -c Release -r linux-musl-${TARGETARCH} -o ./publish |
15 | 23 |
|
16 | | -# Stage 3: Combined runtime |
| 24 | +# -------- Stage 3: Combined runtime image -------- |
17 | 25 | FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine |
| 26 | + |
18 | 27 | WORKDIR /app |
19 | | -RUN mkdir /config |
20 | | -RUN apk add --no-cache nodejs npm libc6-compat shadow su-exec bash |
| 28 | + |
| 29 | +# Prepare environment |
| 30 | +RUN mkdir /config \ |
| 31 | + && apk add --no-cache nodejs npm libc6-compat shadow su-exec bash |
| 32 | + |
| 33 | +# Copy frontend |
21 | 34 | COPY --from=frontend-build /frontend/node_modules ./frontend/node_modules |
22 | 35 | COPY --from=frontend-build /frontend/package.json ./frontend/package.json |
23 | 36 | COPY --from=frontend-build /frontend/server.js ./frontend/server.js |
24 | 37 | COPY --from=frontend-build /frontend/build ./frontend/build |
| 38 | + |
| 39 | +# Copy backend |
25 | 40 | COPY --from=backend-build /backend/publish ./backend |
26 | | -EXPOSE 3000 |
27 | | -ENV NODE_ENV=production |
| 41 | + |
| 42 | +# Entry and runtime setup |
28 | 43 | COPY entrypoint.sh /entrypoint.sh |
29 | 44 | RUN chmod +x /entrypoint.sh |
| 45 | + |
| 46 | +EXPOSE 3000 |
| 47 | +ENV NODE_ENV=production |
| 48 | + |
30 | 49 | CMD ["/entrypoint.sh"] |
0 commit comments