2020-08-09 23:49:13 +02:00
|
|
|
ARG ALPINE_VERSION=3.12
|
|
|
|
ARG RUST_VERSION=1-alpine${ALPINE_VERSION}
|
|
|
|
|
|
|
|
FROM rust:${RUST_VERSION} AS build
|
|
|
|
WORKDIR /usr/src/prometheus_wireguard_exporter
|
|
|
|
|
|
|
|
# Setup
|
|
|
|
ARG ARCH=x86_64
|
|
|
|
RUN apk add --update -q --no-cache musl-dev
|
|
|
|
RUN rustup target add ${ARCH}-unknown-linux-musl
|
|
|
|
|
|
|
|
# Install dependencies
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
RUN mkdir src && \
|
|
|
|
echo "fn main() {}" > src/main.rs
|
|
|
|
RUN cargo build --release && \
|
|
|
|
rm -rf target/release/deps/prometheus_wireguard_exporter*
|
|
|
|
|
|
|
|
# Build the musl linked binary
|
|
|
|
COPY . .
|
|
|
|
RUN cargo build --release
|
|
|
|
RUN cargo install --target ${ARCH}-unknown-linux-musl --path .
|
|
|
|
|
|
|
|
FROM alpine:${ALPINE_VERSION}
|
|
|
|
EXPOSE 9586/tcp
|
2020-10-13 14:07:40 +02:00
|
|
|
RUN adduser prometheus-wireguard-exporter -s /bin/sh -D -u 1000 1000 && \
|
|
|
|
mkdir -p /etc/sudoers.d && \
|
2021-01-02 21:59:08 +01:00
|
|
|
echo 'prometheus-wireguard-exporter ALL=(root) NOPASSWD:/usr/bin/wg show * dump' > /etc/sudoers.d/prometheus-wireguard-exporter && \
|
2020-10-13 14:07:40 +02:00
|
|
|
chmod 0440 /etc/sudoers.d/prometheus-wireguard-exporter
|
|
|
|
RUN apk add --update -q --no-cache wireguard-tools-wg sudo
|
|
|
|
USER prometheus-wireguard-exporter
|
2020-08-09 23:49:13 +02:00
|
|
|
ENTRYPOINT [ "prometheus_wireguard_exporter" ]
|
2020-10-13 14:07:40 +02:00
|
|
|
CMD [ "-a" ]
|
|
|
|
COPY --from=build --chown=prometheus-wireguard-exporter /usr/local/cargo/bin/prometheus_wireguard_exporter /usr/local/bin/prometheus_wireguard_exporter
|