Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

110 строки
4.5 KiB

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