Skip to content

Commit 1765722

Browse files
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 <[email protected]>
1 parent dcbec5d commit 1765722

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1+
# Base stage
12
FROM node:18-alpine AS base
23

34
ENV CHROME_BIN="/usr/bin/chromium-browser"
45
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
56

67
WORKDIR /usr/src/app
78

8-
RUN \
9-
apk --no-cache upgrade && \
10-
apk add --no-cache udev ttf-opensans unifont chromium ca-certificates dumb-init && \
11-
rm -rf /tmp/*
9+
RUN apk --no-cache upgrade && \
10+
apk add --no-cache udev ttf-opensans unifont chromium ca-certificates dumb-init && \
11+
rm -rf /tmp/*
1212

13-
FROM base as build
13+
# Build stage
14+
FROM base AS build
1415

1516
COPY . ./
1617

1718
RUN yarn install --pure-lockfile
1819
RUN yarn run build
1920

20-
EXPOSE 8081
21+
# Production dependencies stage
22+
FROM base AS prod-dependencies
2123

22-
CMD [ "yarn", "run", "dev" ]
24+
COPY package.json yarn.lock ./
25+
RUN yarn install --pure-lockfile --production
2326

27+
# Final stage
2428
FROM base
2529

2630
LABEL maintainer="Grafana team <[email protected]>"
@@ -38,7 +42,7 @@ RUN addgroup -S -g $GF_GID grafana && \
3842

3943
ENV NODE_ENV=production
4044

41-
COPY --from=build /usr/src/app/node_modules node_modules
45+
COPY --from=prod-dependencies /usr/src/app/node_modules node_modules
4246
COPY --from=build /usr/src/app/build build
4347
COPY --from=build /usr/src/app/proto proto
4448
COPY --from=build /usr/src/app/default.json config.json

debian.Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@ RUN apt-get install -y wget gnupg \
1717
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
1818
RUN chmod +x /usr/local/bin/dumb-init
1919

20+
# Build stage
2021
FROM base as build
2122

2223
COPY . ./
2324

2425
RUN yarn install --pure-lockfile
2526
RUN yarn run build
2627

27-
EXPOSE 8081
28+
# Production dependencies stage
29+
FROM base AS prod-dependencies
2830

29-
CMD [ "yarn", "run", "dev" ]
31+
COPY package.json yarn.lock ./
32+
RUN yarn install --pure-lockfile --production
3033

34+
# Final stage
3135
FROM base
3236

3337
ENV NODE_ENV=production
3438

35-
COPY --from=build /usr/src/app/node_modules node_modules
39+
COPY --from=prod-dependencies /usr/src/app/node_modules node_modules
3640
COPY --from=build /usr/src/app/build build
3741
COPY --from=build /usr/src/app/proto proto
3842
COPY --from=build /usr/src/app/default.json config.json

0 commit comments

Comments
 (0)