從原始碼建置

本頁說明如何從原始碼建置並執行 Antimatter,以便進行開發或製作自訂版本。內容涵蓋位於同一個儲存庫中的伺服器與網頁介面,以及 Docker 映像檔與應用程式。

所需條件

  • 前往,使用 server/go.mod 中的版本(撰寫本文時為 1.26.7)。
  • Node.js 與 npm,版本需與 .nvmrc 和 webapp/package.json 中指定的一致(Node 24.11.1 搭配 npm 11.6.2)。若使用 mise,儲存庫中的 mise.toml 會安裝正確的 Node 版本。
  • Docker 與 Compose:開發環境會在容器中執行 PostgreSQL 及其他幾項服務。
  • make、git,以及一台 Linux 或 macOS 電腦。
  • 記憶體:建置網頁介面是最耗資源的部分。建議規劃 16 GB 的 RAM;請參閱 建置與記憶體。
git clone https://github.com/AntimatterChat/antimatter.git
cd antimatter

儲存庫包含位於 server/ 的伺服器、位於 webapp/ 的網頁介面(Fusion 位於 webapp/fusion,經典介面位於 webapp/channels,共用套件位於 webapp/platform),以及位於 e2e-tests/ 的端對端測試。

執行開發伺服器

cd server
make run

make run 會啟動開發容器(PostgreSQL、Redis、郵件攔截器與監控工具),將網頁應用程式的建置檔連結到正確位置,在背景使用 go run 啟動伺服器,並啟動網頁應用程式的觀察器(watcher),在您編輯時重新建置經典介面。開啟 http://localhost:8065 並建立帳號:第一個建立的帳號將成為系統管理員。

指令(位於 server/)功能說明
make run-server, make run-client僅啟動伺服器,或僅啟動網頁應用程式觀察器。
make restart-server在修改 Go 程式碼後重新啟動伺服器。
make stop停止伺服器、觀察器與容器。
make debug-server在 Delve 除錯器下執行伺服器。
make run-cli ARGS="-version"執行伺服器指令。
make config-reset將 config/config.json 重設為預設值。
make clean, make nuke移除建置檔;nuke 也會刪除開發資料。

開發資料庫為 postgres://mmuser:mostest_password@localhost/mattermost_test,這是伺服器的預設資料來源。您可以透過 ENABLED_DOCKER_SERVICES 選擇要啟動哪些容器,設定方式為在 server/config.override.mk 檔案中或您的環境變數中(請參閱 server/config.mk)。

網頁介面

位於 webapp/ 中:

npm install      # also builds the shared packages
npm run build    # the classic interface, then Fusion

建置結果會輸出至 webapp/channels/dist(經典版)和 webapp/fusion/dist(Fusion)。在 server/ 中執行 make client 會將它們連結為 server/client 和 server/client-fusion,供伺服器提供服務:經典版位於 /static/,Fusion 位於 /static/fusion/。

  • npm run run(或在 webapp/ 中執行 make run)會監視並重新建置經典介面。加上 WATCH_FUSION=true 即可同時重新建置 Fusion。
  • npm run dev-server(make dev)會改用 webpack 開發伺服器:經典版使用埠 9005,Fusion 使用埠 9006。
  • 要在瀏覽器中檢視其中一個介面,請在任意頁面的網址後加上 ?webui=fusion 或 ?webui=classic。

測試與檢查

指令位置功能說明
make test-serverserver/針對開發容器執行伺服器的測試套件。此過程耗時較長。
make test-server-quickserver/僅執行快速測試。
go test ./channels/app/... -run TestNameserver/執行單一套件或測試,需先啟動容器(make start-docker)。
make check-styleserver/go vet、golangci-lint 及其他 Go 檢查。
make testwebapp/Web 應用程式的單元測試(Jest),涵蓋所有套件。
npm run test -- <pattern>webapp/fusionFusion 的部分測試。
make check-style, make check-typeswebapp/ESLint 和 TypeScript。
make i18n-extractserver/ 和 webapp/在新增或變更字串後,更新英文字串檔案(請參閱 翻譯)。

請在 server/ 中執行 make modules-tidy,而非 go mod tidy。

發行版檔案

cd webapp && npm run build && cd ..
cd server
make build-linux       # the antimatter and amctl binaries
make package-linux     # dist/antimatter-linux-amd64.tar.gz and -arm64

make build 會一次建置網頁介面與 Linux 二進位檔。該壓縮檔包含 bin/antimatter、bin/amctl、預設的 config/config.json(附有一份關於如何變更設定的 README.md)、兩種網頁介面、模板、字型與翻譯檔。其他平台:make package-osx、make package-windows、make package-freebsd。

內建應用程式

單純執行 make package-linux 會建置一個不含應用程式的壓縮檔。若要像正式發行版那樣將應用程式打包,請先取得已簽章的應用程式套件,並指定其資料夾:

build/package/fetch-apps.sh "$HOME/release-apps"   # needs gh, python3 and gpg
make package-linux PREPACKAGED_PLUGINS_DIR="$HOME/release-apps"

