From 6f352a945c9a3f400dcf62d2d03b87996c4b498e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 7 Feb 2026 11:07:11 +0100 Subject: [PATCH] flutterw, like gradle wrapper for flutter, in a container --- Makefile | 16 ++++++++-------- docker/Dockerfile | 31 +++++++++++++++++++++++++++++++ docker-exec.sh => flutterw | 25 ++++++++++++------------- 3 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 docker/Dockerfile rename docker-exec.sh => flutterw (86%) diff --git a/Makefile b/Makefile index a2e95d6..4d3a443 100644 --- a/Makefile +++ b/Makefile @@ -2,28 +2,28 @@ all: clean-container build-linux-debug-container build-container: - ./docker-exec.sh build + ./flutterw --build clean-container: build-container - ./docker-exec.sh exec flutter clean + ./flutterw clean pub-get-container: build-container - ./docker-exec.sh exec flutter pub get + ./flutterw pub get build-android-release-container: pub-get-container - ./docker-exec.sh exec flutter build apk --release + ./flutterw build apk --release build-linux-debug-container: pub-get-container - ./docker-exec.sh exec flutter build linux --debug + ./flutterw build linux --debug build-web-debug-container: pub-get-container - ./docker-exec.sh exec flutter build web --debug + ./flutterw build web --debug run-linux-debug-container: pub-get-container - ./docker-exec.sh exec flutter run -d linux + ./flutterw run -d linux run-web-debug-container: pub-get-container - ./docker-exec.sh exec flutter run --web-port $${WEB_PORT:-8081} -d web-server + ./flutterw run --web-port $${WEB_PORT:-8081} -d web-server run-linux-debug-native: build-linux-debug-container ./build/linux/x64/debug/bundle/d4rt_formulas diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..534fd40 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,31 @@ +FROM ghcr.io/cirruslabs/flutter:stable + +# Install cmake, ninja, clang, pkg-config for flutter linux +RUN apt-get update && apt-get install -y cmake ninja-build clang pkg-config libgtk-3-dev liblzma-dev + +WORKDIR /app + +# Configure cache directories +ENV PUB_CACHE=/cache/pub-cache +ENV GRADLE_USER_HOME=/cache/gradle-cache +RUN mkdir -p $PUB_CACHE $GRADLE_USER_HOME + +# To avoid: fatal: detected dubious ownership in repository at '/sdks/flutter' +# Pass this during build: --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) +ARG USER_ID +ARG GROUP_ID +RUN echo "Using UID: $USER_ID and GID: $GROUP_ID" +RUN chown -R $USER_ID:$GROUP_ID $PUB_CACHE $GRADLE_USER_HOME +RUN chown -R $USER_ID:$GROUP_ID /sdks/flutter + +USER $USER_ID:$GROUP_ID + +# Copy pubspec files and get dependencies +# Commented out to avoid building the app during image creation, this will be handled externally by makefile +# COPY pubspec.yaml pubspec.lock ./ +# RUN flutter pub get + +# Copy the rest of the application code and build +# Commented out to avoid building the app during image creation, this will be handled externally by makefile +# COPY . . +# RUN flutter build apk --release diff --git a/docker-exec.sh b/flutterw similarity index 86% rename from docker-exec.sh rename to flutterw index f2c842d..89b83bc 100755 --- a/docker-exec.sh +++ b/flutterw @@ -4,7 +4,8 @@ set -e set -x BUILDCACHE=./.build-container-cache - +DOCKERFILE=./docker/Dockerfile +IMAGE=d4rt-formulas-builder detect_container(){ @@ -37,7 +38,7 @@ build_image(){ then USERMAPING="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)" fi - $DOCKER build $USERMAPING -t d4rt-formulas-builder -f Dockerfile . + $DOCKER build $USERMAPING -t $IMAGE -f $DOCKERFILE . } graphic_options(){ @@ -112,24 +113,22 @@ exec_in_container(){ main(){ detect_container - if [ "$1" = "build" ]; then + if [ "$1" = "--build" ]; then build_image return $? - fi - - if [ "$1" = "cleancache" ]; then + elif [ "$1" = "--cleancache" ]; then clean_build_cache return $? - fi - - - if [ "$1" = "exec" ]; then + elif [ "$1" = "--exec" ]; then exec_in_container ${@:2} return $? + elif [ "$1" = "" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then + echo "Usage: $0 {build|cleancache|exec }" + return 1 fi - - echo "Usage: $0 {build|cleancache|exec }" - return 1 + + exec_in_container flutter ${@:1} + return $? } main "$@"