-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (44 loc) · 1.39 KB
/
Dockerfile
File metadata and controls
66 lines (44 loc) · 1.39 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
63
64
65
66
# Stage 1: Build frontend
FROM --platform=$BUILDPLATFORM node:25-alpine AS frontend-builder
WORKDIR /app/web
# Copy package files
COPY web/package*.json ./
# Install dependencies
RUN npm ci
# Copy frontend source
COPY web/ ./
# Build frontend
RUN npm run build
# Stage 2: Build backend
FROM --platform=$BUILDPLATFORM golang:1.26.1-alpine AS backend-builder
# Build arguments for cross-compilation
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git ca-certificates
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies with retry and verbose output
RUN go env -w GOPROXY=https://proxy.golang.org,direct && \
go mod download -x
# Copy source code
COPY . .
# Copy frontend build from previous stage
COPY --from=frontend-builder /app/web/dist ./web/dist
# Build the Go application for target platform
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o tracker .
# Stage 3: Final runtime image
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the binary from builder
COPY --from=backend-builder /app/tracker .
# Copy frontend build
COPY --from=frontend-builder /app/web/dist ./web/dist
# Copy swagger documentation
COPY --from=backend-builder /app/generated/openapiv2 ./generated/openapiv2
# Expose ports
EXPOSE 8080 8081 8765
# Run the application
CMD ["./tracker", "serv"]