Docker: add docker shell support (#1612)

This allows to enter the docker container in a shell by:

    ./compile.sh docker-shell
        BOARD=firefly-rk3399 BRANCH=dev RELEASE=bionic BUILD_DESKTOP=no

Then you can build the whole thing in the docker shell with:

    ./compile.sh

Once you need to build the U-Boot only for development purpose, you can run:

    # Optional: prepare the environment first if you had not run `./compile.sh`
    ./compile.sh 'prepare_host && compile_sunxi_tools && install_rkbin_tools'

    # build the U-Boot only
    ./compile.sh compile_uboot

If you prefer to use profile, for example, `userpatches/config-my.conf`,  try:

    ./compile.sh my 'prepare_host && compile_sunxi_tools && install_rkbin_tools'
    ./compile.sh my compile_uboot

This commit also fixes #1638.
This commit is contained in:
Levin Du 2019-11-28 22:24:22 +08:00 committed by Igor Pečovnik
parent 158e0f4849
commit de4cb7722d
2 changed files with 41 additions and 20 deletions

View File

@ -31,7 +31,7 @@ fi
if [[ $EUID == 0 ]] || [[ "$1" == vagrant ]]; then
:
elif [[ "$1" == docker || "$1" == dockerpurge ]] && grep -q `whoami` <(getent group docker); then
elif [[ "$1" == docker || "$1" == dockerpurge || "$1" == docker-shell ]] && grep -q `whoami` <(getent group docker); then
:
else
display_alert "This script requires root privileges, trying to use sudo" "" "wrn"
@ -91,6 +91,20 @@ if [[ "$1" == vagrant && -z "$(which vagrant)" ]]; then
sudo apt-get install -y vagrant virtualbox
fi
if [[ "$1" == dockerpurge && -f /etc/debian_version ]]; then
display_alert "Purging Armbian Docker containers" "" "wrn"
docker container ls -a | grep armbian | awk '{print $1}' | xargs docker container rm &> /dev/null
docker image ls | grep armbian | awk '{print $3}' | xargs docker image rm &> /dev/null
shift
set -- "docker" "$@"
fi
if [[ "$1" == docker-shell ]]; then
shift
SHELL_ONLY=yes
set -- "docker" "$@"
fi
# Install Docker if not there but wanted. We cover only Debian based distro install. Else, manual Docker install is needed
if [[ "$1" == docker && -f /etc/debian_version && -z "$(which docker)" ]]; then
display_alert "Docker not installed." "Installing" "Info"
@ -113,16 +127,6 @@ if [[ "$1" == docker && -f /etc/debian_version && -z "$(which docker)" ]]; then
exit $?
fi
if [[ "$1" == dockerpurge && -f /etc/debian_version ]]; then
display_alert "Purging Armbian Docker containers" "" "wrn"
docker container ls -a | grep armbian | awk '{print $1}' | xargs docker container rm &> /dev/null
docker image ls | grep armbian | awk '{print $3}' | xargs docker image rm &> /dev/null
shift
arr=("docker" "$@")
"$SRC/compile.sh" ${arr[@]}
exit $?
fi
# Create userpatches directory if not exists
mkdir -p $SRC/userpatches

View File

@ -5,13 +5,7 @@
[[ ! -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
# second argument can be a build parameter or a config file
unset DOCKER_CONF
[[ $1 != *=* ]] && DOCKER_CONF=$1
# 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}
@ -27,7 +21,7 @@ else
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
echo
display_alert "Docker container build exited with code: " "$STATUS" "err"
exit 1
fi
@ -86,8 +80,31 @@ 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_CONF "$@"
if [[ $SHELL_ONLY == yes ]]; then
display_alert "Running the container in shell mode" "" "info"
cat <<\EOF
Welcome to the docker shell of Armbian.
To build the whole thing using default profile, run:
./compile.sh
To build the U-Boot only, run:
# Optional: prepare the environment first if you had not run `./compile.sh`
./compile.sh 'prepare_host && compile_sunxi_tools && install_rkbin_tools'
# build the U-Boot only
./compile.sh compile_uboot
If you prefer to use profile, for example, `userpatches/config-my.conf`, try:
./compile.sh my 'prepare_host && compile_sunxi_tools && install_rkbin_tools'
./compile.sh my compile_uboot
EOF
docker run "${DOCKER_FLAGS[@]}" -it --rm --entrypoint /usr/bin/env armbian:$VERSION "$@" /bin/bash
else
display_alert "Running the container" "" "info"
docker run "${DOCKER_FLAGS[@]}" -it --rm armbian:$VERSION "$@"
fi
# Docker error treatment
STATUS=$?