grafana: Move to multi-stage build

This improves cacheability and lowers total container image size by only
copying artefacts that are useful for deployment.
This commit is contained in:
Alex Palaistras 2024-01-02 15:55:37 +00:00
parent f9625a8e66
commit 9b9a906363

View File

@ -1,16 +1,21 @@
FROM docker.io/debian:bookworm-slim@sha256:f80c45482c8d147da87613cb6878a7238b8642bcc24fc11bad78c7bec726f340 FROM docker.io/debian:bookworm-slim@sha256:f80c45482c8d147da87613cb6878a7238b8642bcc24fc11bad78c7bec726f340 AS builder
ARG VERSION=10.2.3 # renovate: datasource=github-releases depName=grafana/grafana extractVersion=^v(?<version>.*)$ ARG VERSION=10.2.3 # renovate: datasource=github-releases depName=grafana/grafana extractVersion=^v(?<version>.*)$
WORKDIR /src
RUN apt-get update -y && apt-get upgrade -y && \ ADD https://dl.grafana.com/oss/release/grafana-${VERSION}.linux-amd64.tar.gz /src.tar.gz
apt-get install -y --no-install-recommends curl ca-certificates RUN tar --no-same-owner -xvzf /src.tar.gz && \
install -D --mode 0755 /src/grafana-v${VERSION}/bin/grafana /build/usr/bin/grafana && \
mkdir -p /build/usr/share/grafana && cp -R /src/grafana-v${VERSION}/public /build/usr/share/grafana/public
RUN addgroup --system --gid 10000 grafana FROM docker.io/debian:bookworm-slim@sha256:f80c45482c8d147da87613cb6878a7238b8642bcc24fc11bad78c7bec726f340
RUN adduser --system --uid 10000 --ingroup grafana --home /var/lib/grafana grafana RUN apt-get update -y && apt-get upgrade -y && apt-get install -y --no-install-recommends \
ca-certificates gettext gosu
RUN curl -fsSL https://dl.grafana.com/oss/release/grafana-${VERSION}.linux-amd64.tar.gz | \ RUN apt-get update -y && apt-get install -y --no-install-recommends curl
tar -C /opt --no-same-owner -xvzf - && mv /opt/grafana-v${VERSION} /opt/grafana RUN adduser --system --group --uid 10000 --home /var/lib/grafana grafana
COPY --from=builder /build /
COPY container/config /etc/grafana COPY container/config /etc/grafana
USER grafana
ENTRYPOINT ["/opt/grafana/bin/grafana", "server", "--config", "/etc/grafana/grafana.ini", "--homepath", "/opt/grafana", "web"] USER grafana
ENTRYPOINT ["/usr/bin/grafana", "server", "--config", "/etc/grafana/grafana.ini", "--homepath", "/usr/share/grafana", "web"]