forked from stellar-kracken/swipely_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (47 loc) · 2.13 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (47 loc) · 2.13 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
54
55
56
57
58
59
# =============================================================================
# Bridge Watch — Backend Dockerfile
# =============================================================================
# Stages:
# base shared dependencies
# dev hot reload with tsx watch (docker-compose.dev.yml)
# builder compiles TypeScript
# production minimal production image (docker-compose.yml)
FROM node:20-alpine AS base
WORKDIR /app
# Install dependencies first (layer cache friendly). This layer is only
# invalidated when package.json changes, not on every source edit. The
# BuildKit cache mount keeps npm's package cache across builds so even an
# invalidated install re-downloads as little as possible.
COPY package.json ./
RUN --mount=type=cache,sharing=locked,target=/root/.npm npm install
# -----------------------------------------------------------------------------
# Development — live reload via tsx watch
# -----------------------------------------------------------------------------
FROM base AS dev
COPY tsconfig.json ./
# Source is mounted as a volume at runtime, no COPY needed
EXPOSE 3001 3002
CMD ["npm", "run", "dev"]
# -----------------------------------------------------------------------------
# Builder — compile TypeScript to dist/
# -----------------------------------------------------------------------------
FROM base AS builder
COPY tsconfig.json ./
COPY src ./src
RUN npm run build
# -----------------------------------------------------------------------------
# Production — lean image with only compiled output
# -----------------------------------------------------------------------------
FROM node:20-alpine AS production
WORKDIR /app
ENV NODE_ENV=production
COPY package.json ./
RUN --mount=type=cache,sharing=locked,target=/root/.npm npm install --omit=dev && npm cache clean --force || true
COPY --from=builder /app/dist ./dist
# Non-root user for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
EXPOSE 3001 3002
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD wget -qO- http://localhost:3001/health || exit 1
CMD ["node", "dist/index.js"]