diff --git a/Dockerfile.standalone b/Dockerfile.standalone index cbd723f9..d75960c2 100644 --- a/Dockerfile.standalone +++ b/Dockerfile.standalone @@ -5,6 +5,8 @@ # The COPY always runs; the RUN only downloads missing files. FROM ubuntu:22.04 AS qemu-provider +ARG ENABLE_ESP32=0 + RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates \ && rm -rf /var/lib/apt/lists/* @@ -15,44 +17,50 @@ RUN mkdir -p /qemu COPY prebuilt/qemu/ /qemu/ # Download any missing files from GitHub Release -RUN cd /qemu \ - && for f in libqemu-xtensa.so libqemu-riscv32.so esp32-v3-rom.bin esp32-v3-rom-app.bin esp32c3-rom.bin; do \ - if [ ! -f "$f" ]; then \ - echo "Downloading $f from release..." ; \ - curl -fSL -o "$f" "${QEMU_RELEASE_URL}/$f" ; \ - else \ - echo "Using local $f ($(stat -c%s "$f") bytes)" ; \ - fi ; \ - done \ - && ls -lh /qemu/ +RUN if [ "$ENABLE_ESP32" = "1" ]; then \ + cd /qemu \ + && for f in libqemu-xtensa.so libqemu-riscv32.so esp32-v3-rom.bin esp32-v3-rom-app.bin esp32c3-rom.bin; do \ + if [ ! -f "$f" ]; then \ + echo "Downloading $f from release..." ; \ + curl -fSL -o "$f" "${QEMU_RELEASE_URL}/$f" ; \ + else \ + echo "Using local $f ($(stat -c%s "$f") bytes)" ; \ + fi ; \ + done \ + && ls -lh /qemu/ ; \ + else \ + echo "ESP32 support disabled. Skipping QEMU downloads." ; \ + fi # ---- Stage 0.5: ESP-IDF toolchain for ESP32 compilation ---- -FROM debian:bookworm-slim AS espidf-builder +FROM ubuntu:22.04 AS espidf-builder -RUN apt-get update && apt-get install -y --no-install-recommends \ +ARG ENABLE_ESP32=0 + +# Create empty directories to ensure COPY works later even if ESP32 is disabled +RUN mkdir -p /opt/esp-idf /root/.espressif /opt/arduino-esp32 + +RUN if [ "$ENABLE_ESP32" = "1" ]; then \ + apt-get update && apt-get install -y --no-install-recommends \ git wget flex bison gperf python3 python3-pip python3-venv \ cmake ninja-build ccache libffi-dev libssl-dev \ libusb-1.0-0 ca-certificates \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* ; \ + fi # Install ESP-IDF 4.4.7 (matches Arduino ESP32 core 2.0.17 / lcgamboa QEMU ROM) -RUN git clone -b v4.4.7 --recursive --depth=1 --shallow-submodules \ - https://github.com/espressif/esp-idf.git /opt/esp-idf - -WORKDIR /opt/esp-idf - -# Install toolchains for esp32 (Xtensa) and esp32c3 (RISC-V) only -RUN ./install.sh esp32,esp32c3 - -# Clean up large unnecessary files to reduce image size -RUN rm -rf .git docs examples \ - && find /root/.espressif -name '*.tar.*' -delete 2>/dev/null || true - -# Install Arduino-as-component for full Arduino API support in ESP-IDF builds -RUN git clone --branch 2.0.17 --depth=1 --recursive --shallow-submodules \ - https://github.com/espressif/arduino-esp32.git /opt/arduino-esp32 \ - && rm -rf /opt/arduino-esp32/.git +RUN if [ "$ENABLE_ESP32" = "1" ]; then \ + git clone -b v4.4.7 --recursive --depth=1 --shallow-submodules \ + https://github.com/espressif/esp-idf.git /opt/esp-idf && \ + cd /opt/esp-idf && \ + ./install.sh esp32,esp32c3 && \ + rm -rf .git docs examples && \ + find /root/.espressif -name '*.tar.*' -delete 2>/dev/null || true && \ + git clone --branch 2.0.17 --depth=1 --recursive --shallow-submodules \ + https://github.com/espressif/arduino-esp32.git /opt/arduino-esp32 && \ + rm -rf /opt/arduino-esp32/.git ; \ + fi # ---- Stage 1: Build frontend and wokwi-libs ---- @@ -99,6 +107,8 @@ RUN npm install && npm run build:docker # ---- Stage 2: Final Production Image ---- FROM python:3.12-slim +ARG ENABLE_ESP32=0 + # Install system dependencies, nginx, and QEMU .so runtime libraries RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ @@ -179,8 +189,10 @@ ENV ARDUINO_ESP32_PATH=/opt/arduino-esp32 # Install ESP-IDF Python dependencies using the final image's Python # The requirements.txt has version constraints required by ESP-IDF 4.4.x -RUN grep -v 'esp-windows-curses' /opt/esp-idf/requirements.txt \ - | pip install --no-cache-dir -r /dev/stdin +RUN if [ "$ENABLE_ESP32" = "1" ]; then \ + grep -v 'esp-windows-curses' /opt/esp-idf/requirements.txt \ + | pip install --no-cache-dir -r /dev/stdin ; \ + fi EXPOSE 80