-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathDockerfile.alpine
More file actions
130 lines (113 loc) · 5.44 KB
/
Dockerfile.alpine
File metadata and controls
130 lines (113 loc) · 5.44 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
# Stage 1: Build image
ARG SQLITE_YEAR=2026
ARG SQLITE_AUTOCONF_VERSION=3520000
ARG LIBUV_VERSION=1.52.1
ARG LLHTTP_VERSION=9.3.1
FROM alpine:latest AS builder
ARG SQLITE_YEAR
ARG SQLITE_AUTOCONF_VERSION
ARG LIBUV_VERSION
ARG LLHTTP_VERSION
RUN apk update && 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 \
bash
# 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" && \
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 && \
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 mkdir -p /tmp/llhttp/include /tmp/llhttp/src /usr/include && \
wget -q "https://raw.githubusercontent.com/nodejs/llhttp/release/v${LLHTTP_VERSION}/include/llhttp.h" -O /tmp/llhttp/include/llhttp.h && \
wget -q "https://raw.githubusercontent.com/nodejs/llhttp/release/v${LLHTTP_VERSION}/src/llhttp.c" -O /tmp/llhttp/src/llhttp.c && \
wget -q "https://raw.githubusercontent.com/nodejs/llhttp/release/v${LLHTTP_VERSION}/src/api.c" -O /tmp/llhttp/src/api.c && \
wget -q "https://raw.githubusercontent.com/nodejs/llhttp/release/v${LLHTTP_VERSION}/src/http.c" -O /tmp/llhttp/src/http.c && \
cc -fPIC -I/tmp/llhttp/include -c /tmp/llhttp/src/llhttp.c -o /tmp/llhttp/llhttp.o && \
cc -fPIC -I/tmp/llhttp/include -c /tmp/llhttp/src/api.c -o /tmp/llhttp/api.o && \
cc -fPIC -I/tmp/llhttp/include -c /tmp/llhttp/src/http.c -o /tmp/llhttp/http.o && \
cc -shared -Wl,-soname,libllhttp.so.9 -o /usr/lib/libllhttp.so.${LLHTTP_VERSION} /tmp/llhttp/llhttp.o /tmp/llhttp/api.o /tmp/llhttp/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 /tmp/llhttp/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
# Fetch external dependencies
RUN mkdir -p /opt/external && \
# ezxml
cd /opt/external && \
git clone https://github.com/lxfontes/ezxml.git && \
# inih
cd /opt/external && \
git clone https://github.com/benhoyt/inih.git
# 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 -R 777 /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:latest AS final
# Install runtime dependencies
RUN apk update && apk add --no-cache \
ffmpeg-libavformat \
ffmpeg-libavcodec \
ffmpeg-libswscale \
libcurl \
mbedtls \
cjson \
mosquitto-libs \
yaml
# Create necessary directories in runtime
RUN mkdir -p /etc/lightnvr /var/lib/lightnvr/data /var/log/lightnvr /var/run/lightnvr && \
chmod -R 777 /var/lib/lightnvr /var/log/lightnvr /var/run/lightnvr
# Copy compiled binary and config files from builder stage
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/
# Expose required ports
EXPOSE 8080
# Volume for configuration and data persistence
# /etc/lightnvr - Configuration files
# /var/lib/lightnvr/data - Persistent data (database, recordings, models, etc.)
VOLUME /etc/lightnvr
VOLUME /var/lib/lightnvr/data
# Command to start the service
CMD ["/bin/lightnvr", "-c", "/etc/lightnvr/lightnvr.ini"]