Skip to content

Commit

Permalink
Chore/esbuildify again (#323)
Browse files Browse the repository at this point in the history
* esbuild again
* Use distroless image
  • Loading branch information
jordy25519 authored Dec 18, 2024
1 parent b129bfe commit a6b9867
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 101 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/**/node_modules/
lib/
.husky/
node_modules/
27 changes: 19 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
FROM public.ecr.aws/bitnami/node:20.18.1
RUN apt-get install git
ENV NODE_ENV=production
RUN npm install -g typescript
FROM public.ecr.aws/docker/library/node:20 AS builder

RUN npm install -g typescript bun

WORKDIR /app
COPY drift-common /app/drift-common
COPY . .
WORKDIR /app/drift-common/protocol/sdk
RUN yarn
RUN bun install
RUN yarn build
WORKDIR /app/drift-common/common-ts
RUN yarn
RUN bun install
RUN yarn build
WORKDIR /app
RUN yarn
RUN yarn build
RUN bun install
RUN node esbuild.config.js --minify-whitespace

FROM public.ecr.aws/docker/library/node:20 AS modules
WORKDIR /app
# 'bigint-buffer' native lib for performance
# @triton-one/yellowstone-grpc so .wasm lib included
RUN apt update && apt install -y build-essential python3
RUN npm install -C lib bigint-buffer @triton-one/yellowstone-grpc

FROM gcr.io/distroless/nodejs20-debian12
COPY --from=builder /app/lib/ ./lib/
COPY --from=modules /app/lib/node_modules/ ./lib/node_modules/

ENV NODE_ENV=production
EXPOSE 9464
27 changes: 27 additions & 0 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const esbuild = require('esbuild');
const glob = require('tiny-glob');

const commonConfig = {
bundle: true,
platform: 'node',
target: 'node20',
sourcemap: false,
minify: false, // makes messy debug/error output
treeShaking: true,
legalComments: 'none',
metafile: true,
format: 'cjs',
external: [
'bigint-buffer',
'@triton-one/yellowstone-grpc'
]
};

(async () => {
let entryPoints = await glob("./src/**/*.ts");
await esbuild.build({
...commonConfig,
entryPoints,
outdir: 'lib',
});
})().catch(() => process.exit(1));
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"license": "Apache-2.0",
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@drift/common": "file:./drift-common/common-ts",
"@drift-labs/sdk": "file:./drift-common/protocol/sdk",
"@drift/common": "file:./drift-common/common-ts",
"@opentelemetry/api": "^1.1.0",
"@opentelemetry/auto-instrumentations-node": "^0.31.1",
"@opentelemetry/exporter-prometheus": "^0.31.0",
Expand Down Expand Up @@ -42,12 +42,14 @@
"@types/k6": "^0.45.0",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"esbuild": "^0.24.0",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"husky": "^7.0.4",
"k6": "^0.0.0",
"prettier": "^2.4.1",
"tiny-glob": "^0.2.9",
"ts-node": "^10.9.1"
},
"scripts": {
Expand Down
Loading

0 comments on commit a6b9867

Please sign in to comment.