-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (41 loc) · 1.68 KB
/
Dockerfile
File metadata and controls
56 lines (41 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Build stage
# Use golang:1.25.4-alpine which uses Alpine 3.22.2 to avoid qemu emulation issues
FROM golang:1.26.2-alpine@sha256:f85330846cde1e57ca9ec309382da3b8e6ae3ab943d2739500e08c86393a21b1 AS builder
WORKDIR /app
# Install git and ca-certificates
RUN apk add --no-cache git ca-certificates
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application with version information
# Accept build args for version info, fall back to git describe if not provided
ARG VERSION
ARG COMMIT
ARG BUILD_DATE
RUN VERSION=${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo "dev")} && \
COMMIT=${COMMIT:-$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")} && \
BUILD_DATE=${BUILD_DATE:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")} && \
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo \
-ldflags="-s -w \
-X github.com/d0ugal/zigbee2mqtt-exporter/internal/version.Version=$VERSION \
-X github.com/d0ugal/zigbee2mqtt-exporter/internal/version.Commit=$COMMIT \
-X github.com/d0ugal/zigbee2mqtt-exporter/internal/version.BuildDate=$BUILD_DATE" \
-o zigbee2mqtt-exporter ./cmd
# Final stage
FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11
RUN apk --no-cache add ca-certificates
# Setup an unprivileged user
RUN addgroup -g 1000 appgroup && \
adduser -D -u 1000 -G appgroup appuser
WORKDIR /app
RUN chown appuser:appgroup /app
USER appuser
# Copy the binary from builder stage
COPY --from=builder --chown=appuser:appuser /app/zigbee2mqtt-exporter .
# Expose port
EXPOSE 8087
# Run the binary
CMD ["/app/zigbee2mqtt-exporter"]