shrink docker image / esbuildify (#319)

multistage docker build + esbuild
This commit is contained in:
jordy25519
2024-12-17 12:12:43 +08:00
committed by GitHub
parent 83bc842e7d
commit 4227c6b546
4 changed files with 66 additions and 16 deletions

View File

@@ -1,19 +1,36 @@
FROM public.ecr.aws/bitnami/node:20.18.1
RUN apt-get install git
ENV NODE_ENV=production
RUN npm install -g typescript
FROM node:20.18.1 AS builder
WORKDIR /app
COPY drift-common /app/drift-common
COPY . .
# Copy package files first to leverage cache
COPY package.json yarn.lock ./
COPY drift-common/protocol/sdk/package.json ./drift-common/protocol/sdk/
COPY drift-common/common-ts/package.json ./drift-common/common-ts/
RUN npm install -g bun typescript husky
WORKDIR /app/drift-common/protocol/sdk
RUN yarn
RUN yarn build
WORKDIR /app/drift-common/common-ts
RUN yarn
RUN yarn build
WORKDIR /app
RUN yarn
RUN yarn build
COPY drift-common/protocol/sdk/ .
RUN bun install --production && bun run build
WORKDIR /app/drift-common/common-ts
COPY drift-common/common-ts/ .
RUN bun install --production && bun run build
WORKDIR /app
COPY . .
# no '--production' for esbuild
RUN bun install && bun esbuild.config.js
FROM node:20.18.1-alpine
# 'bigint-buffer' native lib for performance
# @triton-one/yellowstone-grpc so .wasm lib included
RUN apk add python3 make g++ --virtual .build &&\
npm install -C /lib bigint-buffer @triton-one/yellowstone-grpc &&\
apk del .build
COPY --from=builder /app/lib/ ./lib/
ENV NODE_ENV=production
EXPOSE 9464
CMD ["node", "./lib/index.js"]