-
Notifications
You must be signed in to change notification settings - Fork 37
/
Dockerfile
257 lines (248 loc) · 13.3 KB
/
Dockerfile
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Declare the telegraf image so we can copy telegraf binary out of it,
# and avoid headache of having to add apt key / apt repo and/or build from src.
# hadolint ignore=DL3008,SC2086,SC2039,SC2068,DL3006
FROM telegraf AS telegraf
RUN touch /tmp/.nothing
# Build final image
# hadolint ignore=DL3008,SC2086,SC2039,SC2068,DL3006
FROM ghcr.io/sdr-enthusiasts/docker-baseimage:readsb-full
# Copy telegraf
COPY --from=telegraf /usr/bin/telegraf /usr/bin/telegraf
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \
###########################################################################
##### READSBRRD ENVIRONMENT VARS #####
READSBRRD_STEP=60 \
###########################################################################
##### READSB GRAPH ENVIRONMENT VARS #####
READSB_GRAPH_SIZE="default" \
READSB_GRAPH_ALL_LARGE="no" \
READSB_GRAPH_FONT_SIZE=10.0 \
READSB_GRAPH_MAX_MESSAGES_LINE=0 \
READSB_GRAPH_LARGE_WIDTH=1096 \
READSB_GRAPH_LARGE_HEIGHT=235 \
READSB_GRAPH_SMALL_WIDTH=619 \
READSB_GRAPH_SMALL_HEIGHT=324 \
###########################################################################
##### AUTOGAIN ENVIRONMENT VARS #####
# How often the autogain.sh is run (in seconds)
AUTOGAIN_SERVICE_PERIOD=900 \
# The autogain state file (init/finetune/finish)
AUTOGAIN_STATE_FILE="/run/autogain/state" \
# The current gain figure as-set by autogain
AUTOGAIN_CURRENT_VALUE_FILE="/run/autogain/autogain_current_value" \
# The timestamp (seconds since epoch) when the current gain figure was set
AUTOGAIN_CURRENT_TIMESTAMP_FILE="/run/autogain/autogain_current_timestamp" \
# The timestamp (seconds since epoch) when the current gain figure should be reviewed
AUTOGAIN_REVIEW_TIMESTAMP_FILE="/run/autogain/autogain_review_timestamp" \
# The maximum allowable percentage of strong messages
AUTOGAIN_PERCENT_STRONG_MESSAGES_MAX=10.0 \
# The minimum allowable percentage of strong messages
AUTOGAIN_PERCENT_STRONG_MESSAGES_MIN=0.5 \
# The number of seconds that autogain "init" stage should run for, for each gain level
AUTOGAIN_INITIAL_PERIOD=7200 \
# The minimum number of local_accepted messages that autogain "init" stage should run for, for each gain level
AUTOGAIN_INITIAL_MSGS_ACCEPTED=1000000 \
# The number of seconds that autogain "finetune" stage should run for, for each gain level
AUTOGAIN_FINETUNE_PERIOD=604800 \
# The minimum number of local_accepted messages that autogain "finetune" stage should run for, for each gain level
AUTOGAIN_FINETUNE_MSGS_ACCEPTED=7000000 \
# How long to run once finetune stage has finished before we start the process over (1 year)
AUTOGAIN_FINISHED_PERIOD=31536000 \
# Maximum gain level that autogain should use
AUTOGAIN_MAX_GAIN_VALUE=49.6 \
# Minimum gain level that autogain should use
AUTOGAIN_MIN_GAIN_VALUE=0.0 \
# State file that will disappear when the container is rebuilt/restarted - so autogain can detect container restart/rebuild
AUTOGAIN_RUNNING_FILE="/tmp/.autogain_running" \
# maximum accepted gain value
AUTOGAIN_MAX_GAIN_VALUE_FILE="/run/autogain/autogain_max_value" \
# minimum accepted gain value
AUTOGAIN_MIN_GAIN_VALUE_FILE="/run/autogain/autogain_min_value" \
###########################################################################
# Protobuf data from readsb
READSB_STATS_PB_FILE="/run/readsb/stats.pb" \
# Protobuf definition
READSB_PROTO_PATH="/opt/readsb-protobuf" \
# Current gain value
GAIN_VALUE_FILE="/tmp/.gain_current" \
###########################################################################
# default BEAST out port
READSB_NET_BEAST_OUTPUT_PORT=30005 \
# default BaseStation out port
READSB_NET_SBS_OUTPUT_PORT=30003 \
# default RAW out put
READSB_NET_RAW_OUTPUT_PORT=30002 \
###########################################################################
PROMETHEUSPORT=9273 \
PROMETHEUSPATH="/metrics"
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Copy container filesystem
COPY rootfs/ /
# hadolint ignore=DL3008,SC2086,SC2039,SC2068,DL3007,DL3008,DL3006
RUN set -x && \
TEMP_PACKAGES=() && \
KEPT_PACKAGES=() && \
# Required for automatic gain script (to interpret .pb files).
KEPT_PACKAGES+=(protobuf-compiler) && \
# Required for downloading stuff & readsb database updates
KEPT_PACKAGES+=(git) && \
# Required for building multiple packages.
TEMP_PACKAGES+=(build-essential) && \
TEMP_PACKAGES+=(pkg-config) && \
TEMP_PACKAGES+=(cmake) && \
TEMP_PACKAGES+=(autoconf) && \
TEMP_PACKAGES+=(automake) && \
# Packages for readsb web interface & graphs.
KEPT_PACKAGES+=(lighttpd) && \
KEPT_PACKAGES+=(lighttpd-mod-magnet) && \
KEPT_PACKAGES+=(collectd-core) && \
KEPT_PACKAGES+=(rrdtool) && \
KEPT_PACKAGES+=(jq) && \
# Packages for telegraf
TEMP_PACKAGES+=(apt-transport-https) && \
KEPT_PACKAGES+=(socat) && \
TEMP_PACKAGES+=(gnupg) && \
# Requirements for kalibrate-rtl
TEMP_PACKAGES+=(libtool) && \
KEPT_PACKAGES+=(libfftw3-bin) && \
TEMP_PACKAGES+=(libfftw3-dev) && \
TEMP_PACKAGES+=(libusb-1.0-0-dev) && \
# Install packages.
apt-get update && \
apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y --no-install-recommends \
${KEPT_PACKAGES[@]} \
${TEMP_PACKAGES[@]} \
&& \
# grab the bias t scripts
curl -o /etc/s6-overlay/scripts/05-rtlsdr-biastee-init https://raw.githubusercontent.com/sdr-enthusiasts/sdre-bias-t-common/main/09-rtlsdr-biastee-init && \
curl -o /etc/s6-overlay/scripts/05-rtlsdr-biastee-down https://raw.githubusercontent.com/sdr-enthusiasts/sdre-bias-t-common/main/09-rtlsdr-biastee-down && \
chmod +x /etc/s6-overlay/scripts/05-rtlsdr-biastee-init && \
chmod +x /etc/s6-overlay/scripts/05-rtlsdr-biastee-down && \
git config --global advice.detachedHead false && \
# Build & install kalibrate-rtl
# See: https://discussions.flightaware.com/t/setting-frequency-offset-or-exact-frequency-ppm/15812/6
git clone https://github.com/steve-m/kalibrate-rtl.git "/src/kalibrate-rtl" && \
pushd "/src/kalibrate-rtl" && \
echo "kalibrate-rtl $(git log | head -1 | tr -s ' ' '_')" >> /VERSIONS && \
./bootstrap && \
./configure && \
make all install && \
popd && \
# readsb - Deploy webapp.
ln -s /etc/lighttpd/conf-available/01-setenv.conf /etc/lighttpd/conf-enabled/01-setenv.conf && \
ln -s /etc/lighttpd/conf-available/87-cachebust.conf /etc/lighttpd/conf-enabled/87-cachebust.conf && \
ln -s /etc/lighttpd/conf-available/89-readsb.conf /etc/lighttpd/conf-enabled/89-readsb.conf && \
ln -s /etc/lighttpd/conf-available/88-readsb-statcache.conf /etc/lighttpd/conf-enabled/88-readsb-statcache.conf && \
# Healthcheck stuff
mkdir -p /etc/lighttpd/lua && \
echo -e 'server.modules += ("mod_magnet")\n\n$HTTP["url"] =~ "^/health/?" {\n magnet.attract-physical-path-to = ("/etc/lighttpd/lua/healthcheck.lua")\n}' > /etc/lighttpd/conf-enabled/90-healthcheck.conf && \
echo -e 'lighty.content = { "OK" }\nreturn 200' > /etc/lighttpd/lua/healthcheck.lua && \
# readsb - users/permissions/dirs.
addgroup --system --gid 1000 readsb && \
useradd \
--uid 1000 \
--system \
--home-dir /usr/share/readsb \
--no-create-home \
--no-user-group \
--gid 1000 \
--groups plugdev,dialout \
readsb \
&& \
mkdir -p "/var/lib/collectd/rrd/localhost/readsb" && \
chmod -R 755 "/var/lib/collectd" && \
chown readsb "/var/lib/collectd" && \
chown -R readsb: "/usr/share/readsb" && \
mkdir -p "/run/readsb" && \
chmod -R 755 "/run/readsb" && \
chown -R readsb: "/run/readsb" && \
touch "/etc/default/readsb" && \
chown -R readsb: "/etc/default/readsb" && \
# lighttpd configuration - PID file location + permissions.
sed -i 's/^server\.pid-file.*/server.pid-file = "\/var\/run\/lighttpd\/lighttpd.pid"/g' /etc/lighttpd/lighttpd.conf && \
mkdir -p "/var/run/lighttpd" && \
chown readsb "/var/run/lighttpd" && \
# lighttpd configuration - mod_compress location + permissions.
mkdir -p "/var/cache/lighttpd/compress/script/readsb/backend" && \
mkdir -p "/var/cache/lighttpd/compress/css/bootstrap" && \
mkdir -p "/var/cache/lighttpd/compress/css/leaflet" && \
chown -R readsb:www-data "/var/cache/lighttpd" && \
chmod -R u+rwx,g+rwx "/var/cache/lighttpd" && \
# lighttpd configuration - remove "unconfigured" conf.
rm -v "/etc/lighttpd/conf-enabled/99-unconfigured.conf" && \
# lighttpd configuration - change server port (needs to be a high port as this is a rootless container).
sed -i 's/^server\.port.*/server.port = 8080/g' /etc/lighttpd/lighttpd.conf && \
# lighttpd configuration - remove errorlog, lighttpd runs in the foreground so errors will show in container log.
sed -i 's/^server\.errorlog.*//g' /etc/lighttpd/lighttpd.conf && \
# collectd configuration - move collectd DataDir under /run & set correct permissions.
mv -v "/var/lib/collectd" "/run" && \
chown -R readsb "/run/collectd" && \
ln -s "/run/collectd" "/var/lib" && \
# copy our config in & remove empty dir
mv -v /etc/collectd.readsb/collectd.conf /etc/collectd/collectd.conf && \
rmdir /etc/collectd.readsb && \
# collectd configuration - remove unneeded readsb plugins.
sed -i 's/^LoadPlugin syslog.*//g' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
sed -i 's/^LoadPlugin exec.*//g' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
sed -i 's/^LoadPlugin curl.*//g' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
# collectd configuration - remove syslog configuration from readsb config (as we'll be logging to stdout/container log).
sed -i '/<Plugin syslog>/,/<\/Plugin>/d' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
# collectd configuration - change default disk from mmcblk0 to add more standard disks.
sed -i 's/Disk "mmcblk0"/Disk "mmcblk0"\n\tDisk "mmcblk1"\n\tDisk "sda"\n\tDisk "hda"/g' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
# collectd configuration - add gain (using the file created by autogain start script and updates)
sed -i 's/<Chain "PostCache">/<Plugin table>\n\t<Table "\/tmp\/.gain_current">\n\t\tInstance localhost\n\t\tSeparator " "\n\t\t<Result>\n\t\t\tType gauge\n\t\t\tInstancePrefix "gain"\n\t\t\tValuesFrom 0\n\t\t<\/Result>\n\t<\/Table>\n<\/Plugin>\n\n<Chain "PostCache">/g' /etc/collectd/collectd.conf.d/readsb.collectd.conf && \
# graphs.sh - add required configuration for gain to be added to graphs
sed -i '/--vertical-label "dBFS"/ {N; s/--right-axis 1:0 \\/--right-axis 1.2:50 \\\n\t\t--right-axis-label "dB" \\/}' /usr/share/readsb/graphs/graphs.sh && \
sed -i 's/"DEF:peak=$(check $2\/dbfs_max_signal.rrd):value:MAX" \\/"DEF:peak=$(check $2\/dbfs_max_signal.rrd):value:MAX" \\\n "DEF:dgain=$(check \/var\/run\/collectd\/rrd\/localhost\/table-localhost\/gauge-gain.rrd):value:AVERAGE" \\/g' /usr/share/readsb/graphs/graphs.sh && \
sed -i 's/"CDEF:mes=median,UN,signal,median,IF" \\/"CDEF:mes=median,UN,signal,median,IF" \\\n\t\t"CDEF:gain=dgain,1.2,*,50,-" \\/g' /usr/share/readsb/graphs/graphs.sh && \
sed -i 's/"GPRINT:peak:MAX:%4.1lf\\c" \\/"GPRINT:peak:MAX:%4.1lf\\c" \\\n\t\t"LINE1:gain#$RED:Gain Level (RHS)\\:" \\\n\t\t"GPRINT:dgain:LAST:%4.1lf\\c" \\/g' /usr/share/readsb/graphs/graphs.sh && \
# set up auto-gain file structure
mkdir -p "/run/autogain" && \
chown readsb "/run/autogain" && \
# Configure telegraf
mkdir -p /etc/telegraf/telegraf.d && \
mv -v /etc/telegraf.readsb/telegraf.conf /etc/telegraf/telegraf.conf && \
rmdir /etc/telegraf.readsb && \
echo "telegraf --version" >> /VERSIONS && \
# Update readsb webapp databases
# attempt download of aircrafts.json
curl \
--location \
-o /usr/share/readsb/html/db/aircrafts.json \
-z /usr/share/readsb/html/db/aircrafts.json \
'https://github.com/Mictronics/readsb-protobuf/raw/dev/webapp/src/db/aircrafts.json' \
&& \
# attempt download of dbversion.json
curl \
--location \
-o /usr/share/readsb/html/db/dbversion.json \
-z /usr/share/readsb/html/db/dbversion.json \
'https://github.com/Mictronics/readsb-protobuf/raw/dev/webapp/src/db/dbversion.json' \
&& \
# attempt download of operators.json
curl \
--location \
-o /usr/share/readsb/html/db/operators.json \
-z /usr/share/readsb/html/db/operators.json \
'https://github.com/Mictronics/readsb-protobuf/raw/dev/webapp/src/db/operators.json' \
&& \
# attempt download of types.json
curl \
--location \
-o /usr/share/readsb/html/db/types.json \
-z /usr/share/readsb/html/db/types.json \
'https://github.com/Mictronics/readsb-protobuf/raw/dev/webapp/src/db/types.json' \
&& \
# Clean-up.
apt-get remove -y ${TEMP_PACKAGES[@]} && \
apt-get autoremove -y && \
rm -rf /src/* /tmp/* /var/lib/apt/lists/* && \
# Document versions.
echo "readsb $(readsb --version | cut -d ' ' -f 2)" >> /VERSIONS && \
cat /VERSIONS && \
readsb --version | cut -d ' ' -f 2 > /CONTAINER_VERSION
# Set s6 init as entrypoint
ENTRYPOINT [ "/init" ]
# Add healthcheck
HEALTHCHECK --start-period=3600s --interval=600s CMD /scripts/healthcheck.sh
# This container can't be rootless - readsb can't talk to RTLSDR if USER is set :-(