-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
100 lines (91 loc) · 3.65 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
FROM alpine:latest
ARG MONITOR_BRANCH=master
VOLUME /config
RUN apk add --no-cache \
openrc \
coreutils \
procps \
gawk \
git \
bash \
curl \
mosquitto \
mosquitto-clients \
bc \
bluez \
bluez-deprecated \
bluez-btmon \
dumb-init \
&& git clone git://github.com/andrewjfreyer/monitor /monitor
COPY entrypoint.sh /entrypoint.sh
ENV PREF_CONFIG_DIR=/config \
PREF_ARRIVAL_SCAN_ATTEMPTS=1 \
PREF_DEPART_SCAN_ATTEMPTS=2 \
PREF_BEACON_EXPIRATION=240 \
PREF_MINIMUM_TIME_BETWEEN_SCANS=15 \
PREF_PASS_FILTER_ADV_FLAGS_ARRIVE=".*" \
PREF_PASS_FILTER_MANUFACTURER_ARRIVE=".*" \
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE="NONE" \
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="NONE" \
MQTT_ADDRESS=0.0.0.0 \
MQTT_PORT=1883 \
MQTT_USER= \
MQTT_PASSWORD= \
MQTT_TOPICPATH=monitor \
MQTT_PUBLISHER_IDENTITY= \
MQTT_CERTIFICATE_PATH= \
MQTT_VERSION= \
LAST_MSG_DELAY=30
RUN cd /monitor \
&& git checkout $MONITOR_BRANCH \
&& touch .pids \
&& touch .previous_version \
# make things executable
&& ln -s /monitor/monitor.sh /usr/local/bin/monitor \
&& chmod a+x monitor.sh \
# link the public name cache to the config directory ... i think there's a bug in monitor.sh where it doesn't consistently reference the same path to this...sometimes it looks in $base_directory (which we have as /config) and sometimes its in the app root (i.e. /monitor)
&& ln -s /config/.public_name_cache .public_name_cache \
# no systemctl ... this keeps the error out about it
&& sed -i 's|systemctl is-active.*|SERVICE_ACTIVE=false|' support/init \
# default config directory to come from an environment variable
&& sed -i 's|PREF_CONFIG_DIR='"''"'|PREF_CONFIG_DIR="${PREF_CONFIG_DIR}"|' support/argv \
# Setting up openrc to work in docker ... https://github.com/dockage/alpine/blob/master/3.9/openrc/Dockerfile
# Start copy/paste from dockage
# Disable getty's
&& sed -i 's/^\(tty\d\:\:\)/#\1/g' /etc/inittab \
&& sed -i \
# Change subsystem type to "docker"
-e 's/#rc_sys=".*"/rc_sys="docker"/g' \
# Allow all variables through
-e 's/#rc_env_allow=".*"/rc_env_allow="\*"/g' \
# Start crashed services
-e 's/#rc_crashed_stop=.*/rc_crashed_stop=NO/g' \
-e 's/#rc_crashed_start=.*/rc_crashed_start=YES/g' \
# Define extra dependencies for services
-e 's/#rc_provide=".*"/rc_provide="loopback net"/g' \
/etc/rc.conf \
# Remove unnecessary services
&& rm -f /etc/init.d/hwdrivers \
/etc/init.d/hwclock \
/etc/init.d/hwdrivers \
/etc/init.d/modules \
/etc/init.d/modules-load \
/etc/init.d/modloop \
# Can't do cgroups
&& sed -i 's/\tcgroup_add_service/\t#cgroup_add_service/g' /lib/rc/sh/openrc-run.sh \
&& sed -i 's/VSERVER/DOCKER/Ig' /lib/rc/sh/init.sh \
# END copy/paste from dockage
# don't set hostname since docker sets it
&& sed -i 's/hostname $opts/# hostname $opts/g' /etc/init.d/hostname \
# don't mount tmpfs since not privileged
&& sed -i 's/mount -t tmpfs/# mount -t tmpfs/g' /lib/rc/sh/init.sh \
# Start up openrc
&& mkdir /run/openrc \
&& touch /run/openrc/softlevel \
&& openrc
WORKDIR /monitor
COPY entrypoint.sh /entrypoint.sh
COPY health.sh /usr/local/bin/health
ENTRYPOINT ["dumb-init", "--", "/entrypoint.sh"]
HEALTHCHECK CMD health
# docker build --tag mashupmill/presence-monitor . && docker run --rm -it --name monitor --net host --privileged --volume ~/monitor/config:/config mashupmill/presence-monitor -b -r