flutterw, like gradle wrapper for flutter, in a container

This commit is contained in:
Your Name 2026-02-07 11:07:11 +01:00
parent dae8fe1ece
commit 6f352a945c
3 changed files with 51 additions and 21 deletions

View file

@ -2,28 +2,28 @@
all: clean-container build-linux-debug-container all: clean-container build-linux-debug-container
build-container: build-container:
./docker-exec.sh build ./flutterw --build
clean-container: build-container clean-container: build-container
./docker-exec.sh exec flutter clean ./flutterw clean
pub-get-container: build-container pub-get-container: build-container
./docker-exec.sh exec flutter pub get ./flutterw pub get
build-android-release-container: pub-get-container 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 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 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 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 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 run-linux-debug-native: build-linux-debug-container
./build/linux/x64/debug/bundle/d4rt_formulas ./build/linux/x64/debug/bundle/d4rt_formulas

31
docker/Dockerfile Normal file
View file

@ -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

View file

@ -4,7 +4,8 @@ set -e
set -x set -x
BUILDCACHE=./.build-container-cache BUILDCACHE=./.build-container-cache
DOCKERFILE=./docker/Dockerfile
IMAGE=d4rt-formulas-builder
detect_container(){ detect_container(){
@ -37,7 +38,7 @@ build_image(){
then then
USERMAPING="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)" USERMAPING="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)"
fi fi
$DOCKER build $USERMAPING -t d4rt-formulas-builder -f Dockerfile . $DOCKER build $USERMAPING -t $IMAGE -f $DOCKERFILE .
} }
graphic_options(){ graphic_options(){
@ -112,24 +113,22 @@ exec_in_container(){
main(){ main(){
detect_container detect_container
if [ "$1" = "build" ]; then if [ "$1" = "--build" ]; then
build_image build_image
return $? return $?
fi elif [ "$1" = "--cleancache" ]; then
if [ "$1" = "cleancache" ]; then
clean_build_cache clean_build_cache
return $? return $?
fi elif [ "$1" = "--exec" ]; then
if [ "$1" = "exec" ]; then
exec_in_container ${@:2} exec_in_container ${@:2}
return $? return $?
fi elif [ "$1" = "" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: $0 {build|cleancache|exec <command>}" echo "Usage: $0 {build|cleancache|exec <command>}"
return 1 return 1
fi
exec_in_container flutter ${@:1}
return $?
} }
main "$@" main "$@"