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) · 2.97 KB
/
Dockerfile
File metadata and controls
87 lines (65 loc) · 2.97 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:d4c4845f5d60c6a974c6000ce58ae079328d03ab7f721a0734277e69905473e5 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:20-alpine@sha256:09e2b3d9726018aecf269bd35325f46bf75046a643a66d28360ec71132750ec8 AS ts-core
RUN npm install -g pnpm
# 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
# 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
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
# Create symlink stage (for backwards compatibility with earlier image file structure)
FROM alpine:latest@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS symlink
RUN mkdir -p /root && ln -s /erpc-server /root/erpc-server
# Final stage
FROM gcr.io/distroless/static-debian12:nonroot@sha256:a9329520abc449e3b14d5bc3a6ffae065bdde0f02667fa10880c49b35c109fd1 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"]