Containing and Deploying the Exporter
Now that you have a working exporter for your Pico W temperature sensor, let’s create an image to run the exporter as a container in your Raspberry Pi infrastructure, similar to what you did in Containing the Server.
First, create a Dockerfile using the multi-stage approach to compile your Go Prometheus exporter in the first stage, and create an image for it in the second stage:
| FROM docker.io/golang:1.22 AS builder |
| RUN mkdir /app |
| WORKDIR /app |
| COPY . /app |
| RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" |
| |
| FROM docker.io/alpine:latest |
| RUN mkdir /app && adduser -h /app -D picotempexport |
| WORKDIR /app |
| COPY --chown=picotempexport --from=builder /app/picotempexport ... |
Get Automate Your Home Using Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.