fetch-apps.sh 會下載 antimatter-docker 的 plugins.json 中列出的每個應用程式的最新 GitHub 發行版及其簽章,並使用 Antimatter 的插件金鑰驗證簽章。預設會取得 Whiteboard、Voice channels、Calls、Agents、Todo、Polls、Notes、GIFs 和 Memes;可透過 AM_BUNDLED_APPS(以空格分隔的儲存庫名稱)變更此清單。沒有發行版或沒有簽章的應用程式會被略過並顯示警告。這些套件會放入壓縮檔的 prepackaged_plugins/ 資料夾中。

.deb 與 .rpm 套件

build/package/build-packages.sh <archive> <amd64|arm64> <version> <out-dir> 會使用 nfpm 將發行壓縮檔轉換為整合式的 .deb 與 .rpm 套件。管理員指南中說明了這些套件會安裝哪些內容:請參閱 安裝 .deb 或 .rpm 套件。

發行工作流程

伺服器儲存庫中的 antimatter-release.yml 工作流程會在 GitHub 上執行所有這些步驟:當出現 v* 標籤時,它會為 amd64 和 arm64 建置壓縮檔與套件,附上 SHA256SUMS,並將其發佈為該標籤的 GitHub 發行版(若版本號包含 -,則為預發行版)。若手動執行,它會將建置編號設為 0.9.0-dev.<run>,並將檔案保留為工作流程產物。每個應用程式儲存庫都有一個 release.yml 工作流程,以相同方式發佈其已簽章的套件。

Docker 映像檔

antimatter-docker 儲存庫會在 Docker 內完整建置已發布的映像檔,包含伺服器及其應用程式:

git clone https://github.com/AntimatterChat/antimatter-docker.git
cd antimatter-docker
scripts/build-all.sh                     # from the main branches on GitHub
SOURCES=local scripts/build-all.sh       # from your checkouts next to this folder
VARIANT=next scripts/build-all.sh        # the "next" image, with every Antimatter app

需要支援 buildx 的 Docker、Python 3、git 和 gpg,約 16 GB 的 RAM 和 30 GB 的磁碟空間。結果會載入為 ghcr.io/antimatterchat/antimatter:dev;可使用 ANTIMATTER_IMAGE=ghcr.io/antimatterchat/antimatter:dev docker compose -f compose.local.yml up -d 進行測試。plugins.json 列出已建置的應用程式及其版本,儲存庫的 README 則說明各種變體。

build-all.sh 會使用 Antimatter 簽章金鑰對隨附的應用程式進行簽章,而映像檔建置會拒絕未簽章的應用程式。若沒有該私鑰(僅維護者持有),請單獨執行前幾個步驟:scripts/fetch-sources.sh、scripts/build-plugins.sh(應用程式套件位於 out/plugins/)以及 scripts/build-server.sh(伺服器壓縮檔位於 out/server/)。

建置與記憶體

網頁介面是大型 webpack 建置,記憶體不足是最常見的建置失敗原因。

  • npm run build 會依序建置經典介面與 Fusion,而非同時進行,以降低峰值記憶體使用量。請勿自行並行執行。
  • 壓縮工具會為每個處理器核心啟動一個工作程序。在核心數多但記憶體少的機器上,請限制建置可見的處理器數量:taskset -c 0-5 npm run build。
  • 如果 Node 堆積空間不足,請提高其限制:NODE_OPTIONS=--max-old-space-size=6144。Docker 建置使用此值(位於 build.env 中的 BUILD_NODE_OPTIONS)。
  • 避免在小機器上同時執行伺服器的完整測試套件、網頁建置和 Docker 建置。

應用程式

每個應用程式(外掛)都有各自的儲存庫和 Makefile;make dist 會建置其套件。請參閱 建置、安裝與除錯。

桌面應用程式

桌面應用程式 是一個 Electron 應用程式。使用 Node.js 24 或更高版本:

npm install --allow-git=all
npm run build          # development build, into dist/
npm start              # run it
npm run package:linux  # packages into release/ (also package:windows, package:mac)

建置時的設定(例如要預先設定的伺服器)位於 src/common/config/buildConfig.ts。若沒有 Apple 憑證,請設定 AM_MAC_ADHOC_SIGN=true,以對 macOS 應用程式進行 ad hoc 簽章(不進行認證):Apple 晶片 Mac 會拒絕執行未簽章的程式碼。儲存庫中的 release.yml 工作流會在 v* 標籤上,為 Linux、Windows 和 macOS 建置未簽章的套件。

行動應用程式

行動應用程式 是一款 React Native 應用程式;其 README 列出了相關指令(npm run ios、npm run android)。若要建置自己的版本,您還需要自己的簽章金鑰、用於 Android 通知的 Firebase 專案、用於 iOS 的 APNs 金鑰,以及一個持有這些憑證的推送代理。儲存庫中的 release.yml 工作流會在 v* 標籤上,建置 Android APK 和 AAB,以及未簽章的 iOS .ipa(無需商店帳號);其 README 列出了用於簽章 Android 建置並設定 Firebase 的密鑰。