# DO NOT EDIT THIS FILE # # This is a Docker launcher file. To set up the configuration, use command line arguments to compile.sh # or create a config file named "config-docker-guest.conf" based on config-example.conf [[ ! -c /dev/loop-control ]] && display_alert "/dev/loop-control does not exist, image building may not work" "" "wrn" # remove "docker" from the command line since "docker-guest" will be passed instead shift # create user accessible directories and set their owner group and permissions # if they are created from Docker they will be owned by root and require root permissions to change/delete mkdir -p $SRC/{output,userpatches} grep -q '^docker:' /etc/group && chgrp --quiet docker $SRC/{output,userpatches} chmod --quiet g+w,g+s $SRC/{output,userpatches} VERSION=$(cat $SRC/VERSION) if grep -q $VERSION <(grep armbian <(docker images)); then display_alert "Using existed a armbian Docker container" else # build a new container based on provided Dockerfile display_alert "Docker container not found or out of date" display_alert "Building a Docker container" if ! docker build -t armbian:$VERSION . ; then STATUS=$? # Adding a newline, so the alert won't be shown in the same line as the error echo display_alert "Docker container build exited with code: " "$STATUS" "err" exit 1 fi fi DOCKER_FLAGS=() # Running this container in privileged mode is a simple way to solve loop device access issues #DOCKER_FLAGS+=(--privileged) # add only required capabilities instead (though MKNOD should be already present) # CAP_SYS_PTRACE is required for systemd-detect-virt in some cases DOCKER_FLAGS+=(--cap-add=SYS_ADMIN --cap-add=MKNOD --cap-add=SYS_PTRACE) # mounting things inside the container on Ubuntu won't work without this # https://github.com/moby/moby/issues/16429#issuecomment-217126586 DOCKER_FLAGS+=(--security-opt=apparmor:unconfined) # remove resulting container after exit to minimize clutter # bad side effect - named volumes are considered not attached to anything and are removed on "docker volume prune" #DOCKER_FLAGS+=(--rm) # pass through loop devices for d in /dev/loop*; do DOCKER_FLAGS+=(--device=$d) done # accessing dynamically created devices won't work by default # and --device doesn't accept devices that don't exist at the time "docker run" is executed # https://github.com/moby/moby/issues/27886 # --device-cgroup-rule requires new Docker version # Test for --device-cgroup-rule support. If supported, appends it # Otherwise, let it go and let user know that only kernel and u-boot for you if docker run --help | grep device-cgroup-rule > /dev/null 2>&1; then # allow loop devices (not required) DOCKER_FLAGS+=(--device-cgroup-rule='b 7:* rmw') # allow loop device partitions DOCKER_FLAGS+=(--device-cgroup-rule='b 259:* rmw') # this is an ugly hack, but it is required to get /dev/loopXpY minor number # for mknod inside the container, and container itself still uses private /dev internally DOCKER_FLAGS+=(-v /dev:/tmp/dev:ro) else display_alert "Your Docker version does not support device-cgroup-rule" "" "wrn" display_alert "and will be able to create only Kernel and u-boot packages (KERNEL_ONLY=yes)" "" "wrn" fi # map source to Docker Working dir. DOCKER_FLAGS+=(-v=$SRC/:/root/armbian/) # mount 2 named volumes - for cacheable data and compiler cache DOCKER_FLAGS+=(-v=armbian-cache:/root/armbian/cache -v=armbian-ccache:/root/.ccache) DOCKER_FLAGS+=(-e COLUMNS="`tput cols`" -e LINES="`tput lines`") # pass other command line arguments like KERNEL_ONLY=yes, KERNEL_CONFIGURE=yes, etc. # pass "docker-guest" as an additional config name that will be sourced in the container if exists display_alert "Running the container" "" "info" docker run "${DOCKER_FLAGS[@]}" -it armbian:$VERSION docker-guest "$@" # Docker error treatment STATUS=$? # Adding a newline, so the message won't be shown in the same line as the error echo case $STATUS in 0) # No errors from either Docker or build script echo ;; 125) display_alert "Docker command failed, check syntax or version support. Error code: " "$STATUS" "err" ;; 126) display_alert "Failure when running containerd command. Error code: " "$STATUS" "err" ;; 127) display_alert "containerd command not found. Error code: " "$STATUS" "err" ;; 137) display_alert "Container exit from docker stop. Error code: " "$STATUS" "info" ;; *) # Build script exited with error, but the error message should have been already printed echo ;; esac # don't need to proceed further on the host exit 0