-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.build
More file actions
60 lines (42 loc) · 1.65 KB
/
Dockerfile.build
File metadata and controls
60 lines (42 loc) · 1.65 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
# Multi-stage Docker build for lambda-nat-proxy
# This ensures reproducible builds with all dependencies included
# Stage 1: Node.js environment for dashboard build
FROM node:18-alpine AS dashboard-builder
# Set working directory
WORKDIR /app
# Copy package files
COPY web/package*.json ./web/
WORKDIR /app/web
# Install dependencies and build dashboard
RUN npm ci --only=production
COPY web/ .
RUN npm run build
# Stage 2: Go environment for binary build
FROM golang:1.21-alpine AS go-builder
# Build arguments for target platform
ARG TARGETOS=linux
ARG TARGETARCH=amd64
# Install build dependencies
RUN apk add --no-cache git
# Set working directory
WORKDIR /app
# Copy source code first
COPY . .
# Copy built dashboard from previous stage
COPY --from=dashboard-builder /app/web/dist ./internal/dashboard/web/dist
# Fix the replace directive in lambda/go.mod to use absolute path
RUN sed -i 's|replace github.com/dan-v/lambda-nat-punch-proxy => ..|replace github.com/dan-v/lambda-nat-punch-proxy => /app|' lambda/go.mod
# Download dependencies
RUN go mod download
RUN cd lambda && go mod download
# Build Lambda function
RUN cd lambda && GOOS=linux GOARCH=amd64 go build -o ../cmd/lambda-nat-proxy/assets/bootstrap .
# Build main binary for target platform
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -o lambda-nat-proxy ./cmd/lambda-nat-proxy
# Stage 3: Final minimal image (optional, for running)
FROM alpine:latest AS final
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=go-builder /app/lambda-nat-proxy .
COPY --from=go-builder /app/cmd/lambda-nat-proxy/assets/bootstrap ./assets/
CMD ["./lambda-nat-proxy"]