Docker y podman, x11 y wayland
This commit is contained in:
parent
28671888e1
commit
8d020f5807
4 changed files with 80 additions and 47 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
21
Makefile
21
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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 <command>}"
|
||||
exit 1
|
||||
if [ "$1" = "exec" ]; then
|
||||
exec_in_container ${@:2}
|
||||
return $?
|
||||
fi
|
||||
|
||||
echo "Usage: $0 {build|exec <command>}"
|
||||
return 1
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
|||
Loading…
Reference in a new issue