# Stage 1: Dependencies
FROM node:22-alpine AS deps

WORKDIR /app

# Copy package files
COPY package.json package-lock.json* ./

# Install dependencies
RUN npm ci

# Stage 2: Development
FROM node:22-alpine AS development

WORKDIR /app

# Install tools for healthcheck and port checking
RUN apk add --no-cache wget curl netcat-openbsd

# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules

# Copy source code
COPY . .

# Make entrypoint script executable
RUN chmod +x /app/docker-entrypoint.sh

# Expose Hardhat node port
EXPOSE 8545

# Start with entrypoint script
ENTRYPOINT ["/app/docker-entrypoint.sh"]
