FROM php:8.3-cli-alpine

LABEL maintainer="Security Linter Team"
LABEL description="PHP/Laravel Security Linter - Static security analysis tool"
LABEL version="0.0.1"

# Build arguments
ARG PHP_MEMORY_LIMIT=1024M

# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /app/security-linter

# Copy composer files first for better caching
COPY composer.json composer.lock* ./

# Install dependencies
RUN composer install --no-dev --optimize-autoloader --no-interaction --no-progress

# Copy source code
COPY src/ ./src/
COPY bin/ ./bin/
COPY docs/ ./docs/

# Make binary executable, set memory limit, and create symlink
RUN chmod +x bin/security-lint \
    && echo "memory_limit=${PHP_MEMORY_LIMIT}" > /usr/local/etc/php/conf.d/memory.ini \
    && ln -s /app/security-linter/bin/security-lint /usr/local/bin/security-lint

# Default working directory for target code
WORKDIR /target

# Set entrypoint
ENTRYPOINT ["security-lint"]

# Default command (show help)
CMD ["--help"]
