FROM ubuntu:22.04

# Set environment variables
ENV FLUTTER_HOME=/opt/flutter
ENV PATH="$FLUTTER_HOME/bin:$PATH"
ENV PUB_CACHE=/opt/pub-cache

# Install system dependencies including Node.js
# Nodejs is required for the forgejo runner (checkout action)
RUN apt-get update && apt-get install -y \
    curl \
    git \
    wget \
    unzip \
    ca-certificates \
    gnupg \
    && mkdir -p /etc/apt/keyrings \
    && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
    && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
    && apt-get update \
    && apt-get install -y nodejs \
    && rm -rf /var/lib/apt/lists/*

# Install Flutter
RUN git clone https://github.com/flutter/flutter.git $FLUTTER_HOME \
    && flutter doctor \
    && flutter channel stable \
    && flutter upgrade \
    && flutter config --enable-web \
    && flutter precache --web

# Create cache directories
RUN mkdir -p $PUB_CACHE

WORKDIR /workspace
