forked from jketterl/openwebrx
-
Notifications
You must be signed in to change notification settings - Fork 52
/
docker.sh
executable file
·203 lines (175 loc) · 7.99 KB
/
docker.sh
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
#!/usr/bin/env bash
set -euo pipefail
export DH_PROJECT="openwebrxplus"
export DH_USERNAME="slechev"
#IMAGES="${DH_PROJECT}-rtlsdr ${DH_PROJECT}-sdrplay ${DH_PROJECT}-hackrf ${DH_PROJECT}-airspy ${DH_PROJECT}-rtlsdr-soapy ${DH_PROJECT}-plutosdr ${DH_PROJECT}-limesdr ${DH_PROJECT}-soapyremote ${DH_PROJECT}-perseus ${DH_PROJECT}-fcdpp ${DH_PROJECT}-radioberry ${DH_PROJECT}-uhd ${DH_PROJECT}-rtltcp ${DH_PROJECT}-runds ${DH_PROJECT}-hpsdr ${DH_PROJECT}-bladerf ${DH_PROJECT}-full ${DH_PROJECT}"
IMAGES="${DH_PROJECT}-full"
ARCH=${ARCH:-$(uname -m)}
TAG=${TAG:-"latest"}
ARCHTAG="${TAG}-${ARCH}"
NIGHTLY_BUILD=$(date +%F)
CORES=$(cat /proc/cpuinfo | grep processor | wc -l)
MAKEFLAGS="${MAKEFLAGS:-"-j$CORES"}"
usage () {
echo "Usage: ${0} [command]"
echo "Available commands:"
echo " help Show this usage information"
echo " buildn Build full docker nightly image (current sources)"
echo " buildr Build full docker release image (form Marat's apt repo)"
echo
echo "Environment variables:"
echo " ARCH - build for different architecture, ex: ARCH=arm64 ${0} buildn"
echo " TAG - use different TAG (default is 'latest'), ex: TAG=mytag ${0} buildn"
echo " MAKEFLAGS - set MAKEFLAGS for the compiler, ex: MAKEFLAGS='-j12' ${0} buildn"
}
nightly () {
# this build method is used for multiplatform automated builds every night
# NOTE: this will not work with podman, since it requires specidic docker bulder
if docker buildx ls >/dev/null 2>&1; then
echo "Building with docker..."
else
echo "This cannot be done with Podman, we need docker buildx drivers."
exit
fi
# create docker builder https://docs.docker.com/build/building/multi-platform/
# we enable networking so the builder container has access to the host netwoerk (needed for registry)
echo -e "\n\nCreating docker builder for multiarch...\n\n"
docker buildx create --name owrxp-builder --driver docker-container --bootstrap --use --driver-opt network=host || true # ignore errors if already created
# create another docker container for local registry.
# we need this to store our -base image, because docker builder always try to pull the -base image
# from dockerhub and not use the localy present -base image for building the -full image.
echo -e "\n\nCreating local docker registry...\n\n"
docker container rm -vf registry 2>/dev/null || true # remove an existing registry container (ignoring errors)
docker run -d --name registry --network=host registry:2 # create new registry container
# build the -base image and store it in local registry (see the tags)
echo -e "\n\nBuilding the base image for AMD64, ARM64v8 and ARM32v7.\n\n"
time docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t localhost:5000/${DH_PROJECT}-base:${NIGHTLY_BUILD} \
-t localhost:5000/${DH_PROJECT}-base \
--push --pull -f docker/Dockerfiles/Dockerfile-base .
GIT_HASH=$(git rev-parse --short master)
# build the -full image using the -base from LOCAL_REGISTRY
echo -e "\n\nBuilding the full image for AMD64, ARM64v8 and ARM32v7.\n\n"
time docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--build-arg LOCAL_REGISTRY="localhost:5000/" \
--build-arg GIT_HASH=${GIT_HASH} \
--build-arg ARCHTAG=latest \
--build-arg PROJECT=${DH_PROJECT} \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t ${DH_USERNAME}/${DH_PROJECT}-nightly:${NIGHTLY_BUILD} \
-t ${DH_USERNAME}/${DH_PROJECT}-nightly \
--pull=false \
--push -f docker/Dockerfiles/Dockerfile-full .
echo -e "\n\nRemoving docker builder (keeping state/caches for next use)...\n\n"
docker buildx rm --keep-state owrxp-builder # keep state is needed to keep the caches for the next build
echo -e "\n\nRemoving local docker registry...\n\n"
docker container rm -vf registry
}
release () {
# this build method is used for multiplatform release builds
# NOTE: this will not work with podman, since it requires specidic docker bulder
if docker buildx ls >/dev/null 2>&1; then
echo "Building with docker..."
else
echo "This cannot be done with Podman, we need docker buildx drivers."
exit
fi
if [[ -z ${1:-} ]] ; then
echo "Usage: ${0} dorelease [version]"
echo "NOTE: The version param will be used for tagging only."
echo "The image will be built from the current packages in the apt-repo."
echo; echo;
return
fi
# create docker builder https://docs.docker.com/build/building/multi-platform/
# we enable networking so the builder container has access to the host netwoerk (needed for registry)
echo -e "\n\nCreating docker builder for multiarch...\n\n"
docker buildx create --name owrxp-builder --driver docker-container --bootstrap --use --driver-opt network=host || true # ignore errors if already created
echo -ne "\n\nBuilding release image: $1.\n\n"
docker buildx build \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--build-arg VERSION=$1 \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t ${DH_USERNAME}/${DH_PROJECT}:${1} \
-t ${DH_USERNAME}/${DH_PROJECT} \
--pull --push -f docker/deb_based/Dockerfile .
echo -e "\n\nRemoving docker builder (keeping state/caches for next use)...\n\n"
docker buildx rm --keep-state owrxp-builder # keep state is needed to keep the caches for the next build
}
buildn () {
PLATFORM=""
if [[ "${ARCH}" != "$(uname -m)" ]]; then
PLATFORM="--platform=linux/$ARCH"
fi
echo -ne "\n\nBuilding the base image for $ARCH.\n\n"
time docker build $PLATFORM \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t ${DH_PROJECT}-base:${ARCHTAG} \
--pull -f docker/Dockerfiles/Dockerfile-base .
# NOTE: uncomment next 2 lines if you're building all images
#echo -ne "\n\nBuilding soapysdr image.\n\n"
#docker build $PLATFORM --build-arg ARCHTAG=${ARCHTAG} --build-arg PROJECT=${DH_PROJECT} --build-arg MAKEFLAGS="$MAKEFLAGS" -t ${DH_PROJECT}-soapysdr-base:${ARCHTAG} -f docker/Dockerfiles/Dockerfile-soapysdr .
GIT_HASH=$(git rev-parse --short master)
for image in ${IMAGES}; do
i=$(echo ${image} | rev | cut -d- -f1 | rev)
# "openwebrx" is a special image that gets tag-aliased later on
if [[ ! -z "${i}" && "${i}" != "${DH_PROJECT}" ]] ; then
echo -ne "\n\nBuilding ${i} image for $ARCH.\n\n"
time docker build $PLATFORM \
--build-arg GIT_HASH=${GIT_HASH} \
--build-arg ARCHTAG=$ARCHTAG \
--build-arg PROJECT=${DH_PROJECT} \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t ${DH_USERNAME}/${image}:${ARCHTAG} \
-f docker/Dockerfiles/Dockerfile-${i} .
fi
done
# tag full image alias image
docker tag ${DH_USERNAME}/${DH_PROJECT}-full:${ARCHTAG} ${DH_USERNAME}/${DH_PROJECT}-nightly:${NIGHTLY_BUILD}
docker tag ${DH_USERNAME}/${DH_PROJECT}-full:${ARCHTAG} ${DH_USERNAME}/${DH_PROJECT}-nightly
}
buildr () {
if [[ -z ${1:-} ]] ; then
echo "Usage: ${0} buildr [version]"
echo "NOTE: The version param will be used for tagging only."
echo "The image will be built from the current packages in the apt-repo."
echo; echo;
return
fi
PLATFORM=""
if [[ "${ARCH}" != "$(uname -m)" ]]; then
PLATFORM="--platform=linux/$ARCH"
fi
echo -ne "\n\nBuilding release image for $ARCH: $1.\n\n"
docker build $PLATFORM \
--build-arg VERSION=$1 \
--build-arg MAKEFLAGS="$MAKEFLAGS" \
-t ${DH_USERNAME}/${DH_PROJECT}:${1}-${ARCH} \
-t ${DH_USERNAME}/${DH_PROJECT}:${1} \
-t ${DH_USERNAME}/${DH_PROJECT} \
--pull -f docker/deb_based/Dockerfile .
}
dev () {
if [[ -z ${1:-} ]] ; then
echo "Usage: ${0} dev [ImageId]"; echo; echo;
docker image ls
return
fi
docker run --rm -it --entrypoint /bin/bash -p 8073:8073 --device /dev/bus/usb ${1}
}
run () {
docker run --rm -it -p 8073:8073 --device /dev/bus/usb openwebrxplus-full:latest-${ARCH}
}
case ${1:-} in
build) buildn ;; # alias for buildn
buildn) buildn ;;
buildr) buildr ${@:2} ;;
dev) dev ${@:2} ;;
run) run ;;
donightly) nightly ;;
dorelease) release ${@:2} ;;
*) usage ;;
esac