-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (45 loc) · 1.4 KB
/
Dockerfile
File metadata and controls
57 lines (45 loc) · 1.4 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
57
# Stage 1: Build the React Frontend
FROM node:24-alpine AS ui-builder
WORKDIR /web
# Install dependencies first for better caching
COPY web/package*.json ./
RUN npm ci
# Build the UI
COPY web/ .
RUN npm run build
# Stage 2: Build the Go Backend
FROM golang:1.25-alpine AS go-builder
RUN apk add --no-cache make git
WORKDIR /workspace
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Copy the built UI assets to be embedded
COPY --from=ui-builder /web/dist/ internal/ui/dist/
ARG BUILD_VERSION=v0.0.0
# Build static binary
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-w -s -X github.com/ygelfand/power-dash/internal/cli.PowerDashVersion=${BUILD_VERSION}" \
-o bin/power-dash cmd/power-dash/main.go
# Stage 3: Final Production Image
FROM alpine:3.23
# Create a non-root user and group
RUN addgroup -S powerdash && adduser -S powerdash -G powerdash
# Install necessary runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
# Create directory structure
WORKDIR /app
RUN mkdir -p /data /etc/power-dash
# Copy binary
COPY --from=go-builder /workspace/bin/power-dash /usr/local/bin/power-dash
COPY config/power-dash.example.yaml /etc/power-dash/power-dash.yaml
RUN chown -R powerdash:powerdash /data
# Expose the application port
EXPOSE 8080
# Define volume for persistent data
VOLUME ["/data"]
# Switch to non-root user
USER powerdash
# Default entrypoint
ENTRYPOINT ["power-dash"]
CMD ["run"]