Skip to content

Commit 780a51a

Browse files
committed
made api file production optimized
1 parent 2556b39 commit 780a51a

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

Dockerfile

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM oven/bun:1.3 AS base
2-
WORKDIR /app
2+
WORKDIR /var/www/api
33

44
# -----------------------------
55
# deps stage - cache dependencies
@@ -17,15 +17,7 @@ RUN bunx prisma generate
1717
FROM deps AS build
1818

1919
COPY . .
20-
RUN bun build src/server.ts --outdir dist
21-
22-
# -----------------------------
23-
# prod deps stage - install only production dependencies
24-
# -----------------------------
25-
FROM base AS prod-deps
26-
27-
COPY package.json bun.lock* ./
28-
RUN bun install --production --frozen-lockfile
20+
RUN bun build src/server.ts --target=bun --production --outdir dist
2921

3022
# -----------------------------
3123
# development stage
@@ -40,13 +32,16 @@ CMD ["bun", "src/server.ts"]
4032
# -----------------------------
4133

4234

43-
FROM prod-deps AS production
35+
FROM oven/bun:1-slim AS production
36+
37+
WORKDIR /var/www/api
38+
RUN groupadd -g 1001 nodejs && useradd -u 1001 -g nodejs -m bunjs
4439

45-
RUN addgroup -g 1001 -S nodejs && adduser -S bunjs -u 1001
40+
COPY --from=build --chown=bunjs:nodejs /var/www/api/dist ./dist
41+
COPY --from=deps --chown=bunjs:nodejs /var/www/api/src/generated ./dist/generated
4642

47-
COPY --from=deps --chown=bunjs:nodejs /app/src/generated ./src/generated
48-
COPY --from=build --chown=bunjs:nodejs /app/dist ./dist
4943

44+
RUN chown -R bunjs:nodejs /var/www/api
5045
USER bunjs
5146

5247
ENV NODE_ENV=production
@@ -57,4 +52,4 @@ EXPOSE 3000
5752
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
5853
CMD wget -qO- http://localhost:3000/health || exit 1
5954

60-
CMD ["bun", "dist/server.js"]
55+
CMD ["bun", "./dist/server.js"]

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ services:
1616
volumes:
1717
- ./:/app:cached
1818
- /app/node_modules
19-
command: ["bun", "src/server.ts"]
2019
depends_on:
2120
- db
2221
healthcheck:

0 commit comments

Comments
 (0)