Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (37 loc) · 1.57 KB
/
Copy pathDockerfile
File metadata and controls
53 lines (37 loc) · 1.57 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
FROM node:lts-alpine AS base
WORKDIR /app
FROM base AS builder
RUN npm install -g pnpm@latest
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml /app/
RUN pnpm install --frozen-lockfile
COPY . /app
RUN <<EOF
set -eu
BANNER='
const { dirname: __dirname, filename: __filename } = import.meta;
const require = (() => {
const r = process.getBuiltinModule("module").createRequire(import.meta.url);
return (name) => { try { return r(name) } catch { return {default:{}}; } }
})();
'
pnpm build:server
pnpm esbuild --bundle dist/server/main.js --outfile=main.mjs \
--platform=node --format=esm --target=node24 --charset=utf8 \
--minify --keep-names --sourcemap --legal-comments=external \
--banner:js="$BANNER" \
--external:@fastify/view --external:@fastify/multipart --external:@nestjs/websockets --external:@nestjs/microservices --external:@nestjs/platform-express \
--external:class-transformer/storage --external:libphonenumber-js
# Swagger resolves its UI assets at runtime via createRequire.
node --input-type=module -e '
import { cpSync } from "node:fs";
import { createRequire } from "node:module";
const require = createRequire(import.meta.resolve("@nestjs/swagger"));
cpSync(require("swagger-ui-dist/absolute-path.js")(), "/runtime/node_modules/swagger-ui-dist", { recursive: true });
'
rm -rf .[!.]* dist node_modules src test tools scripts
EOF
FROM base AS production
RUN apk add --no-cache git
COPY --from=builder /app /app
COPY --from=builder /runtime/node_modules /app/node_modules
ENTRYPOINT [ "node", "main.mjs" ]