-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
42 lines (29 loc) · 898 Bytes
/
Dockerfile
File metadata and controls
42 lines (29 loc) · 898 Bytes
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
# syntax = docker/dockerfile:1.4
# Build stage
FROM golang:1.22-alpine AS builder
# Set the working directory
WORKDIR /root
# Copy go mod and sum files first for better layer caching
COPY go.mod go.sum ./
# Download dependencies in a separate layer
RUN go mod download
# Copy the source code
COPY . .
# Set build arguments
ARG VERSION
ARG COMMIT_SHA
# Set environment variables
ENV CGO_ENABLED=0 \
GOOS=linux \
LDFLAGS="-w -s -X common.ErpcVersion=${VERSION} -X common.ErpcCommitSha=${COMMIT_SHA}"
# Build the binary
RUN go build -ldflags="$LDFLAGS" -a -installsuffix cgo -o erpc-server ./cmd/erpc/main.go
# Final stage - using distroless for smaller image
FROM gcr.io/distroless/static-debian11 AS final
WORKDIR /root
# Copy binary from the builder
COPY --from=builder /root/erpc-server .
# Expose ports
EXPOSE 8080 6060
# Run the appropriate binary
CMD ["/root/erpc-server"]