# Build Stage
FROM node:20-alpine AS builder

WORKDIR /usr/src/app

COPY package*.json ./
COPY tsconfig.json ./
COPY src ./src

# Install ALL dependencies (including dev for building)
RUN npm install

# Build the project
RUN npm run build

# Production Stage (Clean image)
FROM node:20-alpine

WORKDIR /usr/src/app

COPY package*.json ./

# Install ONLY production dependencies
RUN npm ci --omit=dev

# Copy built files from builder
COPY --from=builder /usr/src/app/dist ./dist

# Copy the injection script
COPY copy-agent.sh .
RUN chmod +x copy-agent.sh

# Default command: copy files to the mounted volume
CMD ["./copy-agent.sh", "/elven-instrumentation"]
