-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·171 lines (147 loc) · 4.81 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
#!/bin/bash
CWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
cd "${CWD}" || exit 1
# shellcheck source=./lib/log.sh
source "${CWD}"/lib/log.sh
# to use APT proxy, run: ./image 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() {
cd "${CWD}"/apt-cache || exit 1
docker compose up -d
cd .. || exit 1
}
stop-apt-cache() {
cd "${CWD}"/apt-cache || exit 1
docker compose down -v
cd .. || exit 1
}
check-apt() {
cd "${CWD}"/apt-cache || exit 1
if [ "$(docker compose ps -q)" != "" ]; then
log log "APT-Cache is running..."
else
log inf "Starting APT-Cache..."
start-apt-cache
fi
cd .. || exit 1
}
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
}
settings() {
if [ ! -f ./settings.env ]; then
cat > settings.env << __EOF__
# Settings file for the openwebrx-deb-builder
# shellcheck disable=SC2148,SC2034 shell=bash
# Architectures to build for (space separated list in brackets):
# possible values: amd64 arm64 armhf
ARCHITECTURES=(amd64 arm64 armhf)
# setup multi-job compile to all CPU cores, but leave 4 for the system
MAKEFLAGS=-j$(nproc --ignore=4)
# Packages to compile. Set to 'y' or 'n'.
# NOTE: the builder will compile the dependency packages too.
BUILD_OWRX=y
BUILD_CSDR=n
BUILD_PYCSDR=n
BUILD_CSDR_ETI=n
BUILD_PYCSDR_ETI=n
BUILD_OWRXCONNECTOR=n
BUILD_SOAPYSDRPLAY3=n
BUILD_CODECSERVER=n
BUILD_DIGIHAM=n
BUILD_PYDIGIHAM=n
BUILD_JS8PY=n
BUILD_REDSEA=n
BUILD_LIBACARS=n
BUILD_ACARSDEC=n
BUILD_NRSC5=n
BUILD_CWSKIMMER=n
# If you are going to push the builder image to dockerhub,
# you should set your username and use 'docker login' command.
# If you do not know what this is, do not touch these variables.
PUSH_TO_DOCKERHUB=n
REGISTRY="docker.com"
REGISTRYUSER="slechev"
IMAGE_NAME="openwebrxplus-deb-builder"
# vim: set ft=sh
__EOF__
fi
${EDITOR:-vim} ./settings.env
}
create() {
source ./settings.env
if [ "${PUSH_TO_DOCKERHUB:-}" == "y" ]; then DOCKER_PUSH='--push'; else DOCKER_PUSH='--load'; fi
if [ ${#ARCHITECTURES[@]} -gt 1 ] && [ "${PUSH_TO_DOCKERHUB:-}" != "y" ]; then
log err "Creating multi-arch builders is supported only if you push to docker hub. Reduce to one arch only if you are going to create a builder locally."
exit 1
fi
log inf "Creating builders with Docker/BuildX"
docker buildx create --name owrxp-builder --driver docker-container --bootstrap --use --driver-opt network=host || true
for file in docker/Dockerfile*; do
IMAGE_TAG=$(echo "${file}" | sed -e 's/^docker\/Dockerfile-//' )
log inf "Creating builders for [6[${IMAGE_TAG}]]"
PLATFORMS=""
for arch in "${ARCHITECTURES[@]}"; do
PLATFORMS="${PLATFORMS},linux/$arch"
done
PLATFORMS=$(echo "${PLATFORMS}" | cut -c2-)
log inf "[6[${IMAGE_TAG}]] creating builders for [5[${PLATFORMS}]]"
time docker buildx build \
--tag "${REGISTRYUSER}/${IMAGE_NAME}:${IMAGE_TAG}" \
--platform "${PLATFORMS}" \
${DOCKER_PUSH} \
-f "${file}" \
.
done
docker buildx rm --keep-state owrxp-builder
}
build() {
source ./settings.env
log inf "Building packages with Docker/BuildX"
for file in docker/Dockerfile*; do
IMAGE_TAG=$(echo "${file}" | sed -e 's/^docker\/Dockerfile-//' )
for arch in "${ARCHITECTURES[@]}"; do
distro=$(echo "${IMAGE_TAG}" | cut -d '-' -f 1)
release=$(echo "${IMAGE_TAG}" | cut -d '-' -f 2)
log inf "running [4[${distro}]] [6[${release}]] build for [5[${arch}]]"
mkdir -p "owrx/${distro}/${release}/${arch}"
time docker run -it --rm --platform "linux/${arch}" \
--name "owrx-build-${IMAGE_TAG}" \
-e APT_PROXY="${APT_PROXY}" \
-e OUTPUT_DIR="/output/${arch}" \
-e MAKEFLAGS="${MAKEFLAGS}" \
-v "${CWD}/owrx/${distro}/${release}/:/output" \
-v "${CWD}/settings.env:/settings.env" \
-v "${CWD}/scripts:/scripts" \
"${REGISTRYUSER}/${IMAGE_NAME}:${IMAGE_TAG}"
done
done
}
## MAIN
log "Builder for OpenWebRX+ DEB Packages"
check-docker
check-apt
usage() {
log war "Usage: $0 [command]"
log war ". commands:"
log war "... [5[build]] - build DEB packages from settings"
log war "... [5[create]] - create docker builders"
log war "... [5[settings]] - create and/or edit settings"
log war "... [5[start-apt-cache]] - to start apt-cache docker container"
log war "... [5[stop-apt-cache]] - to stop apt-cache docker container"
echo
log war "NOTE: to clear the caches, you should remove the 'buildx' volume and the 'cache' folder."
}
if [[ $(type -t "$1") == 'function' ]]; then
$1 "$@"
else
[ "$1" != "" ] && log err "Command '$1' not found..." && echo
usage
fi