CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

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