From 1765722dca1738b56c304da041e411bc683eb47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agn=C3=A8s=20Toulet?= <35176601+AgnesToulet@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:38:13 +0200 Subject: [PATCH] Chore: Don't install dev packages in Docker image (#575) * add flag to yarn install in docker image * make great dockerfile * remove dev-dependencies stage * apply same update to Debian Dockerfile --------- Co-authored-by: Maciej Tonderski --- Dockerfile | 20 ++++++++++++-------- debian.Dockerfile | 10 +++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d09c135..9773c94e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# Base stage FROM node:18-alpine AS base ENV CHROME_BIN="/usr/bin/chromium-browser" @@ -5,22 +6,25 @@ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" WORKDIR /usr/src/app -RUN \ - apk --no-cache upgrade && \ - apk add --no-cache udev ttf-opensans unifont chromium ca-certificates dumb-init && \ - rm -rf /tmp/* +RUN apk --no-cache upgrade && \ + apk add --no-cache udev ttf-opensans unifont chromium ca-certificates dumb-init && \ + rm -rf /tmp/* -FROM base as build +# Build stage +FROM base AS build COPY . ./ RUN yarn install --pure-lockfile RUN yarn run build -EXPOSE 8081 +# Production dependencies stage +FROM base AS prod-dependencies -CMD [ "yarn", "run", "dev" ] +COPY package.json yarn.lock ./ +RUN yarn install --pure-lockfile --production +# Final stage FROM base LABEL maintainer="Grafana team " @@ -38,7 +42,7 @@ RUN addgroup -S -g $GF_GID grafana && \ ENV NODE_ENV=production -COPY --from=build /usr/src/app/node_modules node_modules +COPY --from=prod-dependencies /usr/src/app/node_modules node_modules COPY --from=build /usr/src/app/build build COPY --from=build /usr/src/app/proto proto COPY --from=build /usr/src/app/default.json config.json diff --git a/debian.Dockerfile b/debian.Dockerfile index 90e05eb0..1eee7bbe 100644 --- a/debian.Dockerfile +++ b/debian.Dockerfile @@ -17,6 +17,7 @@ RUN apt-get install -y wget gnupg \ ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init RUN chmod +x /usr/local/bin/dumb-init +# Build stage FROM base as build COPY . ./ @@ -24,15 +25,18 @@ COPY . ./ RUN yarn install --pure-lockfile RUN yarn run build -EXPOSE 8081 +# Production dependencies stage +FROM base AS prod-dependencies -CMD [ "yarn", "run", "dev" ] +COPY package.json yarn.lock ./ +RUN yarn install --pure-lockfile --production +# Final stage FROM base ENV NODE_ENV=production -COPY --from=build /usr/src/app/node_modules node_modules +COPY --from=prod-dependencies /usr/src/app/node_modules node_modules COPY --from=build /usr/src/app/build build COPY --from=build /usr/src/app/proto proto COPY --from=build /usr/src/app/default.json config.json