# docker build -t ola-ui .
# docker run --rm -p 8080:80 --name ola-ui ola-ui

FROM node:14-bullseye AS build

WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci --unsafe-perm --before=2025-09-01 --ignore-scripts

# Copy the source code.
COPY . .

# Run scripts skipped during npm ci (generates src/environments/version.ts).
RUN npm run postinstall

# Build the production bundle. Using npx avoids platform-specific npm script wrappers.
# Note: base-href/deploy-url set for hosting under /loanapp.
RUN npx ng build \
      --base-href="/loanapp/" \
      --deploy-url="/loanapp/"

FROM nginx:1.25-alpine AS runtime

COPY docker/nginx.conf /tmp/default.conf
RUN rm -f /etc/nginx/conf.d/default.conf && \
    mv /tmp/default.conf /etc/nginx/conf.d/default.conf

COPY --from=build /app/dist/ui /usr/share/nginx/html

EXPOSE 80

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