# FastLED AVR8JS Docker Image
# Minimal Alpine-based image for running Arduino Uno firmware in avr8js simulator
# Target size: ~50-60MB

FROM node:20-alpine

LABEL maintainer="FastLED Project"
LABEL description="AVR8JS Arduino simulator for FastLED testing"
LABEL version="1.0"

# Set working directory
WORKDIR /app

# Copy package.json for avr8js installation
# This layer is cached unless package.json changes
COPY ci/docker_utils/avr8js/package.json /app/package.json

# Install git (required for npm to install from GitHub) and dependencies
RUN apk add --no-cache git && \
    npm install && \
    npm cache clean --force && \
    apk del git && \
    rm -rf /root/.npm /tmp/*

# Copy TypeScript source files
COPY ci/docker_utils/avr8js/*.ts /app/

# Entrypoint: run the simulator using tsx
# Usage: docker run <image> <firmware.hex> [timeout]
ENTRYPOINT ["npx", "tsx", "/app/main.ts"]

# Default: show help
CMD ["--help"]

# Health check (optional, for debugging)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=1 \
  CMD node --version || exit 1
