# gibbz voice — Bun runtime, Vite-built TypeScript client
ARG APP_RELEASE=dev

FROM oven/bun:1 AS build
WORKDIR /app

COPY package.json bun.lock* ./
RUN bun install

COPY tsconfig.json vite.config.ts ./
COPY src ./src
COPY public ./public

# Inject build release into index.html if APP_RELEASE is specified
ARG APP_RELEASE
ENV APP_RELEASE=${APP_RELEASE}
RUN if [ -n "${APP_RELEASE}" ]; then \
      sed -i "s/window.__APP_RELEASE__ || \"dev\"/\"${APP_RELEASE}\"/g" ./src/client/index.html; \
    fi

RUN bun run build && bun install --production

FROM oven/bun:1
WORKDIR /app

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/src/server ./src/server

ENV PORT=8080 \
    HOST=0.0.0.0

EXPOSE 8080

USER bun

CMD ["bun", "src/server/index.ts"]
