docker-prometheus/Dockerfile
2021-03-02 20:52:56 +01:00

46 lines
1.3 KiB
Docker

ARG GO_VERSION=alpine
FROM golang:${GO_VERSION} as build
ARG PROMETHEUS_VERSION=
ARG PROMETHEUS_REPO="https://github.com/prometheus/prometheus.git"
RUN \
apk update --no-cache &&\
apk add --no-cache \
bash \
curl \
git \
make \
yarn && \
git config --global advice.detachedHead false
RUN \
if [ -z "${PROMETHEUS_VERSION}" ]; then \
PROMETHEUS_VERSION=$( \
git ls-remote "${PROMETHEUS_REPO}" | \
awk '$2 ~ /^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+$/ { print substr($2,11) }' | sort -V | tail -n1 \
) ; \
fi && \
echo "selected prometheus branch: ${PROMETHEUS_VERSION}" && \
cd / && \
git clone \
--branch="${PROMETHEUS_VERSION}" \
--depth=1 \
"${PROMETHEUS_REPO}" && \
cd prometheus && \
CGO_ENABLED=0 make build
FROM alpine:3
COPY --from=build /prometheus/prometheus /prometheus
RUN mkdir /data
ENV UID=1000
ENV GID=1000
CMD (grep -qE '^prometheus:x:'"${UID}"':prometheus$' /etc/group || addgroup -g "${GID}" prometheus) && \
(grep -qE '^prometheus:x:'"${UID}"':'"${GID}"':.*$' /etc/passwd || adduser -D -u "${UID}" -G prometheus prometheus) && \
chmod 700 /prometheus && chown prometheus:prometheus /prometheus && \
chown prometheus:prometheus /data && \
su prometheus -c '/prometheus --config.file=/config/prometheus.yaml --storage.tsdb.path=/data/ '