# Frontend Dockerfile
# Stage 1: Build the frontend
FROM node:20 AS builder

WORKDIR /app
COPY . .
RUN npm install
RUN npm run build

# Stage 2: Serve with nginx
FROM nginx:alpine

# Install dos2unix
RUN apk add --no-cache dos2unix

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

# ✅ Copy env.js.template
COPY public/env.js.template /etc/env/env.js.template

# ✅ Copy nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf

# ✅ Add env generator script to nginx entrypoint hook
COPY 10-generate-env.sh /docker-entrypoint.d/10-generate-env.sh
RUN dos2unix /docker-entrypoint.d/10-generate-env.sh && chmod +x /docker-entrypoint.d/10-generate-env.sh

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

