Learn how to get a local Mattermost and webapp instance up and running to create Mattermost plugins
(Originally published at controlaltdieliet.be)
The goal of this four-part series is to help you learn how to write your own Mattermost plugins for the first time. To kick things off, this article teaches you how to set up your developer environment.
My test computer is a five-year-old laptop with an Intel i5 processor and 4GB of RAM. You need at least 30GB of hard disk for this project. Of course, you’ll also need an internet connection.
We start with a freshly installed Ubuntu 20.04. You don’t need to install the desktop environment. If you do, you can browse to your Mattermost instance on the laptop, but you can also reach it from devices in your network as well.
Install the dependences
First, we have to install some dependencies:
sudo apt-get install -y build-essential curl git gcc nodejs npm
Since you’ll run Mattermost in a Docker container, you’ll need a free Docker account to get started. If you don’t have one, sign up here.
Now, it’s time to install Docker:
curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker $(whoami) docker login
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Mattermost is written in Golang and React. To build Mattermost plugins, you need to install Go:
sudo rm -rf /usr/local/go wget https://golang.org/dl/go1.15.6.linux-386.tar.gz sudo tar -C /usr/local -xzf go1.15.6.linux-386.tar.gz sudo apt-get remove -y gccgo-go && wget http://golang.org/dl/go1.15.6.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.15.6.linux-amd64.tar.gz echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
Add Go to your shell
Next, you need to add Go to your shell. To do that, add the following lines to
.bashrc in your home folder:
echo 'export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin export PATH=$PATH:/usr/local/go/bin' >> /YOUR/HOME/FOLDER/.bashrc
After that, you need to modify
/etc/security/limits.conf. Use Sudo, since you need to do this as an administrator. To do this, add the following two lines, replacing
YOURUSERNAME with your username:
/etc/security/limits.conf YOURUSERNAME soft nofile 8096 YOURUSERNAME hard nofile 8096
Clone and install the Mattermost server
To do this, fork the
mattermost-server to your own GitHub account. Then create a folder called
mmplugins and clone the
mattermost-server into that folder. Once that’s done, you need to build the server. When the process is complete, you’ll see its listing on port 8065.
mkdir mmplugins cd mmplugins git clone https://github.com/YOUR_GITHUB_USERNAME/mattermost-server.git cd mattermost-server make run-server
Test your server
Now, it’s time to send a ping command to the API server to test it:
You’ll receive a JSON response like this:
Now it’s time to shutdown your server for the time being:
Modify the configuration file
Next, go to the
mattermost-server/config/ folder and modify the
You’ll need to enable plugins. So, look for
PluginSettings and make sure they are enabled.
Install the webapp
At this point, you’ve successfully installed the Mattermost server. Now, it’s time to install the webapp.
To do that, you first need to fork the
mattermost-server into your own GitHub account.
Go back to the
mmplugins folder we created earlier and clone the
mattermost-webapp into that folder:
git clone https://github.com/YOUR_GITHUB_USERNAME/mattermost-webapp.git
Link your webapp to your server
The next step involves linking your webapp folder to your Mattermost server, like this:
mkdir -p mattermost-webapp/dist cd mattermost-server ln -nfs ../mattermost-webapp/dist client cd ..
Test and run your webapp
Now, go to the webapp folder, test your environment, and run your webapp. Don’t forget to start your server again!
cd mattermost-webapp make test make run cd ../mattermost-server make run-server
Fill your server with some test data
Next, fill your server with some demo data. You can login with a system admin account (e.g., username=systemadmin and password=Sys@admin-sample1) or with a regular account (e.g., username=user-1 and password=SampleUs@r-1).
We will do this in the next step.
cd mattermost-webapp make test-data
Store your credentials for uploading
Next, we’ll store your credentials for uploading like this:
cd mattermost-server/bin/ ./mmctl auth login http://localhost:8065 --name local-name --username sysadmin --password Sys@dmin-sample1
Browse to your Mattermost server
At this point, you can open your browser and surf to your Mattemrost server. You’ll be greeted by the webapp and can log in!
That’s it: You’re finished!
Once you’ve reached this point, you’ve successfully set up your own developer environment. Congratulations!
Now, it’s time to write some code. If you want to stop your server and your container, you have to run
make stop-docker in the
cd mattermost-webapp make stop-docker
Did you run into a ‘Permission Denied’ error?
When you’re starting your server and get a “Permission Denied” error, you don’t have the ability to start Docker with your account. An ugly way to solve this is by making the Docker-socket world read-writeable:
sudo chmod 666 /var/run/docker.sock
In the next installment in this series, I’ll walk you through the structure of plugins, including the differences between webapp and server plugins, and how to deploy them.
In the meantime, you might be interested in checking out my previous series on Mattermost integrations: