# Stage 1 - Define Base image
FROM node:22-alpine AS base

# Stage 2 Install dependencies
FROM base AS install-deps
# Set working directory inside the build container
WORKDIR /app
COPY package*.json /app/
RUN yarn

FROM install-deps AS develop
WORKDIR /app
COPY . .

# Broken, why?
#ENTRYPOINT ["yarn", "dev"]
ENTRYPOINT ["yarn", "dev", "--host=0.0.0.0"]
EXPOSE 5173

FROM base AS build
WORKDIR /app
COPY package*.json /app/
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

FROM nginx:alpine AS production
RUN apk add curl && \
    rm -rf /var/cache/apk/*

COPY --from=build /app/dist /usr/share/nginx/html/
EXPOSE 80
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]
HEALTHCHECK --interval=5s \
    --timeout=5s \
    --start-period=5s \
    --retries=3 \
    CMD "/usr/bin/curl localhost" || exit 1
