forked from erpc/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
43 lines (30 loc) · 1.14 KB
/
Dockerfile
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
# Build stage
FROM golang:1.22-alpine AS builder
ARG VERSION
ARG COMMIT_SHA
# Set the working directory
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy the source code
COPY . .
# Build the application without pprof
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X main.version=${VERSION} -X main.commitSHA=${COMMIT_SHA}" go build -a -installsuffix cgo -o erpc-server ./cmd/erpc/main.go
# Build the application with pprof
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X main.version=${VERSION} -X main.commitSHA=${COMMIT_SHA}" go build -a -installsuffix cgo -tags pprof -o erpc-server-pprof ./cmd/erpc/*.go
# Final stage
FROM alpine:3.18
# Set the working directory
WORKDIR /root/
# Copy the binaries from the builder stage
COPY --from=builder /app/erpc-server .
COPY --from=builder /app/erpc-server-pprof .
# 8080 -> erpc
# 6060 -> pprof (optional)
EXPOSE 8080 6060
# Use an environment variable to determine which binary to run
ENV PPROF=false
# Run the appropriate binary based on the environment variable
CMD if [ "$PPROF" = "true" ]; then ./erpc-server-pprof; else ./erpc-server; fi