File size: 2,615 Bytes
2791b61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# BEX Engine — Portable Build Container
# Produces binaries compatible with GLIBC 2.31+ (Ubuntu 20.04+, Debian 11+)
#
# Usage:
#   docker build -t bex-builder .
#   docker run --rm -v $(pwd)/dist:/out bex-builder
#
# Or build fully static (musl):
#   docker build --target musl -t bex-builder-musl .
#   docker run --rm -v $(pwd)/dist:/out bex-builder-musl

# ===========================================================================
# Stage 1: GLIBC build (Debian Bullseye = GLIBC 2.31)
# ===========================================================================
FROM rust:1.79-bullseye AS glibc-build

RUN apt-get update -qq && apt-get install -y -qq \
    pkg-config libssl-dev cmake g++ \
    && rm -rf /var/lib/apt/lists/*

# Install wasm tools
RUN cargo install wasm-tools-cli --locked

# Add WASM target
RUN rustup target add wasm32-wasip1

WORKDIR /src
COPY . .

# Build engine (host target)
RUN cargo build --release 2>&1 | tail -5

# Build plugins (WASM target)
RUN cargo build --target wasm32-wasip1 --release \
    -p bex-gogoanime -p bex-kaianime -p bex-hianime \
    -p bex-imdb -p bex-kisskh -p bex-yts -p bex-yflix 2>&1 | tail -5

# Convert to components
RUN bash build-plugins.sh || true

# Copy outputs
RUN mkdir -p /out && \
    cp target/release/bex /out/ 2>/dev/null || true && \
    cp target/release/libbex_runtime.so /out/ 2>/dev/null || true && \
    cp target/release/libbex_runtime.a /out/ 2>/dev/null || true && \
    cp dist/*.bex /out/ 2>/dev/null || true

CMD ["cp", "-r", "/out/.", "/dist/"]

# ===========================================================================
# Stage 2: Musl build (fully static, no GLIBC dependency)
# ===========================================================================
FROM rust:1.79-alpine AS musl

RUN apk add --no-cache musl-dev openssl-dev pkgconf cmake g++ make

RUN rustup target add x86_64-unknown-linux-musl
RUN rustup target add wasm32-wasip1

WORKDIR /src
COPY . .

RUN RUSTFLAGS="-C target-feature=+crt-static" \
    cargo build --release --target x86_64-unknown-linux-musl 2>&1 | tail -5

RUN mkdir -p /out && \
    cp target/x86_64-unknown-linux-musl/release/bex /out/ 2>/dev/null || true && \
    cp target/x86_64-unknown-linux-musl/release/libbex_runtime.a /out/ 2>/dev/null || true

CMD ["cp", "-r", "/out/.", "/dist/"]

# ===========================================================================
# Final: minimal output image
# ===========================================================================
FROM debian:bullseye-slim AS final

COPY --from=glibc-build /out /dist

ENTRYPOINT ["cp", "-r", "/dist/.", "/out/"]