Skip to content

Commit 9f85765

Browse files
authored
Chore/shrink docker image (#28)
* shrink docker image (esbuild + multistage docker build)
1 parent 8eec5cc commit 9f85765

File tree

4 files changed

+49
-22
lines changed

4 files changed

+49
-22
lines changed

Dockerfile

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
FROM public.ecr.aws/bitnami/node:18
2-
RUN apt-get install git
3-
ENV NODE_ENV=production
4-
RUN npm install -g typescript
1+
FROM node:18 AS builder
52

63
WORKDIR /app
7-
COPY . .
4+
5+
# Install build dependencies
6+
RUN apt update -y && apt install git build-essential make python3 -y
7+
# Copy package files first to leverage cache
8+
COPY package.json yarn.lock ./
9+
COPY drift-common/protocol/sdk/package.json ./drift-common/protocol/sdk/
10+
COPY drift-common/common-ts/package.json ./drift-common/common-ts/
11+
12+
ENV NODE_ENV=production
13+
814
WORKDIR /app/drift-common/protocol/sdk
9-
RUN yarn
10-
RUN yarn build
15+
COPY drift-common/protocol/sdk/ .
16+
RUN yarn && yarn build
17+
1118
WORKDIR /app/drift-common/common-ts
12-
RUN yarn
13-
RUN yarn build
19+
COPY drift-common/common-ts/ .
20+
RUN yarn && yarn build
21+
1422
WORKDIR /app
15-
RUN yarn
16-
RUN yarn build
23+
COPY . .
24+
RUN yarn && yarn build
1725

26+
FROM node:18-alpine
27+
COPY --from=builder /app/dist/ ./lib/
28+
29+
ENV NODE_ENV=production
1830
EXPOSE 9464
1931

20-
CMD [ "yarn", "start" ]
32+
CMD ["node", "./lib/index.js"]

esbuild.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const esbuild = require('esbuild');
2+
3+
const commonConfig = {
4+
bundle: true,
5+
platform: 'node',
6+
target: 'node18',
7+
sourcemap: true,
8+
// minify: true, makes messy debug/error output
9+
treeShaking: true,
10+
legalComments: 'none',
11+
mainFields: ['module', 'main'],
12+
metafile: true,
13+
format: 'cjs'
14+
};
15+
16+
esbuild.build({
17+
...commonConfig,
18+
entryPoints: ['src/index.ts', 'src/wsConnectionManager.ts'],
19+
outdir: 'dist',
20+
}).catch(() => process.exit(1));

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,26 @@
2121
"start": "ts-node src/index.ts",
2222
"ws-manager": "ts-node src/wsConnectionManager.ts",
2323
"playground": "ts-node src/playground.ts",
24-
"build": "yarn clean && tsc",
24+
"build": "yarn clean && node esbuild.config.js",
2525
"clean": "rm -rf lib",
2626
"prettify": "prettier --check './src/**/*.ts'",
27-
"prettify:fix": "prettier --write './src/**/*.ts'"
27+
"prettify:fix": "prettier --write './src/**/*.ts'"
2828
},
2929
"dependencies": {
3030
"@aws-sdk/client-ssm": "^3.535.0",
3131
"@aws-sdk/credential-provider-node": "^3.535.0",
3232
"@coral-xyz/anchor": "^0.29.0",
33-
"@drift-labs/sdk": "file:./drift-common/protocol/sdk",
33+
"@drift-labs/sdk": "file:./drift-common/protocol/sdk",
3434
"@drift/common": "file:./drift-common/common-ts",
35-
"@grpc/grpc-js": "^1.8.0",
35+
"@grpc/grpc-js": "^1.8.0",
3636
"@triton-one/yellowstone-grpc": "0.6.0",
3737
"buffer": "^6.0.3",
3838
"compression": "^1.7.4",
3939
"cors": "^2.8.5",
4040
"dotenv": "^16.4.5",
41+
"esbuild": "^0.20.1",
4142
"express": "^4.19.1",
42-
"ioredis": "^5.3.2",
4343
"prom-client": "^15.1.0",
44-
"rxjs": "^7.8.1",
4544
"ws": "^8.16.0"
4645
}
4746
}

src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ import {
88
DriftEnv,
99
EventType,
1010
ResubOpts,
11-
SwiftOrderRecord,
1211
Wallet,
1312
} from "@drift-labs/sdk";
1413
import { ClientDuplexStream } from "@grpc/grpc-js";
1514
import { Connection, Keypair } from "@solana/web3.js";
16-
import { fromEventPattern } from "rxjs";
1715
import { parseLogsWithRaw } from "@drift-labs/sdk";
18-
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"; // ES Modules import
19-
import Redis from "ioredis";
2016
import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
2117
import { getSerializerFromEventType } from "./utils/utils";
2218
import { RedisClient } from "@drift/common/clients";

0 commit comments

Comments
 (0)