2022-11-28 15:18:53 -06:00
|
|
|
# syntax=docker/dockerfile:1
|
2022-11-28 13:43:42 -06:00
|
|
|
|
2024-03-07 07:04:37 -06:00
|
|
|
ARG BASE_IMAGE=alpine:3.19.1
|
|
|
|
ARG JS_IMAGE=node:20-alpine
|
2023-03-23 10:03:25 -05:00
|
|
|
ARG JS_PLATFORM=linux/amd64
|
2024-04-24 13:26:14 -05:00
|
|
|
ARG GO_IMAGE=golang:1.22.2-alpine
|
2022-11-28 13:43:42 -06:00
|
|
|
|
2022-11-28 15:18:53 -06:00
|
|
|
ARG GO_SRC=go-builder
|
|
|
|
ARG JS_SRC=js-builder
|
|
|
|
|
2023-03-23 10:03:25 -05:00
|
|
|
FROM --platform=${JS_PLATFORM} ${JS_IMAGE} as js-builder
|
2019-08-16 10:46:35 -05:00
|
|
|
|
2021-10-28 09:41:10 -05:00
|
|
|
ENV NODE_OPTIONS=--max_old_space_size=8000
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
WORKDIR /tmp/grafana
|
2021-10-28 09:41:10 -05:00
|
|
|
|
|
|
|
COPY package.json yarn.lock .yarnrc.yml ./
|
2021-10-26 05:08:31 -05:00
|
|
|
COPY .yarn .yarn
|
2019-01-25 03:50:05 -06:00
|
|
|
COPY packages packages
|
2021-10-26 05:08:31 -05:00
|
|
|
COPY plugins-bundled plugins-bundled
|
2023-10-16 10:31:43 -05:00
|
|
|
COPY public public
|
2019-01-25 03:50:05 -06:00
|
|
|
|
2024-02-23 04:14:54 -06:00
|
|
|
RUN apk add --no-cache make build-base python3
|
|
|
|
|
2024-02-23 07:11:04 -06:00
|
|
|
RUN yarn install --immutable
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2024-01-16 07:26:43 -06:00
|
|
|
COPY tsconfig.json .eslintrc .editorconfig .browserslistrc .prettierrc.js ./
|
2018-02-06 18:58:37 -06:00
|
|
|
COPY public public
|
|
|
|
COPY scripts scripts
|
|
|
|
COPY emails emails
|
2018-04-20 13:28:52 -05:00
|
|
|
|
|
|
|
ENV NODE_ENV production
|
2020-12-02 08:49:48 -06:00
|
|
|
RUN yarn build
|
2018-01-29 05:01:05 -06:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
FROM ${GO_IMAGE} as go-builder
|
|
|
|
|
2023-04-18 08:03:27 -05:00
|
|
|
ARG COMMIT_SHA=""
|
|
|
|
ARG BUILD_BRANCH=""
|
2023-02-28 14:18:00 -06:00
|
|
|
ARG GO_BUILD_TAGS="oss"
|
|
|
|
ARG WIRE_TAGS="oss"
|
|
|
|
ARG BINGO="true"
|
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
RUN if grep -i -q alpine /etc/issue; then \
|
2024-04-03 07:21:27 -05:00
|
|
|
apk add --no-cache \
|
|
|
|
# This is required to allow building on arm64 due to https://github.com/golang/go/issues/22040
|
|
|
|
binutils-gold \
|
|
|
|
# Install build dependencies
|
|
|
|
gcc g++ make git; \
|
2022-11-28 13:43:42 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
WORKDIR /tmp/grafana
|
2020-05-04 04:59:10 -05:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
COPY go.* ./
|
|
|
|
COPY .bingo .bingo
|
2020-05-04 04:59:10 -05:00
|
|
|
|
2023-11-17 10:38:46 -06:00
|
|
|
# Include vendored dependencies
|
|
|
|
COPY pkg/util/xorm/go.* pkg/util/xorm/
|
2024-02-27 06:29:58 -06:00
|
|
|
COPY pkg/apiserver/go.* pkg/apiserver/
|
|
|
|
COPY pkg/apimachinery/go.* pkg/apimachinery/
|
2024-04-03 08:01:09 -05:00
|
|
|
COPY pkg/build/wire/go.* pkg/build/wire/
|
2024-03-19 06:41:27 -05:00
|
|
|
COPY pkg/promlib/go.* pkg/promlib/
|
2023-11-17 10:38:46 -06:00
|
|
|
|
2023-02-28 14:18:00 -06:00
|
|
|
RUN go mod download
|
|
|
|
RUN if [[ "$BINGO" = "true" ]]; then \
|
|
|
|
go install github.com/bwplotka/bingo@latest && \
|
|
|
|
bingo get -v; \
|
|
|
|
fi
|
2020-05-04 04:59:10 -05:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
COPY embed.go Makefile build.go package.json ./
|
|
|
|
COPY cue.mod cue.mod
|
|
|
|
COPY kinds kinds
|
2023-03-14 14:44:11 -05:00
|
|
|
COPY local local
|
2021-09-09 00:54:36 -05:00
|
|
|
COPY packages/grafana-schema packages/grafana-schema
|
2021-05-04 02:43:12 -05:00
|
|
|
COPY public/app/plugins public/app/plugins
|
2023-02-02 05:18:04 -06:00
|
|
|
COPY public/api-merged.json public/api-merged.json
|
2020-05-04 04:59:10 -05:00
|
|
|
COPY pkg pkg
|
2021-10-28 09:41:10 -05:00
|
|
|
COPY scripts scripts
|
2022-11-28 15:18:53 -06:00
|
|
|
COPY conf conf
|
2023-01-25 09:31:16 -06:00
|
|
|
COPY .github .github
|
2023-08-30 06:26:50 -05:00
|
|
|
COPY LICENSE ./
|
2023-04-18 08:03:27 -05:00
|
|
|
|
|
|
|
ENV COMMIT_SHA=${COMMIT_SHA}
|
|
|
|
ENV BUILD_BRANCH=${BUILD_BRANCH}
|
2020-05-04 04:59:10 -05:00
|
|
|
|
2023-02-28 14:18:00 -06:00
|
|
|
RUN make build-go GO_BUILD_TAGS=${GO_BUILD_TAGS} WIRE_TAGS=${WIRE_TAGS}
|
2020-05-04 04:59:10 -05:00
|
|
|
|
2022-11-28 15:18:53 -06:00
|
|
|
FROM ${BASE_IMAGE} as tgz-builder
|
|
|
|
|
|
|
|
WORKDIR /tmp/grafana
|
|
|
|
|
|
|
|
ARG GRAFANA_TGZ="grafana-latest.linux-x64-musl.tar.gz"
|
|
|
|
|
|
|
|
COPY ${GRAFANA_TGZ} /tmp/grafana.tar.gz
|
|
|
|
|
|
|
|
# add -v to make tar print every file it extracts
|
|
|
|
RUN tar x -z -f /tmp/grafana.tar.gz --strip-components=1
|
|
|
|
|
|
|
|
# helpers for COPY --from
|
|
|
|
FROM ${GO_SRC} as go-src
|
|
|
|
FROM ${JS_SRC} as js-src
|
|
|
|
|
2020-05-04 04:59:10 -05:00
|
|
|
# Final stage
|
2022-11-28 13:43:42 -06:00
|
|
|
FROM ${BASE_IMAGE}
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
LABEL maintainer="Grafana Labs <hello@grafana.com>"
|
2019-05-13 03:51:16 -05:00
|
|
|
|
2018-04-20 13:28:52 -05:00
|
|
|
ARG GF_UID="472"
|
2020-11-23 05:29:53 -06:00
|
|
|
ARG GF_GID="0"
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2019-11-04 12:55:40 -06:00
|
|
|
ENV PATH="/usr/share/grafana/bin:$PATH" \
|
2022-11-28 13:43:42 -06:00
|
|
|
GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
|
|
|
|
GF_PATHS_DATA="/var/lib/grafana" \
|
|
|
|
GF_PATHS_HOME="/usr/share/grafana" \
|
|
|
|
GF_PATHS_LOGS="/var/log/grafana" \
|
|
|
|
GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \
|
|
|
|
GF_PATHS_PROVISIONING="/etc/grafana/provisioning"
|
2018-04-20 13:28:52 -05:00
|
|
|
|
|
|
|
WORKDIR $GF_PATHS_HOME
|
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
# Install dependencies
|
|
|
|
RUN if grep -i -q alpine /etc/issue; then \
|
2023-03-31 15:36:57 -05:00
|
|
|
apk add --no-cache ca-certificates bash curl tzdata musl-utils && \
|
2022-11-28 13:43:42 -06:00
|
|
|
apk info -vv | sort; \
|
|
|
|
elif grep -i -q ubuntu /etc/issue; then \
|
|
|
|
DEBIAN_FRONTEND=noninteractive && \
|
|
|
|
apt-get update && \
|
2023-08-30 12:26:35 -05:00
|
|
|
apt-get install -y ca-certificates curl tzdata musl && \
|
2022-11-28 13:43:42 -06:00
|
|
|
apt-get autoremove -y && \
|
|
|
|
rm -rf /var/lib/apt/lists/*; \
|
|
|
|
else \
|
|
|
|
echo 'ERROR: Unsupported base image' && /bin/false; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
# glibc support for alpine x86_64 only
|
|
|
|
RUN if grep -i -q alpine /etc/issue && [ `arch` = "x86_64" ]; then \
|
2023-02-27 07:50:32 -06:00
|
|
|
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
|
2022-11-28 13:43:42 -06:00
|
|
|
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-2.35-r0.apk \
|
|
|
|
-O /tmp/glibc-2.35-r0.apk && \
|
|
|
|
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-bin-2.35-r0.apk \
|
|
|
|
-O /tmp/glibc-bin-2.35-r0.apk && \
|
2023-02-27 07:50:32 -06:00
|
|
|
apk add --force-overwrite --no-cache /tmp/glibc-2.35-r0.apk /tmp/glibc-bin-2.35-r0.apk && \
|
2022-11-28 13:43:42 -06:00
|
|
|
rm -f /lib64/ld-linux-x86-64.so.2 && \
|
|
|
|
ln -s /usr/glibc-compat/lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 && \
|
|
|
|
rm -f /tmp/glibc-2.35-r0.apk && \
|
|
|
|
rm -f /tmp/glibc-bin-2.35-r0.apk && \
|
|
|
|
rm -f /lib/ld-linux-x86-64.so.2 && \
|
|
|
|
rm -f /etc/ld.so.cache; \
|
|
|
|
fi
|
2018-08-07 09:11:37 -05:00
|
|
|
|
2022-11-28 15:18:53 -06:00
|
|
|
COPY --from=go-src /tmp/grafana/conf ./conf
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2020-11-23 05:29:53 -06:00
|
|
|
RUN if [ ! $(getent group "$GF_GID") ]; then \
|
2022-11-28 13:43:42 -06:00
|
|
|
if grep -i -q alpine /etc/issue; then \
|
|
|
|
addgroup -S -g $GF_GID grafana; \
|
|
|
|
else \
|
|
|
|
addgroup --system --gid $GF_GID grafana; \
|
|
|
|
fi; \
|
|
|
|
fi && \
|
|
|
|
GF_GID_NAME=$(getent group $GF_GID | cut -d':' -f1) && \
|
|
|
|
mkdir -p "$GF_PATHS_HOME/.aws" && \
|
|
|
|
if grep -i -q alpine /etc/issue; then \
|
|
|
|
adduser -S -u $GF_UID -G "$GF_GID_NAME" grafana; \
|
|
|
|
else \
|
|
|
|
adduser --system --uid $GF_UID --ingroup "$GF_GID_NAME" grafana; \
|
|
|
|
fi && \
|
|
|
|
mkdir -p "$GF_PATHS_PROVISIONING/datasources" \
|
|
|
|
"$GF_PATHS_PROVISIONING/dashboards" \
|
|
|
|
"$GF_PATHS_PROVISIONING/notifiers" \
|
|
|
|
"$GF_PATHS_PROVISIONING/plugins" \
|
|
|
|
"$GF_PATHS_PROVISIONING/access-control" \
|
|
|
|
"$GF_PATHS_PROVISIONING/alerting" \
|
|
|
|
"$GF_PATHS_LOGS" \
|
|
|
|
"$GF_PATHS_PLUGINS" \
|
|
|
|
"$GF_PATHS_DATA" && \
|
|
|
|
cp conf/sample.ini "$GF_PATHS_CONFIG" && \
|
|
|
|
cp conf/ldap.toml /etc/grafana/ldap.toml && \
|
|
|
|
chown -R "grafana:$GF_GID_NAME" "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING" && \
|
|
|
|
chmod -R 777 "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING"
|
|
|
|
|
2022-11-28 15:18:53 -06:00
|
|
|
COPY --from=go-src /tmp/grafana/bin/grafana* /tmp/grafana/bin/*/grafana* ./bin/
|
|
|
|
COPY --from=js-src /tmp/grafana/public ./public
|
2023-08-30 06:26:50 -05:00
|
|
|
COPY --from=go-src /tmp/grafana/LICENSE ./
|
2018-04-20 13:28:52 -05:00
|
|
|
|
|
|
|
EXPOSE 3000
|
|
|
|
|
2022-11-28 15:18:53 -06:00
|
|
|
ARG RUN_SH=./packaging/docker/run.sh
|
|
|
|
|
|
|
|
COPY ${RUN_SH} /run.sh
|
2018-04-20 13:28:52 -05:00
|
|
|
|
2022-11-28 13:43:42 -06:00
|
|
|
USER "$GF_UID"
|
2018-04-20 13:28:52 -05:00
|
|
|
ENTRYPOINT [ "/run.sh" ]
|