forked from erpc/erpc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (65 loc) · 3.02 KB
/
Copy pathDockerfile
File metadata and controls
87 lines (65 loc) · 3.02 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# syntax = docker/dockerfile:1.4
# This Dockerfile is used to build the eRPC server image.
# Docker build stages:
# - go-builder -> build the go binary
# - ts-core -> Core stage for TS related stuff (just installing pnpm)
# - ts-dev -> Install dev dependencies and compile the SDK
# - ts-prod -> Install prod dependencies only
# - final -> Final stage where we copy the Go binary and the TS files
# Build stage for Go
FROM golang:1.26-alpine@sha256:7a3e50096189ad57c9f9f865e7e4aa8585ed1585248513dc5cda498e2f41812c AS go-builder
WORKDIR /build
# Copy go mod and sum files first for better layer caching
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Set build arguments
ARG VERSION
ARG COMMIT_SHA
# Set environment variables for Go build
ENV CGO_ENABLED=0 \
GOOS=linux \
LDFLAGS="-w -s -X github.com/erpc/erpc/common.ErpcVersion=${VERSION} -X github.com/erpc/erpc/common.ErpcCommitSha=${COMMIT_SHA}"
# Build the Go binary
RUN go build -v -ldflags="$LDFLAGS" -a -installsuffix cgo -o erpc-server ./cmd/erpc/main.go && \
go build -v -ldflags="$LDFLAGS" -a -installsuffix cgo -tags pprof -o erpc-server-pprof ./cmd/erpc/*.go
# Global typescript related image
FROM node:22-alpine@sha256:968df39aedcea65eeb078fb336ed7191baf48f972b4479711397108be0966920 AS ts-core
RUN npm install -g pnpm@11.0.9
# Stage where we will install dev dependencies + compile sdk
FROM ts-core AS ts-dev
RUN mkdir -p /temp/dev/typescript
RUN npm install -g pnpm@11.0.9
# Copy only the TypeScript package files
COPY typescript/config /temp/dev/typescript/config
COPY pnpm* /temp/dev/
COPY package.json /temp/dev/package.json
# Install everything and build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store cd /temp/dev && pnpm install --frozen-lockfile --ignore-scripts
RUN cd /temp/dev && pnpm build
# Stage where we will install prod dependencies only
FROM ts-core AS ts-prod
RUN mkdir -p /temp/prod/typescript
COPY typescript/config /temp/prod/typescript/config
COPY pnpm* /temp/prod/
COPY package.json /temp/prod/package.json
# Install every prod dependencies
RUN --mount=type=cache,id=pnpm,target=/pnpm/store cd /temp/prod && pnpm install --prod --frozen-lockfile --ignore-scripts
# Create symlink stage (for backwards compatibility with earlier image file structure)
FROM alpine:latest@sha256:a2d49ea686c2adfe3c992e47dc3b5e7fa6e6b5055609400dc2acaeb241c829f4 AS symlink
RUN mkdir -p /root && ln -s /erpc-server /root/erpc-server
# Final stage
FROM gcr.io/distroless/static-debian12:nonroot@sha256:d093aa3e30dbadd3efe1310db061a14da60299baff8450a17fe0ccc514a16639 AS final
# Copy Go binaries from go-builder
COPY --from=go-builder /build/erpc-server /
COPY --from=go-builder /build/erpc-server-pprof /
# Copy symlinked directory with preserved symlinks
COPY --from=symlink --link /root /root
# Copy TypeScript package files from ts-dev and ts-prod
COPY --from=ts-dev /temp/dev/typescript /typescript
COPY --from=ts-prod /temp/prod/node_modules /node_modules
# Expose ports
EXPOSE 4000 4001 6060
# Run the server
CMD ["/erpc-server"]