mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 12:17:06 +00:00
82 lines
2.9 KiB
Docker
82 lines
2.9 KiB
Docker
FROM golang:1.24-bookworm AS base
|
|
|
|
RUN apt-get update
|
|
run apt-get install -y libssl-dev cmake build-essential gperf libz-dev make git
|
|
|
|
FROM base AS tdlib
|
|
|
|
ARG TD_COMMIT
|
|
ARG MAKEOPTS
|
|
RUN git clone https://github.com/tdlib/td /src/
|
|
RUN git -C /src/ checkout "${TD_COMMIT}"
|
|
RUN mkdir build
|
|
WORKDIR /build/
|
|
RUN cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/compiled/ /src/
|
|
RUN cmake --build . ${MAKEOPTS}
|
|
RUN make install
|
|
|
|
FROM base AS ntgcalls-build
|
|
ARG MAKEOPTS
|
|
# CMake >= 3.27 required; bookworm ships 3.25
|
|
ARG CMAKE_VERSION=3.31.6
|
|
RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-$(uname -m).tar.gz \
|
|
| tar xz -C /usr/local --strip-components=1
|
|
RUN apt-get install -y libasound2-dev libpulse-dev
|
|
COPY ntgcalls/ /ntgcalls-src/
|
|
WORKDIR /ntgcalls-build/
|
|
RUN cmake -DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_TOOLCHAIN_FILE=/ntgcalls-src/cmake/Toolchain.cmake \
|
|
-DPython_EXECUTABLE=$(which python3) \
|
|
-DSTATIC_BUILD=ON \
|
|
/ntgcalls-src/
|
|
RUN cmake --build . ${MAKEOPTS}
|
|
|
|
FROM base AS deps
|
|
COPY --from=tdlib /compiled/ /usr/local/
|
|
COPY --from=ntgcalls-build /ntgcalls-src/static-output/lib/libntgcalls.a /usr/local/lib/
|
|
COPY --from=ntgcalls-build /ntgcalls-src/static-output/include/ /usr/local/include/
|
|
COPY docker/resolv_shim.c /tmp/resolv_shim.c
|
|
RUN gcc -c -o /tmp/resolv_shim.o /tmp/resolv_shim.c && \
|
|
ar rcs /usr/local/lib/libresolv_shim.a /tmp/resolv_shim.o
|
|
# Needed by gopkg.in/hraban/opus.v2 (cgo pkg-config) and faster final link.
|
|
# Installed here (not in `base`) to keep tdlib/ntgcalls layers cached.
|
|
RUN apt-get install -y libopus-dev libopusfile-dev mold
|
|
# Isolate libntgcalls.a's bundled BoringSSL so its symbols don't displace
|
|
# system OpenSSL at link time (TDLib was built against the latter).
|
|
COPY docker/isolate_ntgcalls_crypto.sh /tmp/isolate_ntgcalls_crypto.sh
|
|
RUN bash /tmp/isolate_ntgcalls_crypto.sh
|
|
|
|
FROM deps AS cache
|
|
COPY ./ /src
|
|
RUN git -C /src submodule update --init
|
|
WORKDIR /src
|
|
RUN --mount=type=cache,target=/go/pkg/mod go get
|
|
|
|
FROM cache AS build
|
|
ARG MAKEOPTS
|
|
ENV CGO_ENABLED=1
|
|
ENV CGO_CFLAGS="-I/usr/local/include"
|
|
ENV CGO_LDFLAGS="-L/usr/local/lib -lntgcalls -lresolv_shim -lstdc++ -lm -ldl -lrt -lpthread -lz -lresolv"
|
|
WORKDIR /src
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
make ${MAKEOPTS}
|
|
|
|
FROM deps AS test
|
|
COPY ./ /src
|
|
WORKDIR /src
|
|
RUN git submodule update --init
|
|
RUN --mount=type=cache,target=/go/pkg/mod go get
|
|
ENV CGO_ENABLED=1
|
|
ENV CGO_CFLAGS="-I/usr/local/include"
|
|
ENV CGO_LDFLAGS="-L/usr/local/lib -lntgcalls -lresolv_shim -lstdc++ -lm -ldl -lrt -lpthread -lz -lresolv"
|
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
make test
|
|
|
|
FROM scratch AS telegabber
|
|
COPY --from=build /src/release/telegabber /usr/local/bin/
|
|
ENTRYPOINT ["/usr/local/bin/telegabber"]
|
|
|
|
FROM scratch AS binaries
|
|
COPY --from=telegabber /usr/local/bin/telegabber /
|