|
1 | | -# Base stage |
2 | | -FROM node:22-alpine AS base |
| 1 | +FROM debian:12-slim AS debian-updated |
3 | 2 |
|
4 | | -ENV CHROME_BIN="/usr/bin/chromium-browser" |
5 | | -ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" |
| 3 | +SHELL ["/bin/bash", "-euo", "pipefail", "-c"] |
| 4 | + |
| 5 | +# If we ever need to bust the cache, just change the date here. |
| 6 | +# While we don't cache anything in Drone, that might not be true when we migrate to GitHub Actions where some action might automatically enable layer caching. |
| 7 | +# This is fine, but is terrible in situations where we want to _force_ an update of a package. |
| 8 | +RUN echo 'cachebuster 2025-07-16' && apt-get update |
6 | 9 |
|
7 | | -# Folder used by puppeteer to write temporal files |
8 | | -ENV XDG_CONFIG_HOME=/tmp/.chromium |
9 | | -ENV XDG_CACHE_HOME=/tmp/.chromium |
| 10 | +FROM debian-updated AS debs |
10 | 11 |
|
11 | | -WORKDIR /usr/src/app |
| 12 | +RUN apt-cache depends chromium chromium-driver chromium-shell chromium-sandbox font-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-freefont-ttf libxss1 unifont fonts-open-sans fonts-roboto fonts-inter bash busybox util-linux openssl \ |
| 13 | + --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --no-pre-depends | grep '^\w' | xargs apt-get download |
| 14 | +RUN mkdir /dpkg && \ |
| 15 | + find . -type f -name '*.deb' -exec sh -c 'dpkg --extract "$1" /dpkg || exit 5' sh '{}' \; |
12 | 16 |
|
13 | | -# We use edge for Chromium to get the latest release. |
14 | | -RUN apk --no-cache upgrade && \ |
15 | | - apk add --no-cache udev ttf-opensans unifont ca-certificates dumb-init && \ |
16 | | - apk add --no-cache 'chromium>=138.0.7204.157' 'chromium-swiftshader>=138.0.7204.157' --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community && \ |
17 | | - # Remove NPM-related files and directories |
18 | | - rm -rf /usr/local/lib/node_modules/npm && \ |
19 | | - rm -rf /usr/local/bin/npm && \ |
20 | | - rm -rf /usr/local/bin/npx && \ |
21 | | - rm -rf /root/.npm && \ |
22 | | - rm -rf /root/.node-gyp && \ |
23 | | - # Clean up |
24 | | - rm -rf /tmp/* |
| 17 | +FROM debian:testing-slim AS ca-certs |
25 | 18 |
|
26 | | -# Build stage |
27 | | -FROM base AS build |
| 19 | +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates |
| 20 | +RUN update-ca-certificates --fresh |
28 | 21 |
|
| 22 | +FROM node:22-alpine AS build |
| 23 | + |
| 24 | +WORKDIR /src |
29 | 25 | COPY . ./ |
30 | 26 |
|
31 | 27 | RUN yarn install --pure-lockfile |
32 | 28 | RUN yarn run build |
| 29 | +RUN rm -rf node_modules/ && yarn install --pure-lockfile --production |
33 | 30 |
|
34 | | -# Production dependencies stage |
35 | | -FROM base AS prod-dependencies |
36 | | - |
37 | | -COPY package.json yarn.lock ./ |
38 | | -RUN yarn install --pure-lockfile --production |
39 | | - |
40 | | -# Final stage |
41 | | -FROM base |
| 31 | +FROM gcr.io/distroless/nodejs22-debian12:nonroot |
42 | 32 |
|
43 | 33 | LABEL maintainer= "Grafana team <[email protected]>" |
44 | 34 | LABEL org.opencontainers.image.source="https://github.com/grafana/grafana-image-renderer/tree/master/Dockerfile" |
45 | 35 |
|
46 | | -ARG GF_UID="472" |
47 | | -ARG GF_GID="472" |
48 | | -ENV GF_PATHS_HOME="/usr/src/app" |
49 | | - |
50 | | -WORKDIR $GF_PATHS_HOME |
| 36 | +COPY --from=debs /dpkg / |
| 37 | +COPY --from=ca-certs /etc/ssl/certs /etc/ssl/certs |
51 | 38 |
|
52 | | -RUN addgroup -S -g $GF_GID grafana && \ |
53 | | - adduser -S -u $GF_UID -G grafana grafana && \ |
54 | | - mkdir -p "$GF_PATHS_HOME" && \ |
55 | | - chown -R grafana:grafana "$GF_PATHS_HOME" |
| 39 | +USER root |
| 40 | +SHELL ["/bin/busybox", "sh", "-c"] |
| 41 | +RUN /bin/busybox --install |
| 42 | +# Verify that the browser was actually installed. |
| 43 | +RUN /usr/bin/chromium --version |
| 44 | +RUN fc-cache -fr |
| 45 | +USER nonroot |
56 | 46 |
|
| 47 | +ENV CHROME_BIN="/usr/bin/chromium" |
| 48 | +ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" |
57 | 49 | ENV NODE_ENV=production |
58 | 50 |
|
59 | | -COPY --from=prod-dependencies /usr/src/app/node_modules node_modules |
60 | | -COPY --from=build /usr/src/app/build build |
61 | | -COPY --from=build /usr/src/app/proto proto |
62 | | -COPY --from=build /usr/src/app/default.json config.json |
63 | | -COPY --from=build /usr/src/app/plugin.json plugin.json |
| 51 | +COPY --from=build /src/node_modules node_modules |
| 52 | +COPY --from=build /src/build build |
| 53 | +COPY --from=build /src/proto proto |
| 54 | +COPY --from=build /src/default.json config.json |
| 55 | +COPY --from=build /src/plugin.json plugin.json |
64 | 56 |
|
65 | 57 | EXPOSE 8081 |
66 | 58 |
|
67 | | -USER grafana |
68 | | - |
69 | | -ENTRYPOINT ["dumb-init", "--"] |
70 | | -CMD ["node", "build/app.js", "server", "--config=config.json"] |
| 59 | +CMD ["build/app.js", "server", "--config=config.json"] |
0 commit comments