2026-07-02 04:07:18 +07:00
|
|
|
FROM node:22-slim
|
2026-06-01 21:44:29 +07:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2026-07-27 21:54:31 +07:00
|
|
|
# Build args for frontend API URLs
|
|
|
|
|
ARG VITE_BE_API_URL
|
|
|
|
|
ARG VITE_BE_WS_URL
|
|
|
|
|
ENV VITE_BE_API_URL=${VITE_BE_API_URL}
|
|
|
|
|
ENV VITE_BE_WS_URL=${VITE_BE_WS_URL}
|
|
|
|
|
|
2026-06-01 21:44:29 +07:00
|
|
|
# Install pnpm
|
|
|
|
|
RUN npm install -g pnpm
|
|
|
|
|
|
2026-06-11 03:58:47 +07:00
|
|
|
# Install build tools for native dependencies (node-crc, @discordjs/opus)
|
2026-07-02 04:07:18 +07:00
|
|
|
RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends python3 make g++ wget && rm -rf /var/lib/apt/lists/*
|
2026-06-11 03:58:47 +07:00
|
|
|
|
2026-06-08 17:51:29 +07:00
|
|
|
# Create non-root user
|
2026-07-02 04:07:18 +07:00
|
|
|
RUN groupadd --system app && useradd --system -g app app
|
2026-06-08 17:51:29 +07:00
|
|
|
|
2026-06-09 22:04:05 +07:00
|
|
|
# Copy dependency definition files first for better caching
|
2026-06-01 21:44:29 +07:00
|
|
|
COPY pnpm-workspace.yaml .
|
|
|
|
|
COPY pnpm-lock.yaml .
|
|
|
|
|
COPY package.json .
|
|
|
|
|
|
2026-06-02 23:31:12 +07:00
|
|
|
# Copy patches (pnpm patchedDependencies)
|
|
|
|
|
COPY patches ./patches
|
|
|
|
|
|
2026-06-08 17:51:29 +07:00
|
|
|
# Copy packages (workspace dependencies)
|
|
|
|
|
COPY packages/shared ./packages/shared
|
|
|
|
|
|
2026-06-01 22:47:47 +07:00
|
|
|
# Copy service
|
2026-06-01 21:44:29 +07:00
|
|
|
COPY services/backend ./services/backend
|
|
|
|
|
|
2026-06-09 22:04:05 +07:00
|
|
|
# Install dependencies with build cache
|
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm install --frozen-lockfile
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-06-02 23:38:07 +07:00
|
|
|
# Build shared workspace dependency first
|
2026-06-09 22:04:05 +07:00
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm --filter './packages/shared' run build
|
2026-06-02 23:38:07 +07:00
|
|
|
|
2026-06-01 21:44:29 +07:00
|
|
|
# Build backend
|
2026-06-09 22:04:05 +07:00
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
|
|
|
|
pnpm --filter './services/backend' run build
|
2026-06-01 21:44:29 +07:00
|
|
|
|
2026-06-08 17:51:29 +07:00
|
|
|
# Own dist + node_modules by non-root user
|
|
|
|
|
RUN chown -R app:app /app
|
|
|
|
|
|
|
|
|
|
# Switch to non-root user
|
|
|
|
|
USER app
|
|
|
|
|
|
2026-06-01 21:44:29 +07:00
|
|
|
# Expose port
|
2026-06-08 17:51:29 +07:00
|
|
|
EXPOSE 3000
|
|
|
|
|
|
|
|
|
|
# Healthcheck — backend serves HTTP on port 3000
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
|
|
|
|
|
CMD wget -qO- http://localhost:3000/api/health || exit 1
|
2026-06-01 21:44:29 +07:00
|
|
|
|
|
|
|
|
# Start backend
|
2026-06-01 22:42:45 +07:00
|
|
|
CMD ["node", "services/backend/dist/index.js"]
|