Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

111 line
4.5 KiB

  1. {#
  2. SPDX-FileCopyrightText: 2026 MDAD project contributors
  3. SPDX-FileCopyrightText: 2026 Jason LaGuidice
  4. SPDX-License-Identifier: AGPL-3.0-or-later
  5. #}
  6. # ── Stage 1: builder ─────────────────────────────────────────────────────────
  7. FROM ubuntu:24.04 AS builder
  8. ENV DEBIAN_FRONTEND=noninteractive
  9. RUN apt-get update && apt-get install -y --no-install-recommends \
  10. cmake protobuf-compiler build-essential pkg-config \
  11. git curl ca-certificates \
  12. libolm-dev libclang-dev libssl-dev libunicorn-dev libheif-dev zlib1g-dev \
  13. && rm -rf /var/lib/apt/lists/*
  14. # Rust — install to default ~/.cargo so the Makefile's $(HOME)/.cargo/bin path resolves
  15. RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
  16. | sh -s -- -y --default-toolchain stable
  17. ENV PATH=/root/.cargo/bin:$PATH
  18. # Go — arch-aware, fetches latest stable with fallback
  19. ARG TARGETARCH
  20. RUN set -e; \
  21. GOARCH="${TARGETARCH:-amd64}"; \
  22. GO_VERSION=$(curl -fsSL 'https://go.dev/dl/?mode=json' \
  23. | grep -o '"version":"go[0-9.]*"' | head -1 \
  24. | sed 's/"version":"//;s/"//'); \
  25. : "${GO_VERSION:=go1.25.0}"; \
  26. curl -fsSL "https://go.dev/dl/${GO_VERSION}.linux-${GOARCH}.tar.gz" \
  27. | tar -C /usr/local -xz
  28. ENV PATH=/usr/local/go/bin:$PATH \
  29. GOTOOLCHAIN=local
  30. WORKDIR /build
  31. # ── Rust build layers ─────────────────────────────────────────────────────────
  32. # Copy files that determine whether the clone+patch layer is valid.
  33. # Changing the SHA pin, Makefile, or open-absinthe overlay invalidates this layer.
  34. COPY third_party/rustpush-upstream.sha third_party/
  35. COPY rustpush/ rustpush/
  36. COPY Makefile .
  37. # Clone upstream rustpush at the pinned SHA, apply all patches, overlay open-absinthe.
  38. RUN make ensure-rustpush-source
  39. # Copy Rust crate sources. Changing these invalidates only the Rust build layer,
  40. # not the clone layer above.
  41. COPY pkg/rustpushgo/ pkg/rustpushgo/
  42. COPY nac-validation/ nac-validation/
  43. # Build the Rust static library (~3 min; cached when Rust source is unchanged).
  44. # hardware-key enables the unicorn-based x86 NAC emulator required on Linux
  45. # (both amd64 and arm64 — unicorn supports cross-arch x86 emulation).
  46. RUN cd pkg/rustpushgo && \
  47. cargo build --release --features hardware-key && \
  48. cp target/release/librustpushgo.a /build/librustpushgo.a
  49. # ── Go build layers ───────────────────────────────────────────────────────────
  50. # Download modules first so this layer is cached by go.mod/go.sum.
  51. COPY go.mod go.sum ./
  52. RUN go mod download
  53. # Copy Go source.
  54. COPY cmd/ cmd/
  55. COPY pkg/connector/ pkg/connector/
  56. COPY imessage/ imessage/
  57. COPY ipc/ ipc/
  58. # Build the bridge binary.
  59. ARG BUILD_VERSION=dev
  60. ARG BUILD_COMMIT=unknown
  61. RUN BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) && \
  62. CGO_LDFLAGS="-L/build" \
  63. go build \
  64. -ldflags "-X main.Tag=${BUILD_VERSION} -X main.Commit=${BUILD_COMMIT} -X main.BuildTime=${BUILD_TIME}" \
  65. -o /build/matrix-rustpush \
  66. ./cmd/matrix-rustpush/
  67. # ── Stage 2: runtime ─────────────────────────────────────────────────────────
  68. FROM ubuntu:24.04
  69. ENV DEBIAN_FRONTEND=noninteractive
  70. # Runtime shared libraries the bridge binary needs at startup.
  71. # libunicorn2 — unicorn-engine x86 NAC emulator (hardware-key feature)
  72. # libheif1 — HEIC/HEIF conversion (linked at compile time even when disabled)
  73. # libolm3 — Matrix OLM encryption (mautrix bridgev2 framework)
  74. # libssl3 — OpenSSL (rustpush openssl crate dynamic link)
  75. # ffmpeg — video transcoding
  76. RUN apt-get update && apt-get install -y --no-install-recommends \
  77. libunicorn2 libheif1 libolm3 libssl3 ffmpeg \
  78. ca-certificates openssl curl \
  79. && curl -fsSL 'https://www.apple.com/appleca/AppleIncRootCertificate.cer' \
  80. -o /tmp/AppleRootCA.cer \
  81. && openssl x509 -inform DER -in /tmp/AppleRootCA.cer \
  82. -out /usr/local/share/ca-certificates/AppleRootCA.crt \
  83. && update-ca-certificates \
  84. && rm /tmp/AppleRootCA.cer \
  85. && rm -rf /var/lib/apt/lists/*
  86. COPY --from=builder /build/matrix-rustpush /usr/local/bin/matrix-rustpush
  87. WORKDIR /data
  88. VOLUME /data
  89. EXPOSE 29332
  90. ENTRYPOINT ["matrix-rustpush", "-c", "/data/config.yaml"]