Skip to content

Commit

Permalink
Chore/shrink docker image (#28)
Browse files Browse the repository at this point in the history
* shrink docker image (esbuild + multistage docker build)
  • Loading branch information
jordy25519 authored Dec 11, 2024
1 parent 8eec5cc commit 9f85765
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
36 changes: 24 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
FROM public.ecr.aws/bitnami/node:18
RUN apt-get install git
ENV NODE_ENV=production
RUN npm install -g typescript
FROM node:18 AS builder

WORKDIR /app
COPY . .

# Install build dependencies
RUN apt update -y && apt install git build-essential make python3 -y
# 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/

ENV NODE_ENV=production

WORKDIR /app/drift-common/protocol/sdk
RUN yarn
RUN yarn build
COPY drift-common/protocol/sdk/ .
RUN yarn && yarn build

WORKDIR /app/drift-common/common-ts
RUN yarn
RUN yarn build
COPY drift-common/common-ts/ .
RUN yarn && yarn build

WORKDIR /app
RUN yarn
RUN yarn build
COPY . .
RUN yarn && yarn build

FROM node:18-alpine
COPY --from=builder /app/dist/ ./lib/

ENV NODE_ENV=production
EXPOSE 9464

CMD [ "yarn", "start" ]
CMD ["node", "./lib/index.js"]
20 changes: 20 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const esbuild = require('esbuild');

const commonConfig = {
bundle: true,
platform: 'node',
target: 'node18',
sourcemap: true,
// minify: true, makes messy debug/error output
treeShaking: true,
legalComments: 'none',
mainFields: ['module', 'main'],
metafile: true,
format: 'cjs'
};

esbuild.build({
...commonConfig,
entryPoints: ['src/index.ts', 'src/wsConnectionManager.ts'],
outdir: 'dist',
}).catch(() => process.exit(1));
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@
"start": "ts-node src/index.ts",
"ws-manager": "ts-node src/wsConnectionManager.ts",
"playground": "ts-node src/playground.ts",
"build": "yarn clean && tsc",
"build": "yarn clean && node esbuild.config.js",
"clean": "rm -rf lib",
"prettify": "prettier --check './src/**/*.ts'",
"prettify:fix": "prettier --write './src/**/*.ts'"
"prettify:fix": "prettier --write './src/**/*.ts'"
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.535.0",
"@aws-sdk/credential-provider-node": "^3.535.0",
"@coral-xyz/anchor": "^0.29.0",
"@drift-labs/sdk": "file:./drift-common/protocol/sdk",
"@drift-labs/sdk": "file:./drift-common/protocol/sdk",
"@drift/common": "file:./drift-common/common-ts",
"@grpc/grpc-js": "^1.8.0",
"@grpc/grpc-js": "^1.8.0",
"@triton-one/yellowstone-grpc": "0.6.0",
"buffer": "^6.0.3",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"esbuild": "^0.20.1",
"express": "^4.19.1",
"ioredis": "^5.3.2",
"prom-client": "^15.1.0",
"rxjs": "^7.8.1",
"ws": "^8.16.0"
}
}
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import {
DriftEnv,
EventType,
ResubOpts,
SwiftOrderRecord,
Wallet,
} from "@drift-labs/sdk";
import { ClientDuplexStream } from "@grpc/grpc-js";
import { Connection, Keypair } from "@solana/web3.js";
import { fromEventPattern } from "rxjs";
import { parseLogsWithRaw } from "@drift-labs/sdk";
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"; // ES Modules import
import Redis from "ioredis";
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
import { getSerializerFromEventType } from "./utils/utils";
import { RedisClient } from "@drift/common/clients";
Expand Down

0 comments on commit 9f85765

Please sign in to comment.