cirruslabs / docker-images-flutter

Docker Images for Flutter
MIT License
433 stars 139 forks source link

Run `flutter precache` at image build time #319

Closed bartekpacia closed 4 months ago

bartekpacia commented 4 months ago

flutter precache is called anyway during the first flutter run anyway, which adds time (just now I checked with my very good connection and flutter precache took additional 40s).

So I think it makes sense to add it at build time.

fkorotkov commented 4 months ago

I wasn't able to find documentation that flutter precache is called for the first flutter run. I'm just worried that it will download too much rather than what's needed for a particular flutter run.

bartekpacia commented 4 months ago

@fkorotkov There's no docs around that, but it is true.

The possible inefficiency is that flutter precache downloads artifacts for all platforms (ios, android, web + current desktop (macos or windows or linux)) and puts them in $FLUTTER_ROOT/bin/cache:

Example run ``` $ flutter precache --force Downloading Material fonts... 316ms Downloading Gradle Wrapper... 27ms Downloading android-arm-profile/darwin-x64 tools... 156ms Downloading android-arm-release/darwin-x64 tools... 142ms Downloading android-arm64-profile/darwin-x64 tools... 256ms Downloading android-arm64-release/darwin-x64 tools... 239ms Downloading android-x64-profile/darwin-x64 tools... 248ms Downloading android-x64-release/darwin-x64 tools... 206ms Downloading android-x86 tools... 1,650ms Downloading android-x64 tools... 1,597ms Downloading android-arm tools... 1,533ms Downloading android-arm-profile tools... 342ms Downloading android-arm-release tools... 262ms Downloading android-arm64 tools... 3.3s Downloading android-arm64-profile tools... 276ms Downloading android-arm64-release tools... 198ms Downloading android-x64-profile tools... 278ms Downloading android-x64-release tools... 205ms Downloading android-x86-jit-release tools... 362ms Downloading ios tools... 4.4s Downloading ios-profile tools... 6.1s Downloading ios-release tools... 5.6s Downloading Web SDK... 2,512ms Downloading package sky_engine... 76ms Downloading flutter_patched_sdk tools... 167ms Downloading flutter_patched_sdk_product tools... 141ms Downloading darwin-arm64 tools... 4.7s Downloading darwin-x64/FlutterMacOS.framework tools... 2,187ms Downloading darwin-x64/gen_snapshot tools... 293ms Downloading darwin-x64-profile/FlutterMacOS.framework tools... 1,736ms Downloading darwin-x64-profile tools... 459ms Downloading darwin-x64-profile/gen_snapshot tools... 977ms Downloading darwin-x64-release/FlutterMacOS.framework tools... 1,096ms Downloading darwin-x64-release tools... 116ms Downloading darwin-x64-release/gen_snapshot tools... 242ms Downloading libimobiledevice... 29ms Downloading usbmuxd... 25ms Downloading libplist... 25ms Downloading openssl... 71ms Downloading ios-deploy... 31ms Downloading darwin-arm64/font-subset tools... 131ms ```

But since this whole image is Ubuntu-based, I don't think efficiency is that important and that a few more executables (which they will download anyway) will matter to users. I, for once, would prefer an image that has all the stuff I will most likely need anyway, but which I end up doing at runtime every time.

But if you deem it important, then I think a "full" and "minimal" image could be provided?

bartekpacia commented 4 months ago

I inspected the image using dive and it adds about 0.5 GB:

Screenshot 2024-03-05 at 13 39 53
fkorotkov commented 4 months ago

Which platform are you developing from? flutter precache --help suggests that we can disable some things. I wonder if flutter precache --no-ios --no-windows --no-macos will bring the size down to something acceptable.

bartekpacia commented 4 months ago

Here are some results:

REPOSITORY                   TAG                          IMAGE ID       CREATED          SIZE
flutter                      precache-android-linux-web   09060ea1f951   9 minutes ago    2.99GB
flutter                      precache-android-linux       04a912c9d16d   12 minutes ago   2.83GB
flutter                      precache-android             1724050f6c62   16 minutes ago   2.65GB
flutter                      precache-android-ios         847b9fbc2a96   11 hours ago     3.4GB
flutter                      precache                     4dd426672dd7   12 hours ago     2.99GB
ghcr.io/cirruslabs/flutter   3.19.2                       2c056fd12d90   6 days ago       2.46GB

I think it makes sense to just use flutter precache. By default it downloads artifacts for all platforms that can be used on the machine (i.e it doesn't make sense to pass --ios or --windows since we can't build for them anyway on a Linux box).

See also https://github.com/flutter/flutter/issues/144656

bartekpacia commented 4 months ago

So my suggestion is to have:

or the reverse. Names tentative - lite, full, mini, whatever:)

What do you think @fkorotkov? I'm willing to contribute this.

fkorotkov commented 4 months ago

What do you think of just precaching Android? Plus the size bump is not too big. Seems Android is the main use case for the images. Then if we'll have more requests than we can introduce variants.

bartekpacia commented 4 months ago

I agree, let's do that.Good enough for now:)