diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..812722b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +ARG GO_VERSION=1.16.0 + +FROM golang:${GO_VERSION}-alpine 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}" && \ + 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 + +ARG UID=1000 +ARG GID=1000 + +CMD addgroup -g "${GID}" prometheus && \ + adduser -D -u "${UID}" -G prometheus prometheus && \ + chmod 700 /prometheus && chown prometheus:prometheus /prometheus && \ + su prometheus -c '/prometheus --config.file=/config/prometheus.yml'