# TODO: support multi-arch building # TODO: https://docs.docker.com/reference/build-checks/from-platform-flag-const-disallowed/ # Multi-arch Dockerfile for building Flutter Linux app on ARM64 using emulation # Build with: docker buildx build --platform linux/arm64 -t pdf_signature_arm64 . # ---------------------------------------------------------------------------- # Build stage (Ubuntu 18.04) — glibc 2.27 to maximize compatibility (<= 2.30) # ---------------------------------------------------------------------------- FROM --platform=linux/arm64 ubuntu:18.04 AS build ENV DEBIAN_FRONTEND=noninteractive \ TZ=UTC \ FLUTTER_CHANNEL=stable # Install build dependencies and tooling RUN apt-get update && apt-get install -y \ ca-certificates \ curl \ git \ unzip \ xz-utils \ clang \ ninja-build \ pkg-config \ libgtk-3-dev \ libblkid-dev \ liblzma-dev \ && rm -rf /var/lib/apt/lists/* # Install a newer CMake (>= 3.13 required by Flutter linux build) for ARM64 ARG CMAKE_VERSION=3.27.9 RUN curl -fsSL -o /tmp/cmake.tar.gz \ https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-aarch64.tar.gz \ && tar -C /opt -xzf /tmp/cmake.tar.gz \ && ln -sf /opt/cmake-${CMAKE_VERSION}-linux-aarch64/bin/cmake /usr/local/bin/cmake \ && ln -sf /opt/cmake-${CMAKE_VERSION}-linux-aarch64/bin/ctest /usr/local/bin/ctest \ && ln -sf /opt/cmake-${CMAKE_VERSION}-linux-aarch64/bin/cpack /usr/local/bin/cpack \ && rm -f /tmp/cmake.tar.gz # Install Flutter SDK (ARM64) from source repo (channel: stable) RUN git clone -b ${FLUTTER_CHANNEL} https://github.com/flutter/flutter.git /opt/flutter ENV PATH="/opt/flutter/bin:/opt/flutter/bin/cache/dart-sdk/bin:${PATH}" # Precache Linux desktop artifacts and enable linux desktop RUN flutter config --enable-linux-desktop && \ flutter precache --linux # Set working directory WORKDIR /app # Copy pubspec files first for better caching COPY pubspec.* ./ # Get dependencies RUN flutter pub get # Copy the rest of the project COPY . . # Ensure Linux desktop project files are present (do not overwrite existing files/pubspec) RUN [ -d linux ] || flutter create . --platforms=linux # Refresh dependencies after full context is copied RUN flutter pub get # Generate build_runner outputs if codegen files are referenced RUN bash -lc "if grep -R \"part '.*\\.g\\.dart'\|part '.*\\.freezed\\.dart'\" -n lib >/dev/null; then dart --disable-analytics >/dev/null 2>&1 || true; dart run build_runner build --delete-conflicting-outputs; fi" # Build the Linux app for ARM64 (explicitly specify, though container is ARM64) RUN flutter build linux --target-platform linux-arm64 --release # ---------------------------------------------------------------------------- # Runtime stage (Ubuntu 18.04) — matches glibc from builder (2.27) # ---------------------------------------------------------------------------- FROM --platform=linux/arm64 ubuntu:18.04 AS runtime ENV DEBIAN_FRONTEND=noninteractive TZ=UTC # Install runtime dependencies only (do not ship libc from builder) RUN apt-get update && apt-get install -y \ libgtk-3-0 \ libblkid1 \ liblzma5 \ libstdc++6 \ && rm -rf /var/lib/apt/lists/* # Copy the built app COPY --from=build /app/build/linux/arm64/release/bundle /app # Set working directory WORKDIR /app # Run the app with bundled libraries CMD ["./pdf_signature"]