# ---------- 1️⃣ Build Stage ----------
FROM oven/bun:1 AS builder

WORKDIR /app

# Build arguments
ARG VITE_SPOTIFY_CLIENT_ID
ARG VITE_REDIRECT_URI

# Copy package files first (better layer caching)
COPY package.json bun.lockb* ./

RUN bun install

# Copy the rest of the app
COPY . .

# Build the Vite app
RUN bun run build


# ---------- 2️⃣ Production Stage ----------
FROM nginx:alpine

# Remove default nginx config
RUN rm -rf /usr/share/nginx/html/*

# Copy built files
COPY --from=builder /app/dist /usr/share/nginx/html

# Copy custom nginx config (for SPA routing)
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
