FROM oven/bun:latest AS base

WORKDIR /app

# Install dependencies
COPY package.json bun.lock ./
COPY patches ./patches
RUN bun install --frozen-lockfile

# Build the SvelteKit app with adapter-node
COPY . .

ARG PUBLIC_API_URL=https://opt-api.osdci.net
ENV PUBLIC_API_URL=$PUBLIC_API_URL

RUN bun run build:server

# Production image
FROM node:22-alpine AS production

WORKDIR /app

COPY --from=base /app/build ./build
COPY --from=base /app/package.json ./

ENV NODE_ENV=production
ENV PORT=3000
ENV ORIGIN=https://optima.osdci.net

EXPOSE 3000

CMD ["node", "build/index.js"]
