taskwarrior-flutter icon indicating copy to clipboard operation
taskwarrior-flutter copied to clipboard

feat: added dockerfile for linux and android

Open rohansen856 opened this issue 11 months ago • 9 comments

Description

Please include a summary of the change and which issue is fixed. List any dependencies that are required for this change.

Fixes #391

Replace issue_no with the issue number which is fixed in this PR

Screenshots

Summary

Three files in total was added in this PR

  • docker compose file
  • Dockerfile.linux
  • Dockerfile.android Using these files we can run flutter in containerized environment in both android and linux. For android device, We can either run it in an emulator or through a connected android device. There may be some native device problems due to the adb setup. It can be fixed using:
adb kill-server

Check again for all connected emulators:

adb devices
  • command to run in linux mode:
sudo docker-compose --profile linux up 
  • command to run in android mode:
sudo docker-compose --profile android up 
  • Added different files for android and linux as the android sdk is quite heavy and unneccesary for non-android emulators.

Checklist

  • [x] Tests have been added or updated to cover the changes
  • [x] Documentation has been updated to reflect the changes
  • [x] Code follows the established coding style guidelines
  • [x] All tests are passing

rohansen856 avatar Dec 18 '24 14:12 rohansen856

@BrawlerXull @Pavel401 I have added the containers and observed them to be running locally. I think there should be an update in the contributing file to add the functionality to run the app in containerized mode. Please let me know if anymore changes would be required. thank you.

rohansen856 avatar Dec 18 '24 14:12 rohansen856

Could you please share some outputs? Specifically, a screen recording demonstrating how this will benefit the contributors. I haven’t come across any open-source Flutter repositories that support Docker.

Of course @Pavel401 I will do a screenrecording and show how the docker is working to setup the entire project with just 1 command. The main benifit is that the flutter, dart and android sdk versionsof many devices vary and due to that the app might not work in many local devices (already happened with me!), the only solution would be updating local version of them, but as open source contributors might need to maintain several applications with their own desired version, it would become very problematic to constantly keep changing local dependency versions. AlthoughFVM` solves the problem to an extent but i's still prone to many errors. The best solution is to containerize the application using docker so that maintaining local version is not an issue any more!

About other flutter repos, they may not be that focused on open source contributors so they might not expect the developers to face the constant versioning problem i think... Nevertheless containerizing the app would definitely make it easier to get the app up and running in an instant without any versioning hassle. Thank you.

rohansen856 avatar Dec 19 '24 13:12 rohansen856

A Screen Recording of the running container

Screencast from 2024-12-19 18-33-26.webm

rohansen856 avatar Dec 19 '24 13:12 rohansen856

@BrawlerXull Any thoughts?

Pavel401 avatar Dec 19 '24 19:12 Pavel401

@rohansen856 Can you please share running our project with android emulator?

BrawlerXull avatar Jan 11 '25 08:01 BrawlerXull

@rohansen856 Can you please share running our project with android emulator?

sure... but there is an urgent issue for creating permission screens before 15th. would complete that asap and attach the app running in android emulator in docker.

rohansen856 avatar Jan 11 '25 17:01 rohansen856

@rohansen856 Can you please share running our project with android emulator?

sure... but there is an urgent issue for creating permission screens before 15th. would complete that asap and attach the app running in android emulator in docker.

Works! Complete it according to your convenience :)

BrawlerXull avatar Jan 12 '25 13:01 BrawlerXull

@BrawlerXull here are the screenrecording of the app running on Pixel 6 API 35 emulator using docker. (had to upload the video on multiple chunks because of video file size restrictions on github)

Screencast from 2025-01-30 14-56-02.webm

Screencast from 2025-01-30 15-11-14.webm

Screencast from 2025-01-30 15-13-23.webm

Screencast from 2025-01-30 15-25-23.webm

Screencast from 2025-01-30 15-26-53.webm

rohansen856 avatar Jan 30 '25 10:01 rohansen856

Note: I have got another Dockerfile for the android emulator which does the same thing but is a bit more explanatory and customizable:

FROM ubuntu:20.04

ENV UID=1000
ENV GID=1000
ENV USER="developer"
ENV JAVA_VERSION="8"
ENV ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip"
ENV ANDROID_VERSION="29"
ENV ANDROID_BUILD_TOOLS_VERSION="29.0.3"
ENV ANDROID_ARCHITECTURE="x86_64"
ENV ANDROID_SDK_ROOT="/home/$USER/android"
ENV FLUTTER_CHANNEL="stable"
ENV FLUTTER_VERSION="2.2.1"
ENV FLUTTER_URL="https://storage.googleapis.com/flutter_infra/releases/$FLUTTER_CHANNEL/linux/flutter_linux_$FLUTTER_VERSION-$FLUTTER_CHANNEL.tar.xz"
ENV FLUTTER_HOME="/home/$USER/flutter"
ENV FLUTTER_WEB_PORT="8090"
ENV FLUTTER_DEBUG_PORT="42000"
ENV FLUTTER_EMULATOR_NAME="flutter_emulator"
ENV PATH="$ANDROID_SDK_ROOT/cmdline-tools/tools/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/platforms:$FLUTTER_HOME/bin:$PATH"

# install all dependencies
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update \
  && apt-get install --yes --no-install-recommends openjdk-$JAVA_VERSION-jdk curl unzip sed git bash xz-utils libglvnd0 ssh xauth x11-xserver-utils libpulse0 libxcomposite1 libgl1-mesa-glx sudo \
  && rm -rf /var/lib/{apt,dpkg,cache,log}

# create user
RUN groupadd --gid $GID $USER \
  && useradd -s /bin/bash --uid $UID --gid $GID -m $USER \
  && echo $USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER \
  && chmod 0440 /etc/sudoers.d/$USER

USER $USER
WORKDIR /home/$USER

# android sdk
RUN mkdir -p $ANDROID_SDK_ROOT \
  && mkdir -p /home/$USER/.android \
  && touch /home/$USER/.android/repositories.cfg \
  && curl -o android_tools.zip $ANDROID_TOOLS_URL \
  && unzip -qq -d "$ANDROID_SDK_ROOT" android_tools.zip \
  && rm android_tools.zip \
  && mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && mv $ANDROID_SDK_ROOT/cmdline-tools/bin $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && mv $ANDROID_SDK_ROOT/cmdline-tools/lib $ANDROID_SDK_ROOT/cmdline-tools/tools \
  && yes "y" | sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
  && yes "y" | sdkmanager "platforms;android-$ANDROID_VERSION" \
  && yes "y" | sdkmanager "platform-tools" \
  && yes "y" | sdkmanager "emulator" \
  && yes "y" | sdkmanager "system-images;android-$ANDROID_VERSION;google_apis_playstore;$ANDROID_ARCHITECTURE"

# flutter
RUN curl -o flutter.tar.xz $FLUTTER_URL \
  && mkdir -p $FLUTTER_HOME \
  && tar xf flutter.tar.xz -C /home/$USER \
  && rm flutter.tar.xz \
  && flutter config --no-analytics \
  && flutter precache \
  && yes "y" | flutter doctor --android-licenses \
  && flutter doctor \
  && flutter emulators --create \
  && flutter update-packages

COPY entrypoint.sh /usr/local/bin/
COPY chown.sh /usr/local/bin/
COPY flutter-android-emulator.sh /usr/local/bin/flutter-android-emulator
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

should I update the Dockerfile.android or the previous one would suffice...?

rohansen856 avatar Jan 30 '25 10:01 rohansen856