# syntax=docker/dockerfile:1

FROM oven/bun:1.3.12 AS base
WORKDIR /app
ENV CI=1

COPY package.json bun.lock turbo.json tsconfig.json bts.jsonc ./
COPY apps ./apps
COPY packages ./packages

FROM base AS deps
RUN bun install --frozen-lockfile

FROM deps AS tools
ENV NODE_ENV=development
RUN touch apps/server/.env

FROM deps AS build
ENV NODE_ENV=production
RUN bun run --filter server build

FROM base AS prod-deps
RUN bun install --frozen-lockfile --production

FROM oven/bun:1.3.12 AS runtime
WORKDIR /app
ENV NODE_ENV=production

COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/apps/server/dist ./apps/server/dist

EXPOSE 3000
CMD ["bun", "apps/server/dist/index.mjs"]
