FROM node:18-alpine

WORKDIR /app

# Setup build args clearly
ARG VITE_OPENAPI_BASE_DEV
ARG VITE_SSL_KEY_PATH
ARG VITE_SSL_CERT_PATH
ARG NODE_ENV=development

ENV VITE_OPENAPI_BASE=${VITE_OPENAPI_BASE}
ENV VITE_SSL_KEY_PATH=${VITE_SSL_KEY_PATH}
ENV VITE_SSL_CERT_PATH=${VITE_SSL_CERT_PATH}
ENV NODE_ENV=${NODE_ENV}

# Copy only the necessary package files first
COPY package*.json ./
RUN npm install

# Copy OpenAPI models into the build context
COPY openapi ./openapi

# Copy the rest of the logistics app files
COPY . .

# Build the application
RUN npm run build

# Use a simple HTTP server to serve the built static files
EXPOSE 3000

CMD ["npm", "run", "start-dev"]