Migrate to Wolfi base image and optimize SDK size
Build and Push Flutter SDK Image / build-and-push (Flutter SDK for Linux desktop CI builds, Dockerfile.linux, linux) (release) Successful in 1h8m47s
Build and Push Flutter SDK Image / build-and-push (Flutter SDK for Android CI builds, Dockerfile.android, android) (release) Successful in 1h11m0s
Build and Push Flutter SDK Image / build-and-push (Minimal Flutter SDK for Web/WASM CI builds, Dockerfile, web) (release) Successful in 6m49s
Build and Push Flutter SDK Image / build-and-push (Flutter SDK for Linux desktop CI builds, Dockerfile.linux, linux) (release) Successful in 1h8m47s
Build and Push Flutter SDK Image / build-and-push (Flutter SDK for Android CI builds, Dockerfile.android, android) (release) Successful in 1h11m0s
Build and Push Flutter SDK Image / build-and-push (Minimal Flutter SDK for Web/WASM CI builds, Dockerfile, web) (release) Successful in 6m49s
- Switch all Dockerfiles from debian:bookworm-slim to svrnty/base-distro:flutter-sdk-latest (Wolfi) - Use non-root user (UID 65532) instead of custom flutter user - Strip wrong-platform engine artifacts per variant (web, android, linux) - Remove dev/, examples/ and compact .git with git gc --prune=all - Android: multi-stage build for JDK 17 + Android SDK 36 from Debian - Linux: multi-stage build for clang/cmake/ninja/GTK3 with glibc conflict resolution - Update Android SDK from 35 to 36 (required by Flutter 3.38.9) Image sizes: web 1.32 GB, linux 2.43 GB, android 4.22 GB (down from 4.9 GB, 3.69 GB, 4.15 GB respectively) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+43
-23
@@ -1,27 +1,30 @@
|
||||
FROM debian:bookworm-slim
|
||||
FROM svrnty/base-distro:flutter-sdk-latest AS base
|
||||
|
||||
ARG FLUTTER_VERSION=3.38.9
|
||||
ARG ANDROID_SDK_TOOLS_VERSION=11076708
|
||||
ARG ANDROID_COMPILE_SDK=35
|
||||
ARG ANDROID_BUILD_TOOLS=35.0.1
|
||||
ARG ANDROID_COMPILE_SDK=36
|
||||
ARG ANDROID_BUILD_TOOLS=36.0.0
|
||||
|
||||
LABEL org.opencontainers.image.title="flutter-sdk"
|
||||
LABEL org.opencontainers.image.title="flutter-sdk-android"
|
||||
LABEL org.opencontainers.image.description="Flutter SDK for Android CI builds"
|
||||
LABEL org.opencontainers.image.version="${FLUTTER_VERSION}"
|
||||
|
||||
# Install dependencies for Flutter + Android SDK
|
||||
# --- Install JDK and Android SDK in debian (requires apt + shared libs) ---
|
||||
FROM debian:bookworm-slim AS android-stage
|
||||
|
||||
ARG ANDROID_SDK_TOOLS_VERSION=11076708
|
||||
ARG ANDROID_COMPILE_SDK=36
|
||||
ARG ANDROID_BUILD_TOOLS=36.0.0
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
git \
|
||||
unzip \
|
||||
xz-utils \
|
||||
ca-certificates \
|
||||
openjdk-17-jdk-headless \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Android SDK
|
||||
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
||||
ENV ANDROID_HOME=/opt/android-sdk
|
||||
ENV PATH="${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}"
|
||||
ENV PATH="${JAVA_HOME}/bin:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}"
|
||||
|
||||
RUN mkdir -p "${ANDROID_HOME}/cmdline-tools" && \
|
||||
curl -fsSL "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip" \
|
||||
@@ -30,25 +33,48 @@ RUN mkdir -p "${ANDROID_HOME}/cmdline-tools" && \
|
||||
mv /tmp/cmdline-tools/cmdline-tools "${ANDROID_HOME}/cmdline-tools/latest" && \
|
||||
rm -rf /tmp/cmdline-tools.zip /tmp/cmdline-tools
|
||||
|
||||
# Accept licenses and install SDK components
|
||||
RUN yes | sdkmanager --licenses > /dev/null 2>&1 && \
|
||||
sdkmanager --install \
|
||||
"platform-tools" \
|
||||
"platforms;android-${ANDROID_COMPILE_SDK}" \
|
||||
"build-tools;${ANDROID_BUILD_TOOLS}"
|
||||
|
||||
# Flutter SDK
|
||||
ENV FLUTTER_HOME=/opt/flutter
|
||||
ENV PATH="${FLUTTER_HOME}/bin:${FLUTTER_HOME}/bin/cache/dart-sdk/bin:${PATH}"
|
||||
# --- Build final image ---
|
||||
FROM base
|
||||
|
||||
USER 0
|
||||
|
||||
# Copy JDK and its required shared libraries from debian
|
||||
COPY --from=android-stage /usr/lib/jvm/java-17-openjdk-amd64 /usr/lib/jvm/java-17-openjdk-amd64
|
||||
COPY --from=android-stage /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu
|
||||
COPY --from=android-stage /lib/x86_64-linux-gnu /lib/x86_64-linux-gnu
|
||||
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
||||
ENV PATH="${JAVA_HOME}/bin:${PATH}"
|
||||
|
||||
# Copy Android SDK (already set up with licenses and components)
|
||||
COPY --from=android-stage /opt/android-sdk /opt/android-sdk
|
||||
ENV ANDROID_HOME=/opt/android-sdk
|
||||
ENV PATH="${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}"
|
||||
|
||||
# Download Flutter SDK and strip unnecessary files in a single layer
|
||||
RUN curl -fsSL "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz" \
|
||||
-o /tmp/flutter.tar.xz && \
|
||||
tar xf /tmp/flutter.tar.xz -C /opt && \
|
||||
rm /tmp/flutter.tar.xz
|
||||
rm /tmp/flutter.tar.xz && \
|
||||
rm -rf /opt/flutter/dev \
|
||||
/opt/flutter/examples \
|
||||
/opt/flutter/bin/cache/artifacts/engine/linux-* \
|
||||
/opt/flutter/bin/cache/flutter_web_sdk
|
||||
|
||||
RUN git config --global --add safe.directory "${FLUTTER_HOME}"
|
||||
RUN git config --global --add safe.directory /opt/flutter && \
|
||||
cd /opt/flutter && git gc --prune=all
|
||||
|
||||
# Configure for Android-only
|
||||
# Fix ownership before switching to flutter user
|
||||
RUN chown -R 65532:65532 /opt/flutter "${ANDROID_HOME}"
|
||||
|
||||
USER 65532
|
||||
|
||||
# Configure Flutter for Android-only
|
||||
RUN flutter config --enable-android \
|
||||
--no-enable-web \
|
||||
--no-enable-ios \
|
||||
@@ -69,10 +95,4 @@ RUN flutter precache --android \
|
||||
|
||||
RUN flutter doctor -v
|
||||
|
||||
# Create non-root user for CI builds
|
||||
RUN groupadd -r flutter && useradd -r -g flutter -m -d /home/flutter flutter && \
|
||||
chown -R flutter:flutter "${FLUTTER_HOME}" "${ANDROID_HOME}" /home/flutter
|
||||
|
||||
WORKDIR /app
|
||||
RUN chown flutter:flutter /app
|
||||
USER flutter
|
||||
|
||||
Reference in New Issue
Block a user