-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
62 lines (43 loc) · 1.18 KB
/
Dockerfile
File metadata and controls
62 lines (43 loc) · 1.18 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
58
59
60
61
62
# --- Stage 1: Build Frontend ---
FROM node:22-alpine AS node-builder
WORKDIR /app/web
# Install dependencies and build
COPY web/package.json ./
RUN npm install
COPY web/ ./
RUN npm run build
# --- Stage 2: Build Backend ---
# Use Go 1.25.4 (Specified version)
FROM golang:1.25.4-alpine AS go-builder
# Install build dependencies (git required for go mod)
RUN apk add --no-cache git
WORKDIR /app
# Copy source code
COPY go.mod ./
COPY cmd/ cmd/
COPY internal/ internal/
COPY schema.sql ./
# Resolve dependencies
RUN go mod tidy
# Build the binary
ENV CGO_ENABLED=0
RUN go build -o nwdevice-viz ./cmd/server
# --- Stage 3: Final Image ---
FROM alpine:3.20
WORKDIR /app
# Create a non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy binary and schema
COPY --from=go-builder /app/nwdevice-viz .
COPY --from=go-builder /app/schema.sql .
# Copy built frontend assets
COPY --from=node-builder /app/web/dist ./web/dist
# Create directories and set permissions
RUN mkdir -p /app/data /app/certs && \
chown -R appuser:appgroup /app/data /app/certs /app
# Switch to non-root user
USER appuser
# Create DB directory
VOLUME /app/data
EXPOSE 8080
CMD ["./nwdevice-viz"]