mmpy_bot
mmpy_bot copied to clipboard
CI testing against a Mattermost server
Following from a discussion in the chat (@jneeven @attzonko) we identified a few obstacles and some possible solutions that need to be further explored.
Using
mattermost-previewdocker container
Challenges
- Bootstrapping the initial admin user (usually created manually on first visit)
- Creating a bot user (requires a user with privileged access)
- Extract a bot token and use it in CI with
mmpy_bot - Glue everything above in a GitHub Actions compatible workflow
- Keep the setup compatible with local development
Possibilities to explore
- [x] Creating the user directly in the container with
mattermostlocal commands.- [x] How to execute both the mattermost server and local commands in this case?
- [ ] Can multiple GitHub actions run in the same container?
- [x] Remotely creating a user and bot with a combination of
mmctl token,mmctl botor othermmctlcommands.- [x] Does
mmctlsupport creating the first user? - [x] Can we obtain the bot token through
mmctl?
- [x] Does
Hey @unode, apologies if this is random, but I've done something like this before for Mattermost's golang bot wrapper (See the add_users.sh and docker-compose files in their repo for some setup) as well as wanted to mention you can use mmctl to create and return bot tokens (you just have to log in first with a created user, but its quite easy to do using their cli options.
Depending on my free time (since I'm a student), I'd be happy to assist in this effort if you'd like to chat about it more sometime, or if not, hopefully the link I posted might assist a bit
Hi @saf6260. Thanks a lot for the pointers! This is gold and a massive time saver!!!
Would be great to have a chat. We don't want to distract you from your studies but if you ever want to, join us on Discord. Cheers!
Hey @unode, thanks for the invite! Definitely interested in joining, however it appears I'm having an issue joining via the link provided. Is there a different link I can use? Or I can figure out a different way to send you my discord info if that is easier
Hum... the link seems to work for me. Could you maybe try a different browser (without addons) or visiting the link in incognito mode?
Perhaps some screenshots will help us figure out what might be happening...
On my side, this is what I get when I visit the link:

That worked, thanks! Guess I had a secondary addon that blocked something. Its worked from other links, so not sure what happened
I was able to work on this for another project and works (locally) with the mattermost/mattermost-preview container.
Here's a possibly useful extract:
TARGET="container_name"
MM="docker exec $TARGET mattermost --config=mattermost/config/config_docker.json"
MMCTL="docker exec $TARGET mmctl"
# Create the initial (admin) user
$MM user create --email 'root@localhost' --username root --password password --system_admin
# Authenticate mmctl so we can use some instructions only available or effective through the REST API
$MMCTL auth login http://localhost:8065 --name local --username root --password password
From this we can use mattermost or mmctl to create teams, channels, bot accounts, etc...
$MM user create --email 'user@localhost' --username user --password password --system_admin
$MMCTL config set ServiceSettings.EnableBotAccountCreation true
$MMCTL config set ServiceSettings.SiteURL 'http://localhost:8065'
OUTPUT="$($MMCTL bot create mybot --display-name mybot --with-token)"
$MMCTL roles system_admin mybot
$MMCTL bot assign mybot user
$MM team create --name testteam --display_name TestTeam
$MM team add testteam root user mybot
$MM channel create --team testteam --name bot_test --display_name "bot_test" --private
$MM channel add testteam:bot_test root user mybot
To extract the bot token from the output this gets the job done:
printf "BOT_TOKEN=%s\n" "$(echo "$OUTPUT" | grep autogenerated | sed 's/: autogenerated//g')"
Integration tests already do this so closing.