Repository navigation
Expand file tree
/
Copy pathDockerfile.alpine
More file actions
150 lines (130 loc) · 6.25 KB
/
Copy pathDockerfile.alpine
File metadata and controls
150 lines (130 loc) · 6.25 KB
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
# Stage 1: Build image
ARG SQLITE_YEAR=2026
ARG SQLITE_AUTOCONF_VERSION=3540100
ARG LIBUV_VERSION=1.53.0
ARG LLHTTP_VERSION=9.4.4
ARG SQLITE_TGZ_SHA256=926ef8d3eab93fbf6e06011901273eec076b25594a4e1cdadd50c987f4f6d64e
ARG LIBUV_TGZ_SHA256=279f3f67a24bb9921fe999ca6cd5e332fade8d515873ef9ba054b70e70a31d9e
ARG LLHTTP_TGZ_SHA256=5600adb1498f82a9c719b8eb19310021737388e0d92362a6d47be532710d3c96
FROM alpine:3.24 AS builder
ARG SQLITE_YEAR
ARG SQLITE_AUTOCONF_VERSION
ARG LIBUV_VERSION
ARG LLHTTP_VERSION
ARG SQLITE_TGZ_SHA256
ARG LIBUV_TGZ_SHA256
ARG LLHTTP_TGZ_SHA256
RUN apk add --no-cache \
git cmake build-base pkgconfig \
ffmpeg-dev \
curl-dev \
mbedtls-dev \
cjson-dev \
mosquitto-dev \
yaml-dev \
linux-headers \
wget ca-certificates tzdata \
bash python3
# Build upstream SQLite because Alpine stable can lag the latest SQLite security fixes
RUN cd /tmp && \
wget -q "https://www.sqlite.org/${SQLITE_YEAR}/sqlite-autoconf-${SQLITE_AUTOCONF_VERSION}.tar.gz" -O "sqlite-autoconf-${SQLITE_AUTOCONF_VERSION}.tar.gz" && \
echo "${SQLITE_TGZ_SHA256} sqlite-autoconf-${SQLITE_AUTOCONF_VERSION}.tar.gz" | sha256sum -c - && \
tar -xzf "sqlite-autoconf-${SQLITE_AUTOCONF_VERSION}.tar.gz" && \
cd "sqlite-autoconf-${SQLITE_AUTOCONF_VERSION}" && \
./configure --prefix=/usr --disable-static && \
make -j"$(nproc)" && \
make install && \
sqlite3 --version
# Build upstream libuv because distro packages can lag the latest stable release
RUN cd /tmp && \
wget -q "https://github.com/libuv/libuv/archive/refs/tags/v${LIBUV_VERSION}.tar.gz" -O libuv.tar.gz && \
echo "${LIBUV_TGZ_SHA256} libuv.tar.gz" | sha256sum -c - && \
tar -xzf libuv.tar.gz && \
cd "libuv-${LIBUV_VERSION}" && \
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=/usr && \
cmake --build build -j"$(nproc)" && \
cmake --install build && \
pkg-config --modversion libuv
# Build upstream llhttp so container builds use the latest parser without relying on distro lag
RUN cd /tmp && \
wget -q "https://github.com/nodejs/llhttp/archive/refs/tags/release/v${LLHTTP_VERSION}.tar.gz" -O llhttp.tar.gz && \
echo "${LLHTTP_TGZ_SHA256} llhttp.tar.gz" | sha256sum -c - && \
tar -xzf llhttp.tar.gz && \
cd "llhttp-release-v${LLHTTP_VERSION}" && \
cc -O2 -fPIC -Iinclude -c src/llhttp.c -o /tmp/llhttp.o && \
cc -O2 -fPIC -Iinclude -c src/api.c -o /tmp/api.o && \
cc -O2 -fPIC -Iinclude -c src/http.c -o /tmp/http.o && \
cc -shared -Wl,-soname,libllhttp.so.9 -o /usr/lib/libllhttp.so.${LLHTTP_VERSION} /tmp/llhttp.o /tmp/api.o /tmp/http.o && \
ln -sf /usr/lib/libllhttp.so.${LLHTTP_VERSION} /usr/lib/libllhttp.so.9 && \
ln -sf /usr/lib/libllhttp.so.${LLHTTP_VERSION} /usr/lib/libllhttp.so && \
install -m 644 include/llhttp.h /usr/include/llhttp.h && \
printf 'prefix=/usr\nexec_prefix=${prefix}\nlibdir=${prefix}/lib\nincludedir=${prefix}/include\n\nName: libllhttp\nDescription: llhttp parser\nVersion: %s\nLibs: -L${libdir} -lllhttp\nCflags: -I${includedir}\n' "$LLHTTP_VERSION" > /usr/lib/pkgconfig/libllhttp.pc && \
pkg-config --modversion libllhttp
# Copy current directory contents into container
WORKDIR /opt
COPY . .
# Clean any existing build files and build the application
RUN mkdir -p /etc/lightnvr /var/lib/lightnvr/data /var/log/lightnvr /var/run/lightnvr && \
chmod 755 /etc/lightnvr && \
chmod -R 750 /var/lib/lightnvr /var/log/lightnvr /var/run/lightnvr && \
# Clean any existing build files
rm -rf build/ && \
# Build the application
# PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH \
./scripts/build.sh --release --with-sod && \
./scripts/install.sh --prefix=/ --without-systemd --without-ldconfig
# Stage 2: Minimal runtime image
FROM alpine:3.24 AS final
# Install runtime dependencies
RUN apk update && apk add --no-cache \
ffmpeg-libavformat \
ffmpeg-libavcodec \
ffmpeg-libswscale \
libcurl \
mbedtls \
cjson \
mosquitto-libs \
yaml \
tzdata
# Create necessary directories in runtime
RUN mkdir -p /etc/lightnvr /var/lib/lightnvr/data /var/log/lightnvr /var/run/lightnvr && \
chmod 755 /etc/lightnvr && \
chmod -R 750 /var/lib/lightnvr /var/log/lightnvr /var/run/lightnvr
# Copy compiled binary and config files from builder stage
RUN apk add --no-cache brotli-libs=1.2.1-r0
COPY --from=builder /bin/lightnvr /bin/lightnvr
COPY --from=builder /usr/bin/sqlite3 /usr/bin/sqlite3
COPY --from=builder /usr/lib/libuv.so* /usr/lib/
COPY --from=builder /usr/lib/libllhttp.so* /usr/lib/
COPY --from=builder /usr/lib/libsqlite3.so* /usr/lib/
COPY --from=builder /etc/lightnvr /etc/lightnvr
COPY --from=builder /var/lib/lightnvr /var/lib/lightnvr
COPY --from=builder /var/log/lightnvr /var/log/lightnvr
COPY --from=builder /var/run/lightnvr /var/run/lightnvr
COPY --from=builder /lib/libsod.so.1.1.9 /lib/libsod.so.1.1.9
COPY --from=builder /lib/libsod.so.1.1.9 /lib/libsod.so.1
COPY --from=builder /lib/libsod.so.1 /lib/libsod.so
# Copy database migrations
COPY --from=builder /opt/db/migrations/ /usr/share/lightnvr/migrations/
# Use a PID location writable by the runtime user.
RUN sed -i 's|/var/run/lightnvr.pid|/var/run/lightnvr/lightnvr.pid|g' /etc/lightnvr/lightnvr.ini
# Expose required ports
EXPOSE 8080
# Run the recorder and its managed go2rtc child without root privileges.
RUN addgroup -g 10001 -S lightnvr && adduser -u 10001 -S -D -H -G lightnvr lightnvr && \
mkdir -p /var/lib/lightnvr/data/recordings /var/lib/lightnvr/data/database \
/var/lib/lightnvr/data/models /var/log/lightnvr /var/run/lightnvr && \
chmod -R go-w /var/lib/lightnvr /var/log/lightnvr /var/run/lightnvr && \
chown -R 10001:10001 /etc/lightnvr /var/lib/lightnvr/data \
/var/log/lightnvr /var/run/lightnvr && \
chmod 755 /var/lib/lightnvr
USER 10001:10001
# Volume for configuration and data persistence
# /etc/lightnvr - Configuration files
# /var/lib/lightnvr/data - Persistent data (database, recordings, models, etc.)
# Declare only the parent: implicit child volumes hide legacy data binds (#946).
# Explicit child mounts in Compose remain supported.
VOLUME /etc/lightnvr
VOLUME /var/lib/lightnvr/data
# Command to start the service
CMD ["/bin/lightnvr", "-c", "/etc/lightnvr/lightnvr.ini"]