# Stage 1: Build the Angular application
FROM node:18.19.1-alpine AS build

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to install dependencies
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application files
COPY . .

ARG API_URL
ARG TMDB_API_KEY
RUN sed -i "s|%%API_URL%%|${API_URL}|g" src/environments/environment.prod.ts
RUN sed -i "s|%%TMDB_API_KEY%%|${TMDB_API_KEY}|g" /src/environments/environment.prod.ts

# Build the Angular app with a custom base-href
RUN npm run electron-build:ng

# Stage 2: Serve the Angular app with a lightweight web server
FROM nginx:alpine

# Copy the built Angular app from the build stage
COPY --from=build /app/dist/showy/browser /usr/share/nginx/html

# Copy a custom Nginx configuration (optional, if needed)
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose the default Nginx HTTP port
EXPOSE 80

# Start the Nginx server
CMD ["nginx", "-g", "daemon off;"]
