Skip to content

Commit

Permalink
Chore: Don't install dev packages in Docker image (#575)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
AgnesToulet and McTonderski authored Oct 17, 2024
1 parent dcbec5d commit 1765722
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# Base stage
FROM node:18-alpine AS base

ENV CHROME_BIN="/usr/bin/chromium-browser"
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 <[email protected]>"
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ 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 . ./

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
Expand Down

0 comments on commit 1765722

Please sign in to comment.