|
| 1 | +# ============================================================================== |
| 2 | +# Docker cross-build for x86_64-unknown-linux-gnu |
| 3 | +# |
| 4 | +# On Apple Silicon, this uses QEMU emulation (--platform linux/amd64) — |
| 5 | +# slower than the native arm64 Docker build but functional. |
| 6 | +# Base image matches target OS (Debian 13 trixie). |
| 7 | +# |
| 8 | +# Usage: |
| 9 | +# task build:linux-amd64 |
| 10 | +# # or manually: |
| 11 | +# docker build --platform linux/amd64 \ |
| 12 | +# -f docker/Dockerfile.linux-amd64 \ |
| 13 | +# --target artifacts --output type=local,dest=dist/linux-amd64 . |
| 14 | +# ============================================================================== |
| 15 | + |
| 16 | +# ------------------------------------------------------------------------------ |
| 17 | +# Stage 1: Build environment |
| 18 | +# ------------------------------------------------------------------------------ |
| 19 | +FROM debian:trixie-slim AS builder |
| 20 | + |
| 21 | +ENV DEBIAN_FRONTEND=noninteractive |
| 22 | + |
| 23 | +# -- System packages: build tools -- |
| 24 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 25 | + build-essential \ |
| 26 | + pkg-config \ |
| 27 | + cmake \ |
| 28 | + mold \ |
| 29 | + curl \ |
| 30 | + wget \ |
| 31 | + file \ |
| 32 | + ca-certificates \ |
| 33 | + git \ |
| 34 | + unzip \ |
| 35 | + xz-utils \ |
| 36 | + && rm -rf /var/lib/apt/lists/* |
| 37 | + |
| 38 | +# -- System packages: Tauri + audio dev libraries -- |
| 39 | +ARG WEBKIT_VERSION=4.1 |
| 40 | +ARG SOUP_VERSION=3.0 |
| 41 | + |
| 42 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 43 | + libjavascriptcoregtk-${WEBKIT_VERSION}-dev \ |
| 44 | + libwebkit2gtk-${WEBKIT_VERSION}-dev \ |
| 45 | + libsoup-${SOUP_VERSION}-dev \ |
| 46 | + libgtk-3-dev \ |
| 47 | + libasound2-dev \ |
| 48 | + libdbus-1-dev \ |
| 49 | + libayatana-appindicator3-dev \ |
| 50 | + zlib1g-dev \ |
| 51 | + libutfcpp-dev \ |
| 52 | + libssl-dev \ |
| 53 | + librsvg2-dev \ |
| 54 | + && rm -rf /var/lib/apt/lists/* |
| 55 | + |
| 56 | +# -- Rust (nightly) -- |
| 57 | +ENV RUSTUP_HOME=/usr/local/rustup \ |
| 58 | + CARGO_HOME=/usr/local/cargo \ |
| 59 | + PATH="/usr/local/cargo/bin:${PATH}" |
| 60 | + |
| 61 | +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ |
| 62 | + | sh -s -- -y --default-toolchain nightly --profile minimal \ |
| 63 | + && rustup target add x86_64-unknown-linux-gnu |
| 64 | + |
| 65 | +# -- Zig -- |
| 66 | +ARG ZIG_VERSION=0.14.0 |
| 67 | +RUN curl -sSL "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar.xz" \ |
| 68 | + | tar -xJ -C /opt \ |
| 69 | + && ln -s /opt/zig-linux-x86_64-${ZIG_VERSION}/zig /usr/local/bin/zig |
| 70 | + |
| 71 | +# -- Node.js -- |
| 72 | +ARG NODE_MAJOR=24 |
| 73 | +RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash - \ |
| 74 | + && apt-get install -y --no-install-recommends nodejs \ |
| 75 | + && rm -rf /var/lib/apt/lists/* |
| 76 | + |
| 77 | +# -- Deno -- |
| 78 | +RUN curl -fsSL -L https://github.com/denoland/deno/releases/latest/download/deno-x86_64-unknown-linux-gnu.zip \ |
| 79 | + -o /tmp/deno.zip \ |
| 80 | + && unzip -o /tmp/deno.zip -d /usr/local/bin \ |
| 81 | + && chmod +x /usr/local/bin/deno \ |
| 82 | + && rm /tmp/deno.zip |
| 83 | + |
| 84 | +# -- Last.fm API keys (embedded at compile time via build.rs) -- |
| 85 | +ARG LASTFM_API_KEY |
| 86 | +ARG LASTFM_API_SECRET |
| 87 | +ENV LASTFM_API_KEY=${LASTFM_API_KEY} |
| 88 | +ENV LASTFM_API_SECRET=${LASTFM_API_SECRET} |
| 89 | + |
| 90 | +# -- Build environment -- |
| 91 | +ENV RUSTUP_TOOLCHAIN=nightly \ |
| 92 | + RUSTFLAGS="-Zthreads=16" |
| 93 | + |
| 94 | +WORKDIR /build |
| 95 | + |
| 96 | +# -- Layer: dependency files (cached unless deps change) -- |
| 97 | +COPY Cargo.toml Cargo.lock ./ |
| 98 | +COPY crates/mt-core/Cargo.toml crates/mt-core/ |
| 99 | +COPY crates/mt-core/build.rs crates/mt-core/ |
| 100 | +COPY crates/mt-tauri/Cargo.toml crates/mt-tauri/ |
| 101 | +COPY crates/mt-tauri/.cargo crates/mt-tauri/.cargo/ |
| 102 | + |
| 103 | +# Stub source files for cargo fetch |
| 104 | +RUN mkdir -p crates/mt-core/src && echo "pub fn stub() {}" > crates/mt-core/src/lib.rs \ |
| 105 | + && mkdir -p crates/mt-tauri/src && echo "fn main() {}" > crates/mt-tauri/src/main.rs \ |
| 106 | + && echo "" > crates/mt-tauri/src/lib.rs |
| 107 | + |
| 108 | +RUN cargo fetch --target x86_64-unknown-linux-gnu |
| 109 | + |
| 110 | +# Frontend deps |
| 111 | +COPY deno.jsonc deno.lock ./ |
| 112 | +COPY app/frontend/package.json app/frontend/package-lock.json app/frontend/ |
| 113 | + |
| 114 | +RUN deno install --node-modules-dir=auto |
| 115 | + |
| 116 | +# -- Layer: full source -- |
| 117 | +RUN rm -rf crates/mt-core/src crates/mt-tauri/src |
| 118 | + |
| 119 | +COPY crates/ crates/ |
| 120 | +COPY app/ app/ |
| 121 | +COPY zig-core/ zig-core/ |
| 122 | +COPY scripts/ scripts/ |
| 123 | +COPY static/ static/ |
| 124 | + |
| 125 | +# -- Build TagLib for Linux (force — ignore any host-platform .a files) -- |
| 126 | +RUN bash scripts/build-taglib.sh --force |
| 127 | + |
| 128 | +# -- Build frontend -- |
| 129 | +RUN cd app/frontend && npm run build |
| 130 | + |
| 131 | +# -- Build Tauri app -- |
| 132 | +RUN deno run -A npm:@tauri-apps/cli build \ |
| 133 | + --target x86_64-unknown-linux-gnu \ |
| 134 | + --bundles deb |
| 135 | + |
| 136 | +# ------------------------------------------------------------------------------ |
| 137 | +# Stage 2: Artifact extraction |
| 138 | +# ------------------------------------------------------------------------------ |
| 139 | +FROM scratch AS artifacts |
| 140 | + |
| 141 | +COPY --from=builder /build/target/x86_64-unknown-linux-gnu/release/bundle/deb/*.deb / |
| 142 | +COPY --from=builder /build/target/x86_64-unknown-linux-gnu/release/mt-tauri /mt-tauri |
0 commit comments