From 0f3dcfc57a898b16bc160035141086aa36dda29b Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 9 Aug 2020 17:49:13 -0400 Subject: [PATCH] Dockerfile --- .dockerignore | 11 +++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..67509c3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.git +.github +extra +_config.yml +.gitignore +example.json +LICENSE +README.md +/target +**/*.rs.bk +*.vim diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb0cd86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +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 +RUN apk add --update -q --no-cache wireguard-tools-wg +COPY --from=build --chown=1000 /usr/local/cargo/bin/prometheus_wireguard_exporter /usr/local/bin/prometheus_wireguard_exporter +ENTRYPOINT [ "prometheus_wireguard_exporter" ] +CMD [ "-h" ] +USER 1000