LoginSignup
4
2

More than 3 years have passed since last update.

MattermostをRaspberry Pi3用にビルドする

Last updated at Posted at 2018-04-15

MattermostをRaspberry Pi3用にビルドする

Slack互換のMattermostをdockerコンテナで実装したmattermost-dockerをRasuperry Pi3で動かしてみます。そのために、ラズパイ用のmattermostをビルドしますが、ここでの作業は、Windows上のVirutualBoxにインストールしたUbuntu 16.04 LTSを使用しています。

ここでビルドしたMattermostのパッケージを使って、ラズパイ用のdockerコンテナを作成して動かします。

参考:Mattermost-dockerをRaspberry Pi3で動かす

1. 開発環境の準備

Mattermost公式のInstalling Developer Components on Ubuntu 16.04に従って必要な環境を設定します。最初にmattermost-serverをビルドするための開発環境をWindows上のVirtualBoxにインストールしたUbuntu 16.04LTSに設定しています。

1.1 Ubuntuの初期設定

まずUbuntuの初期設定として、事前に作成したシェルスクリプトを実行します。

git clone https://github.com/tkyonezu/Linux-tools.git
cd Linux-tools
sudo bash ubuntu-setup.sh <ホスト名> <ユーザー名>

引数のホスト名とユーザー名には、Ubuntuをインストールした際のホスト名とユーザー名を指定しています。処理が終了したら、メッセージにしたがって再起動します。

1.2 GuestAdditions CDのインストール

今回はVirtualBoxを使用していますので、続けてGuest Additions CDをインストールします。VirtualBoxのデバイスメニューからGuest Additions CDイメージの挿入...を選択してCDをマウントします。CDをマウントできたら、VBoxLinuxAdditions.runを実行します。

cd /media/<ユーザー名>/VVox_GAs_5.2.8
sudo bash VBoxLinuxAdditions.run

実行後に、また再起動しておきます。ところが、初回は何故かしらエラーになるので上記の処理を再実行して、もう一度起動し直します。これでGuest Additionsが利用できますから、VirtualBoxのデバイスメニューの光学ドライブ仮想ドライブからディスクを除去を実行しておきます。

1.3 newgrp dockerの実行

公式の手順にしたがって、newgrp dockerを実行しておきます。これが必須かどうかは不明ですけど。

newgrp docker

1.4 Goのインストール

次にGoをインストールします。

cd Linux-tools
sudo bash install-go.sh

公式の手順にしたがって、.bashrcを修正します。

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin
ulimit -n 8096

修正後の.bashrcを反映して、インストールされたGoのバージョンを確認しておきます。

$ cd ~
$ source .bashrc
$ go version
go version go1.10.1 linux/amd64

1.5 Node.jsのインストール

次にnode.jsをインストールします。

cd Linux-tools
sudo bash install-node.sh

1.6 Yarnのインストール

最後にYarnをインストールします。

cd Linux-tools
sudo bash install-yarn.sh

2. mattermost-serverのクローン

以上で開発環境の準備ができましたので、mattermostをクローンします。ここでは、mattrermost-servermattermost-webappをクローンします。

mkdir -p ~/go/src/github.com/mattermost
cd ~/go/src/github.com/mattermost
git clone https://github.com/mattermost/mattermost-server.git
git clone https://github.com/mattermost/mattermost-webapp.git

3. mattermost-serverのビルド準備

3.1 Makefileをラズパイ用に修正

mattermost-serverには、Linux amd64OSX amd64Windows amd64用のビルドターゲットが用意されています。そこにLinux armとしてラズパイ用のターゲットを追加します。

まず、Makefileを修正します。.PHONY:の行のbuild-windowsの次にbuild-armを追加します。

.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows build-arm internal-test-web-client vet run-server-for-web-client-tests

3.2 build/release.mkをラズパイ用に修正

次にbuild/release.mkを修正します。まずbuild-windows:の下にbuild-arm:を追加して、build:行にbuil-armを追加します。

build-arm:
        @echo Build Linux arm
ifeq ($(BUILDER_GOOS_GOARCH),"linux_arm")
        env GOOS=linux GOARCH=arm $(GO) build -i -o $(GOPATH)/bin/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
else
        env GOOS=linux GOARCH=arm $(GO) build -i -o $(GOPATH)/bin/linux_arm/platform $(GOFLAGS) $(GO_LINKER_FLAGS) ./
endif

build: build-linux build-windows build-osx build-arm

このbuild/release.mkファイルの最後にMake arm package用の行を追加します。

        @# Make arm package
        @# Copy binary
ifeq ($(BUILDER_GOOS_GOARCH),"linux_arm")
        cp $(GOPATH)/bin/platform $(DIST_PATH)/bin # from native bin dir, not cross-compiled
else
        cp $(GOPATH)/bin/linux_arm/platform $(DIST_PATH)/bin # from cross-compiled bin dir
endif
        @# Package
        tar -C dist -czf $(DIST_PATH)-$(BUILD_TYPE_NAME)-linux-arm.tar.gz mattermost
        @# Don't clean up native package so dev machines will have an unzipped package available
        @#rm -f $(DIST_PATH)/bin/platform

4. mattermost-serverのコンパイル

ここから公式のCompiling Mattermostにある手順で作業を実施します。

4.1 /usr/local/goディレクトリのパーミッション変更

まず公式の手順に従って、/usr/local/goディレクトリのパーミッションを変更します。

sudo chwon -R <ユーザ>:<グループ> /usr/local/go

4.2 mattermost-serverのビルド

以上で準備ができましたので、公式の手順にしたがってmattermostをビルドします。まず、mattermost-serverをビルドします。

env LC_ALL=C make build

4.3 mattermost-webappのビルド

続けてmattermost-webappをビルドします。

env LC_ALL=C make build-client

4.4 packageの作成

無事にビルドできましたので、パッケージを作成します。

make package の実行で unzip が無いとエラーになるので事前にインストールしておきます。

$ sudo apt install zip
make config-reset
make package

今回は、クロスコンパイルしていますのでdistディレクトリに4つのパッケージが作成されています。

$ ls dist
mattermost                          mattermost-team-osx-amd64.tar.gz
mattermost-team-linux-amd64.tar.gz  mattermost-team-windows-amd64.zip
mattermost-team-linux-arm.tar.gz

もちろん、mattermostはEnterprise Editionではなくteam editionとなっています。

ここで作成したmattermost-team-linux-arm.tar.gzをラズパイに転送します。次には、ラズパイでmattermost-dockerを動かします

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2