config-docker.conf 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # DO NOT EDIT THIS FILE
  2. #
  3. # This is a Docker launcher file. To set up the configuration, use command line arguments to compile.sh
  4. # or use pass a config file as a parameter ./compile docker [example] BUILD_KERNEL="yes" ...
  5. [[ ! -c /dev/loop-control ]] && display_alert "/dev/loop-control does not exist, image building may not work" "" "wrn"
  6. # second argument can be a build parameter or a config file
  7. # create user accessible directories and set their owner group and permissions
  8. # if they are created from Docker they will be owned by root and require root permissions to change/delete
  9. mkdir -p $SRC/{output,userpatches}
  10. grep -q '^docker:' /etc/group && chgrp --quiet docker $SRC/{output,userpatches}
  11. chmod --quiet g+w,g+s $SRC/{output,userpatches}
  12. VERSION=latest
  13. if grep -q $VERSION <(grep orangepi <(docker images)); then
  14. display_alert "Using existed a orangepi Docker container"
  15. else
  16. # build a new container based on provided Dockerfile
  17. display_alert "Docker container not found or out of date"
  18. display_alert "Building a Docker container"
  19. if ! docker build -t orangepi:$VERSION . ; then
  20. STATUS=$?
  21. # Adding a newline, so the alert won't be shown in the same line as the error
  22. echo
  23. display_alert "Docker container build exited with code: " "$STATUS" "err"
  24. exit 1
  25. fi
  26. fi
  27. DOCKER_FLAGS=()
  28. # Running this container in privileged mode is a simple way to solve loop device access issues
  29. # Required for USB FEL or when writing image directly to the block device, when CARD_DEVICE is defined
  30. #DOCKER_FLAGS+=(--privileged)
  31. # add only required capabilities instead (though MKNOD should be already present)
  32. # CAP_SYS_PTRACE is required for systemd-detect-virt in some cases
  33. DOCKER_FLAGS+=(--cap-add=SYS_ADMIN --cap-add=MKNOD --cap-add=SYS_PTRACE)
  34. # mounting things inside the container on Ubuntu won't work without this
  35. # https://github.com/moby/moby/issues/16429#issuecomment-217126586
  36. DOCKER_FLAGS+=(--security-opt=apparmor:unconfined)
  37. # remove resulting container after exit to minimize clutter
  38. # bad side effect - named volumes are considered not attached to anything and are removed on "docker volume prune"
  39. DOCKER_FLAGS+=(--rm)
  40. # pass through loop devices
  41. for d in /dev/loop*; do
  42. DOCKER_FLAGS+=(--device=$d)
  43. done
  44. # accessing dynamically created devices won't work by default
  45. # and --device doesn't accept devices that don't exist at the time "docker run" is executed
  46. # https://github.com/moby/moby/issues/27886
  47. # --device-cgroup-rule requires new Docker version
  48. # Test for --device-cgroup-rule support. If supported, appends it
  49. # Otherwise, let it go and let user know that only kernel and u-boot for you
  50. if docker run --help | grep device-cgroup-rule > /dev/null 2>&1; then
  51. # allow loop devices (not required)
  52. DOCKER_FLAGS+=(--device-cgroup-rule='b 7:* rmw')
  53. # allow loop device partitions
  54. DOCKER_FLAGS+=(--device-cgroup-rule='b 259:* rmw')
  55. # this is an ugly hack, but it is required to get /dev/loopXpY minor number
  56. # for mknod inside the container, and container itself still uses private /dev internally
  57. DOCKER_FLAGS+=(-v /dev:/tmp/dev:ro)
  58. else
  59. display_alert "Your Docker version does not support device-cgroup-rule" "" "wrn"
  60. display_alert "and will be able to create only Kernel and u-boot packages (KERNEL_ONLY=yes)" "" "wrn"
  61. fi
  62. # Expose ports for NFS server inside docker container, required for USB FEL
  63. #DOCKER_FLAGS+=(-p 0.0.0.0:2049:2049 -p 0.0.0.0:2049:2049/udp -p 0.0.0.0:111:111 -p 0.0.0.0:111:111/udp -p 0.0.0.0:32765:32765 -p 0.0.0.0:32765:32765/udp -p 0.0.0.0:32767:32767 -p 0.0.0.0:32767:32767/udp)
  64. # Export usb device for FEL, required for USB FEL
  65. #DOCKER_FLAGS+=(-v /dev/bus/usb:/dev/bus/usb:ro)
  66. # map source to Docker Working dir.
  67. DOCKER_FLAGS+=(-v=$SRC/:/root/orangepi/)
  68. # mount 2 named volumes - for cacheable data and compiler cache
  69. DOCKER_FLAGS+=(-v=orangepi-cache:/root/orangepi/cache -v=orangepi-ccache:/root/.ccache)
  70. DOCKER_FLAGS+=(-e COLUMNS="`tput cols`" -e LINES="`tput lines`")
  71. # pass other command line arguments like KERNEL_ONLY=yes, KERNEL_CONFIGURE=yes, etc.
  72. # pass "docker-guest" as an additional config name that will be sourced in the container if exists
  73. if [[ $SHELL_ONLY == yes ]]; then
  74. display_alert "Running the container in shell mode" "" "info"
  75. cat <<\EOF
  76. Welcome to the docker shell of Armbian.
  77. To build the whole thing using default profile, run:
  78. ./compile.sh
  79. To build the U-Boot only, run:
  80. # Optional: prepare the environment first if you had not run `./compile.sh`
  81. ./compile.sh 'prepare_host && compile_sunxi_tools && install_rkbin_tools'
  82. # build the U-Boot only
  83. ./compile.sh compile_uboot
  84. If you prefer to use profile, for example, `userpatches/config-my.conf`, try:
  85. ./compile.sh my 'prepare_host && compile_sunxi_tools && install_rkbin_tools'
  86. ./compile.sh my compile_uboot
  87. EOF
  88. docker run "${DOCKER_FLAGS[@]}" -it --entrypoint /usr/bin/env orangepi:$VERSION "$@" /bin/bash
  89. else
  90. display_alert "Running the container" "" "info"
  91. docker run "${DOCKER_FLAGS[@]}" -it orangepi:$VERSION "$@"
  92. fi
  93. # Docker error treatment
  94. STATUS=$?
  95. # Adding a newline, so the message won't be shown in the same line as the error
  96. echo
  97. case $STATUS in
  98. 0)
  99. # No errors from either Docker or build script
  100. echo
  101. ;;
  102. 125)
  103. display_alert "Docker command failed, check syntax or version support. Error code: " "$STATUS" "err"
  104. ;;
  105. 126)
  106. display_alert "Failure when running containerd command. Error code: " "$STATUS" "err"
  107. ;;
  108. 127)
  109. display_alert "containerd command not found. Error code: " "$STATUS" "err"
  110. ;;
  111. 137)
  112. display_alert "Container exit from docker stop. Error code: " "$STATUS" "info"
  113. ;;
  114. *)
  115. # Build script exited with error, but the error message should have been already printed
  116. echo
  117. ;;
  118. esac
  119. # don't need to proceed further on the host
  120. exit 0