From 8d020f5807cc623f7cf28c8d8fdde40958e45321 Mon Sep 17 00:00:00 2001 From: "alvaro@a37" Date: Wed, 28 Jan 2026 13:35:17 +0100 Subject: [PATCH] Docker y podman, x11 y wayland --- Dockerfile | 2 +- Makefile | 21 ++++++----- docker-compose.yml | 13 ------- docker-exec.sh | 91 ++++++++++++++++++++++++++++++++++------------ 4 files changed, 80 insertions(+), 47 deletions(-) delete mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 4552cb9..773912d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Use the official Flutter SDK image FROM ghcr.io/cirruslabs/flutter:stable # Install cmake, ninja, clang, pkg-config for flutter linux @@ -12,6 +11,7 @@ ENV GRADLE_USER_HOME=/cache/gradle-cache RUN mkdir -p $PUB_CACHE $GRADLE_USER_HOME # 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 diff --git a/Makefile b/Makefile index 858d879..84b2d0b 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,26 @@ -all: clean-podman build-linux-debug-podman build-linux-debug-podman +all: clean-container build-linux-debug-container -build-podman: +build-container: ./docker-exec.sh build -clean-podman: build-podman +clean-container: build-container ./docker-exec.sh exec flutter clean -pub-get-podman: build-podman +pub-get-container: build-container ./docker-exec.sh exec flutter pub get -build-android-release-podman: pub-get-podman +build-android-release-container: pub-get-container ./docker-exec.sh exec flutter build apk --release -build-linux-debug-podman: pub-get-podman +build-linux-debug-container: pub-get-container ./docker-exec.sh exec flutter build linux --debug -run-linux-debug: build-linux-debug-podman - build/linux/x64/debug/bundle/d4rt_formulas +build-web-debug-container: pub-get-container + ./docker-exec.sh exec flutter build web --debug -run-web-release-podman: build-web-release-podman +run-linux-debug-container: build-linux-debug-container + ./docker-exec.sh exec /app/build/linux/x64/debug/bundle/d4rt_formulas + +run-web-debug-container: build-web-debug-container cd build/web && python3 -m http.server 8080 diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 1dcbe96..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3.8' - -services: - flutter: - build: - context: . - dockerfile: Dockerfile - image: d4rt-formulas-builder - volumes: - - ./.build-container-cache:/cache:z - - .:/app:z # Link the current directory to /app in the container - environment: - - FLUTTER_FLAVOR=prod # Example environment variable, adjust as needed diff --git a/docker-exec.sh b/docker-exec.sh index 72cd927..e8147c0 100755 --- a/docker-exec.sh +++ b/docker-exec.sh @@ -2,39 +2,82 @@ set -e -DOCKER=podman +detect_container(){ + + if [ "$DOCKER" != "" ] + then + return 0 + elif command -v podman > /dev/null 2>&1 + then + DOCKER=podman + elif command -v docker > /dev/null 2>&1 + then + DOCKER=docker + else + echo "Error: no container manager detected (like 'docker' or 'podman'), please define DOCKER variable" + exit 2 + fi +} build_image(){ - $DOCKER build -t d4rt-formulas-builder -f Dockerfile . + $DOCKER build -t d4rt-formulas-builder -f Dockerfile . +} + +graphic_options(){ + + is_x11(){ + [ "$XDG_SESSION_TYPE" = "x11" ] || [ "$DISPLAY" != "" ] + } + + is_wayland(){ + [ "$XDG_SESSION_TYPE" = "wayland" ] || [ "$WAYLAND_DISPLAY" != "" ] + } + + if is_x11 + then + echo "--env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --security-opt=label=disable" + elif is_wayland + then + echo "--env=XDG_RUNTIME_DIR=/run/user/$(id -u) --volume=/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland --group-add=video" + else + echo "WARNING: no graphic environment" 1>&2 + fi } exec_in_container(){ + local SPIOPTIONS="--env AT_SPI_BUS=/run/user/$(id -u)/at-spi/bus_0 --volume=/run/user/$(id -u)/at-spi:/run/user/$(id -u)/at-spi --device=/dev/dri" - local XOPTIONS="--env DISPLAY=$DISPLAY --volume /tmp/.X11-unix:/tmp/.X11-unix --security-opt=label=disable" - local WOPTIONS="--env=XDG_RUNTIME_DIR=/run/user/$(id -u) --volume=/run/user/$(id -u)/wayland:/run/user/$(id -u)/wayland --group-add=video" - local SPIOPTIONS="--env AT_SPI_BUS=/run/user/$(id -u)/at-spi/bus_0 --volume=/run/user/$(id -u)/at-spi:/run/user/$(id -u)/at-spi --device=/dev/dri" + local GRAPHICOPTIONS=$(graphic_options) + local BUILDCACHE=./.build-container-cache + mkdir -p $BUILDCACHE - $DOCKER run \ - --rm \ - $XOPTIONS \ - $SPIOPTIONS \ - -v ./.build-container-cache:/cache:z \ - -v .:/app:z \ - -e FLUTTER_FLAVOR=prod \ - d4rt-formulas-builder \ - "$@" + $DOCKER run \ + --rm \ + $GRAPHICOPTIONS \ + $SPIOPTIONS \ + -v $BUILDCACHE:/cache:z \ + -v .:/app:z \ + -e FLUTTER_FLAVOR=prod \ + d4rt-formulas-builder \ + "$@" } -if [ "$1" = "build" ]; then - build_image - exit $? -fi +main(){ + detect_container -if [ "$1" = "exec" ]; then - exec_in_container ${@:2} - exit $? -fi + if [ "$1" = "build" ]; then + build_image + return $? + fi -echo "Usage: $0 {build|exec }" -exit 1 \ No newline at end of file + if [ "$1" = "exec" ]; then + exec_in_container ${@:2} + return $? + fi + + echo "Usage: $0 {build|exec }" + return 1 +} + +main "$@"