FROM node:23 AS builder

# Set the working directory
WORKDIR /app

ARG VITE_API_URL

# Copy package.json and yarn.lock first to leverage Docker's cache
COPY . ./

RUN corepack enable && corepack prepare yarn@4.5.1 --activate

# Install Yarn and the specified version
RUN yarn install

# Manually copy psdfkit
RUN cp -R ./node_modules/pspdfkit/dist/pspdfkit-lib public/pspdfkit-lib

RUN yarn build

FROM registry.gitlab.com/ademe-group/docker-base-images/httpd-images/httpd:apache-alpine3.19 AS RUN

RUN set -x \
   && apk update \
   && apk upgrade

COPY --from=builder /app/dist /var/www/html
COPY --from=builder /app/.htaccess /var/www/html