FROM node:22-slim AS builder

# Install git and other dependencies
RUN apt-get update && apt-get install -y git ca-certificates && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app
COPY package.json .
COPY package-lock.json* .
COPY quartz/ ./quartz/
COPY quartz.lock.json .
RUN npm ci && npx quartz plugin install

FROM node:22-slim
WORKDIR /usr/src/app

# Install git and ca-certificates for vault repo access
RUN apt-get update && apt-get install -y git ca-certificates && rm -rf /var/lib/apt/lists/*

COPY --from=builder /usr/src/app/ /usr/src/app/
COPY . .

# Copy and make entrypoint executable
COPY entrypoint.sh /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh

ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

