-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun
executable file
·225 lines (193 loc) · 5.89 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
CWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
cd "${CWD}" || exit 1
# shellcheck source=./lib/log.sh
# shellcheck disable=SC1091
source "${CWD}"/lib/log.sh
DOCKER_HUB_USER=slechev
PRODUCT=openwebrxplus
DATE=$(date +%F)
TEST_IMG="${DOCKER_HUB_USER}/${PRODUCT}"
TEST_IMG="${DOCKER_HUB_USER}/${PRODUCT}-softmbe"
MAKEFLAGS=-j$(nproc --ignore=4)
# to use APT proxy, run: ./run start-apt-cache
APT_PROXY=
APT_PROXY="http://$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p'):3142"
HAS_DOCKER=$(docker -v 2>/dev/null || false)
HAS_BUILDX=$(docker buildx version 2>/dev/null || false)
start-apt-cache() {
log inf "Starting APT-Cache..."
cd "${CWD}"/apt-cache || exit 1
docker compose up -d
cd .. || exit 1
}
stop-apt-cache() {
log inf "Stopping APT-Cache..."
cd "${CWD}"/apt-cache || exit 1
docker compose down -v || true
cd .. || exit 1
}
check-apt() {
cd "${CWD}"/apt-cache || exit 1
local ret
ret=0
if [ "$(docker compose ps -q)" != "" ]; then
log "APT-Cache is running..."
ret=0
else
ret=1
fi
cd .. || exit 1
return $ret
}
clean() {
stop-apt-cache
log inf "Removing APT-Cache"
sudo rm -rf "${CWD}"/apt-cache/apt-cacher-ng/
docker image rm sameersbn/apt-cacher-ng
log inf "Stopping and Removing BuildX container"
sudo docker buildx stop
sudo docker buildx rm
log inf "Removing BuildX cache"
sudo docker builder prune -af
log inf "Removing BuildX volume"
docker volume rm buildx_buildkit_owrxp-builder0_state
log inf "Removing local cache folder"
sudo rm -rf "${CWD}"/cache
}
check-docker() {
log inf "Docker: [4[${HAS_DOCKER}]], [6[${HAS_BUILDX}]]"
if [ -z "${HAS_DOCKER}" ] || [ -z "${HAS_BUILDX}" ]; then
log err "Cannot find Docker or BuildX. Please install them."
exit 1
fi
}
add-admin() {
docker exec -it ${PRODUCT} /usr/bin/openwebrx admin adduser admin
}
get_owrxp_version() {
curl https://raw.githubusercontent.com/luarvique/openwebrx/master/owrx/version.py 2>/dev/null |
grep -v "looseversion" |
grep "_versionstring" |
cut -d '"' -f 2
}
build() {
check-apt || start-apt-cache
local VER
VER=$(get_owrxp_version)
log inf "Building '${PRODUCT}:${VER}'"
echo
mkdir -p cache
# create docker builder https://docs.docker.com/build/building/multi-platform/
# we enable networking so the builder container has access to the host network (needed for registry)
log inf "Creating docker builder for multiarch..."
docker buildx create \
--name owrxp-builder \
--driver docker-container \
--bootstrap \
--use \
--driver-opt network=host \
2>/dev/null || true # ignore errors if already created
log inf "Building the image for AMD64, ARM64 and ARM32v7."
time docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--build-context mycache="$(pwd)"/cache \
--cache-from type=local,src="$(pwd)"/cache \
--cache-to type=local,dest="$(pwd)"/cache \
--build-arg MAKEFLAGS="${MAKEFLAGS}" \
--build-arg BUILD_DATE="${DATE}" \
--build-arg PRODUCT="${PRODUCT}" \
--build-arg OWRXVERSION="${VER}" \
--build-arg APT_PROXY="${APT_PROXY}" \
-t "${DOCKER_HUB_USER}"/"${PRODUCT}":"${VER}" \
-t "${DOCKER_HUB_USER}"/"${PRODUCT}" \
--pull \
--push \
./buildfiles || exit 1
#--progress=plain \
#--load \
#--platform linux/amd64,linux/arm64,linux/arm/v7 \
#--platform linux/amd64 \
#--cache-from=type=local,src=`pwd`/cache
#--cache-to=type=local,dest=`pwd`/cache
log inf "Building SoftMBE image for AMD64, ARM64 and ARM32v7."
time docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--build-arg MAKEFLAGS="${MAKEFLAGS}" \
-t "${DOCKER_HUB_USER}"/"${PRODUCT}-softmbe":"${VER}" \
-t "${DOCKER_HUB_USER}"/"${PRODUCT}-softmbe" \
--pull \
--push \
./buildfiles-softmbe || exit 1
log inf "Removing docker builder (keeping state/caches for next use)..."
docker buildx rm --keep-state owrxp-builder # keep state is needed to keep the caches for the next build
}
run_internal() {
mkdir -p work/owrx/var work/owrx/etc
docker run --rm \
-h ${PRODUCT} \
--name ${PRODUCT} \
--device /dev/bus/usb \
-p 8073:8073 \
-v ./work/owrx/var:/var/lib/openwebrx \
-v ./work/owrx/etc:/etc/openwebrx \
-e FORWARD_LOCALPORT_1234=5678 \
-e TZ=Europe/Sofia \
"${1}"
}
run() {
docker pull ${TEST_IMG} || true
run_internal ${TEST_IMG}
}
run-from-hub() {
docker pull ${TEST_IMG} || true
run_internal ${TEST_IMG}
}
dev_internal() {
check-apt || start-apt-cache
mkdir -p work/owrx/var work/owrx/etc
docker run -it --rm \
-p 8073:8073 \
--device /dev/bus/usb \
-v ./work/owrx/var:/var/lib/openwebrx \
-v ./work/owrx/etc:/etc/openwebrx \
--name ${PRODUCT}-dev \
--entrypoint /init \
-v "$(pwd)"/cache:/build_cache \
-e http_proxy="${APT_PROXY}" \
-e FORWARD_LOCALPORT_1234=5678 \
-e TZ=Europe/Sofia \
"${1}" /bin/bash
}
dev() {
docker pull ${TEST_IMG} || true
dev_internal ${TEST_IMG}
}
dev-from-hub() {
docker pull ${TEST_IMG} || true
dev_internal ${TEST_IMG}
}
## MAIN
log "Builder for OpenWebRX+ Docker Image"
check-docker
usage() {
log war "Usage: $0 [command]"
log war '. commands:'
log war '... build - build the image and push to hub.docker.com'
log war '... run - run container from latest image'
log war '... run-from-hub - run container from latest image from hub.docker.com'
log war '... dev - start container with bash shell'
log war '... dev-from-hub - start container from hub.docker.com with bash shell'
log war "... add-admin - to add 'admin' user to running docker container"
log war "... clean - remove the builder and the caches."
echo
log war "You can specify MAKEFLAGS for docker builds:"
log war "[6[MAKEFLAGS=\"-j4\" $0]]"
}
if [[ $(type -t "$1") == 'function' ]]; then
# shellcheck disable=SC2068
$1 $@
else
[ "$1" != "" ] && log err "Command '$1' not found..." && echo
usage
fi