| # Copyright 2022 The Flutter Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # ========================================== |
| # STAGE 1: The Heavy Downloader |
| # ========================================== |
| FROM ubuntu:24.04 AS flutter-fetcher |
| |
| # 1. Define the ARG with a fallback default version |
| ARG FLUTTER_VERSION="3.44.3" |
| ARG TARGETARCH |
| |
| ENV TZ="America/Los_Angeles" \ |
| DEBIAN_FRONTEND=noninteractive \ |
| FLUTTER_ROOT="/opt/flutter" \ |
| PATH="/opt/flutter/bin:/home/coder/.local/bin:${PATH}" \ |
| LANG="en_US.UTF-8" \ |
| LANGUAGE="en_US:en" \ |
| LC_ALL="en_US.UTF-8" \ |
| TERM="xterm-256color" \ |
| COLORTERM="truecolor" \ |
| SHELL="/usr/bin/zsh" |
| |
| RUN apt-get update && \ |
| apt-get install -y --no-install-recommends \ |
| curl ca-certificates xz-utils git unzip && \ |
| rm -rf /var/lib/apt/lists/* |
| |
| # Evict the default ubuntu user and create the target user |
| RUN set -ex; \ |
| (userdel -r ubuntu 2>/dev/null || true); \ |
| groupadd -g 1000 coder; \ |
| useradd -u 1000 -g 1000 -m coder; \ |
| mkdir -p /app /opt/flutter /home/linuxbrew/.linuxbrew; \ |
| chown -R coder:coder /app /opt /home/linuxbrew; |
| |
| USER coder |
| |
| RUN set -ex; \ |
| export PATH="/opt/flutter/bin:${PATH}"; \ |
| # 1. Download and uncompress the flutter tool |
| ARCH="${TARGETARCH:-$(dpkg --print-architecture)}"; \ |
| EXCLUDE_CACHE=""; \ |
| if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then \ |
| EXCLUDE_CACHE="--exclude=flutter/bin/cache"; \ |
| fi; \ |
| curl -fsSL "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz" | tar -xJ --exclude=.pub-preload-cache $EXCLUDE_CACHE --no-same-owner -C /opt; \ |
| # 2. Run config to ONLY ENABLE web (and disable everything else) |
| flutter config \ |
| --enable-web \ |
| --no-enable-linux-desktop \ |
| --no-enable-macos-desktop \ |
| --no-enable-windows-desktop \ |
| --no-enable-android \ |
| --no-enable-ios \ |
| --no-enable-fuchsia; \ |
| \ |
| # 3. Precache only the web artifacts |
| flutter precache --web; \ |
| \ |
| # 4. Delete the heavy cache/artifacts/engine folder and test/gallery waste |
| rm -rf /opt/flutter/bin/cache/artifacts/engine; \ |
| rm -rf /home/coder/.pub-cache/hosted/pub.dev/flutter_gallery_assets*; \ |
| rm -rf /home/coder/.pub-cache/hosted/pub.dev/googleapis*; \ |
| \ |
| # 5. Run doctor to finalize setup and verify web artifacts |
| /opt/flutter/bin/flutter doctor -v; \ |
| \ |
| # 6. Log some stuff and setup analytics (user == human) |
| flutter --version ; \ |
| flutter --enable-analytics; \ |
| dart --enable-analytics; |
| |
| # 2. Lock in configuration and force the massive SDK downloads |
| ENV PATH="/opt/flutter/bin:${PATH}" |