# Stage 1: Build the Vue application
FROM node:20-alpine AS builder

# Set the working directory inside the container
WORKDIR /app

ARG VITE_API_BASE_URL
ARG VITE_OSRM_BASE_URL

# Make them available as environment variables during build
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
ENV VITE_OSRM_BASE_URL=$VITE_OSRM_BASE_URL

# Copy package.json and package-lock.json (if it exists)
# to leverage Docker cache for dependencies
COPY package.json package-lock.json* ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the Vue application for production
RUN npm run build

# Stage 2: Serve the application with Nginx
FROM nginx:alpine

# Copy the built application from the builder stage to Nginx's default public directory
COPY --from=builder /app/dist /usr/share/nginx/html

# Expose port 80, which is the default for Nginx
EXPOSE 80

# Command to run Nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]
