# Use the official Node.js 22 LTS image.
FROM node:22-alpine AS base

# Set the working directory in the container.
WORKDIR /app

# Install git.
RUN apk add --no-cache git

# Set build arguments for token and username
ARG GIT_ACCESS_TOKEN
ARG GIT_USERNAME

# Set environment variables (optional, for use in RUN)
ENV GIT_ACCESS_TOKEN=${GIT_ACCESS_TOKEN}
ENV GIT_USERNAME=${GIT_USERNAME}

# Clone the repository.
# IMPORTANT: Replace with your actual repository URL.
RUN git clone https://${GIT_USERNAME}:${GIT_ACCESS_TOKEN}@git.haider.app/tizian/quarry-party-landing-page-react.git .

# Install dependencies.
RUN npm install

# Build the Next.js application.
RUN npm run build

# Create a non-root user to run the application.
RUN addgroup -S nextjs && adduser -S nextjs -G nextjs
USER nextjs

# Expose the port the app runs on.
EXPOSE 8150

# Set the command to start the application.
CMD ["npm", "start", "--", "-p", "8150"]
