# Use the official Node.js image as the base image
FROM node:20 AS build
# Set the working directory in the container
WORKDIR /app

# Copy the package.json and package-lock.json (or yarn.lock) files
COPY package*.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the Vue.js application
RUN npm run build:embed-docker
RUN npm run build:docker

# Use Nginx to serve the application
FROM nginx:stable-alpine

# Copy the build output from the previous stage to Nginx's HTML directory
COPY --from=build /app/dist /usr/share/nginx/html
COPY /deploy/nginx.conf /etc/nginx/nginx.conf

# Copy the entrypoint script
COPY /deploy/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Set the entrypoint to the shell script
ENTRYPOINT ["/entrypoint.sh"]

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