From 7c0966d5ae9c6225cf7a14a426c526ad94ea8280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 2 Apr 2023 22:00:33 +0200 Subject: [PATCH] feat: optimize dockerfile for multi-platform As our api & frontend compilation processes do not depend on the target platform, we can run them once and then just build seperate final images per target platform. --- Dockerfile | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65fd5b1..622d6dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,22 @@ +FROM scratch as ignore + +WORKDIR /listory +COPY . /listory/ + ################## ## common ################## -FROM node:18-alpine as common - -ARG VERSION=unknown -ARG GIT_COMMIT=unknown - -LABEL org.opencontainers.image.title="listory" \ - org.opencontainers.image.version=$VERSION \ - org.opencontainers.image.revision=$GIT_COMMIT \ - stage="common" +FROM --platform=$BUILDPLATFORM node:18-alpine as common WORKDIR /app -COPY *.json /app/ -COPY frontend/*.json /app/frontend/ - ################## ## build-api ################## FROM common as build-api LABEL stage="build-api" +COPY *.json /app/ RUN npm ci COPY src/ /app/src/ @@ -37,22 +32,31 @@ ARG VERSION=unknown WORKDIR /app/frontend +COPY frontend/package*.json /app/frontend/ RUN npm ci -COPY frontend/postcss.config.js /app/frontend/postcss.config.js -COPY frontend/tailwind.config.js /app/frontend/tailwind.config.js -COPY frontend/src/ /app/frontend/src/ -COPY frontend/public/ /app/frontend/public/ -COPY frontend/.env.production /app/frontend/.env.production +COPY frontend/ /app/frontend/ RUN NODE_ENV=production npm run build ################## ## app ################## -FROM common as app -LABEL stage="app" +FROM node:18-alpine as app +ARG VERSION=unknown +ARG GIT_COMMIT=unknown + +LABEL org.opencontainers.image.title="listory" \ + org.opencontainers.image.version=$VERSION \ + org.opencontainers.image.revision=$GIT_COMMIT \ + stage="common" + +WORKDIR /app + +COPY package.json /app/ +COPY package-lock.json /app/ RUN npm ci --omit=dev + COPY --from=build-api /app/dist/ /app/dist/ COPY --from=build-frontend /app/frontend/build /app/static/