Installing mastodon for CI

Bonjour,

My initial idea was to include the installation and running a mastodon server in the CI to conveniently have an ActivityPub server against which fedeproxy could interact (with ActivityPub exclusively, not the API).

It is non trivial and here are today’s notes:

  • cp .env.production.sample .env.production
    • S3_ENABLED=false
    • ES_ENABLED=false
    • REDIS_HOST=redis
    • LOCAL_DOMAIN=m.dachary.org
    • DB_HOST=db
    • DB_PASS=****
  • SECRET_KEY_BASE=$(docker-compose run --rm web bundle exec rake secret)
  • sed -i -e “s/SECRET_KEY_BASE=/&${SECRET_KEY_BASE}/” .env.production
  • OTP_SECRET=$(docker-compose run --rm web bundle exec rake secret)
  • sed -i -e “s/OTP_SECRET=/&${OTP_SECRET}/” .env.production
  • Get the docker-compose.yml from sources, using the latest release v3.3.0
  • chmod 777 ./public/system/
  • Clear leftovers from previous attempts with rm -fr redis postgres public/system/*
  • Patch the docker-compose.yml
  • Follow the steps documented in this mastodon forum post (they are mysteriously repetitive, I’m not sure what the logic is)
  • Setup nginx as instructed in https://docs.joinmastodon.org/admin/install/
  • docker-compose run --rm web bin/tootctl account create loic --email loic@dachary.org --confirmed --role admin
  • chmod 777 ./public/system/

At this point I’m no longer sure it is convenient to use mastodon in the context of a CI

env.production (1.6 KB)
docker-compose.yml (2.8 KB)

I’m unable to mention someone in a toot, it gets the followin stack trace. The relevant part seems to be

"error_message":""
"error_class":"Stoplight::Error::RedLight"

In the larger message.

sidekiq_1    | 2021-05-05T21:11:56.776Z pid=6 tid=3c3u class=ActivityPub::DeliveryWorker jid=4672e759aaed5485b9a85ff9 elapsed=0.075 INFO: fail
sidekiq_1    | 2021-05-05T21:11:56.777Z pid=6 tid=3c3u WARN: {"context":"Job raised exception","job":{"retry":16,"queue":"push","dead":false,"class":"ActivityPub::Del
iveryWorker","args":["{\"@context\":[\"https://www.w3.org/ns/activitystreams\",{\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri
\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"sensitive\":\"as:sensitive\",\"toot\":\"http://joinmastodon.org/ns#\",\"votersCount\":\"to
ot:votersCount\"}],\"id\":\"https://m.dachary.org/users/loic/statuses/106184601111212400/activity\",\"type\":\"Create\",\"actor\":\"https://m.dachary.org/users/loic\"
,\"published\":\"2021-05-05T21:00:30Z\",\"to\":[\"\"],\"cc\":[],\"object\":{\"id\":\"https://m.dachary.org/users/loic/statuses/106184601111212400\",\"type\":\"Note\",
\"summary\":null,\"inReplyTo\":null,\"published\":\"2021-05-05T21:00:30Z\",\"url\":\"https://m.dachary.org/@loic/106184601111212400\",\"attributedTo\":\"https://m.dac
hary.org/users/loic\",\"to\":[\"\"],\"cc\":[],\"sensitive\":false,\"atomUri\":\"https://m.dachary.org/users/loic/statuses/106184601111212400\",\"inReplyToAtomUri\":nu
ll,\"conversation\":\"tag:m.dachary.org,2021-05-05:objectId=1:objectType=Conversation\",\"content\":\"<p><span class=\\\"h-card\\\"><a href=\\\"\\\" class=\\\"u-url m
ention\\\">@<span>dachary</span></a></span> hola</p>\",\"contentMap\":{\"en\":\"<p><span class=\\\"h-card\\\"><a href=\\\"\\\" class=\\\"u-url mention\\\">@<span>dach
ary</span></a></span> hola</p>\"},\"attachment\":[],\"tag\":[{\"type\":\"Mention\",\"href\":\"\",\"name\":\"@dachary@mastodon.online\"}],\"replies\":{\"id\":\"https:/
/m.dachary.org/users/loic/statuses/106184601111212400/replies\",\"type\":\"Collection\",\"first\":{\"type\":\"CollectionPage\",\"next\":\"https://m.dachary.org/users/
loic/statuses/106184601111212400/replies?only_other_accounts=true&page=true\",\"partOf\":\"https://m.dachary.org/users/loic/statuses/106184601111212400/replies\",\"it
ems\":[]}}}}",1,"",{"synchronize_followers":true}],"jid":"4672e759aaed5485b9a85ff9","created_at":1620248430.1792004,"enqueued_at":1620249116.7002182,"error_message":"
ArgumentError","error_class":"ArgumentError","failed_at":1620248430.2676272,"retry_count":4,"retried_at":1620248783.7026713},"jobstr":"{\"retry\":16,\"queue\":\"push\
",\"dead\":false,\"class\":\"ActivityPub::DeliveryWorker\",\"args\":[\"{\\\"@context\\\":[\\\"https://www.w3.org/ns/activitystreams\\\",{\\\"ostatus\\\":\\\"http://os
tatus.org#\\\",\\\"atomUri\\\":\\\"ostatus:atomUri\\\",\\\"inReplyToAtomUri\\\":\\\"ostatus:inReplyToAtomUri\\\",\\\"conversation\\\":\\\"ostatus:conversation\\\",\\\
"sensitive\\\":\\\"as:sensitive\\\",\\\"toot\\\":\\\"http://joinmastodon.org/ns#\\\",\\\"votersCount\\\":\\\"toot:votersCount\\\"}],\\\"id\\\":\\\"https://m.dachary.o
rg/users/loic/statuses/106184601111212400/activity\\\",\\\"type\\\":\\\"Create\\\",\\\"actor\\\":\\\"https://m.dachary.org/users/loic\\\",\\\"published\\\":\\\"2021-0
5-05T21:00:30Z\\\",\\\"to\\\":[\\\"\\\"],\\\"cc\\\":[],\\\"object\\\":{\\\"id\\\":\\\"https://m.dachary.org/users/loic/statuses/106184601111212400\\\",\\\"type\\\":\\
\"Note\\\",\\\"summary\\\":null,\\\"inReplyTo\\\":null,\\\"published\\\":\\\"2021-05-05T21:00:30Z\\\",\\\"url\\\":\\\"https://m.dachary.org/@loic/106184601111212400\\
\",\\\"attributedTo\\\":\\\"https://m.dachary.org/users/loic\\\",\\\"to\\\":[\\\"\\\"],\\\"cc\\\":[],\\\"sensitive\\\":false,\\\"atomUri\\\":\\\"https://m.dachary.org
/users/loic/statuses/106184601111212400\\\",\\\"inReplyToAtomUri\\\":null,\\\"conversation\\\":\\\"tag:m.dachary.org,2021-05-05:objectId=1:objectType=Conversation\\\"
,\\\"content\\\":\\\"<p><span class=\\\\\\\"h-card\\\\\\\"><a href=\\\\\\\"\\\\\\\" class=\\\\\\\"u-url mention\\\\\\\">@<span>dachary</span></a></span> hola</p>\\\",
\\\"contentMap\\\":{\\\"en\\\":\\\"<p><span class=\\\\\\\"h-card\\\\\\\"><a href=\\\\\\\"\\\\\\\" class=\\\\\\\"u-url mention\\\\\\\">@<span>dachary</span></a></span>
 hola</p>\\\"},\\\"attachment\\\":[],\\\"tag\\\":[{\\\"type\\\":\\\"Mention\\\",\\\"href\\\":\\\"\\\",\\\"name\\\":\\\"@dachary@mastodon.online\\\"}],\\\"replies\\\":
{\\\"id\\\":\\\"https://m.dachary.org/users/loic/statuses/106184601111212400/replies\\\",\\\"type\\\":\\\"Collection\\\",\\\"first\\\":{\\\"type\\\":\\\"CollectionPag
e\\\",\\\"next\\\":\\\"https://m.dachary.org/users/loic/statuses/106184601111212400/replies?only_other_accounts=true&page=true\\\",\\\"partOf\\\":\\\"https://m.dachar
y.org/users/loic/statuses/106184601111212400/replies\\\",\\\"items\\\":[]}}}}\",1,\"\",{\"synchronize_followers\":true}],\"jid\":\"4672e759aaed5485b9a85ff9\",\"create
d_at\":1620248430.1792004,\"enqueued_at\":1620249116.7002182,\"error_message\":\"ArgumentError\",\"error_class\":\"ArgumentError\",\"failed_at\":1620248430.2676272,\"
retry_count\":4,\"retried_at\":1620248783.7026713}"}
sidekiq_1    | 2021-05-05T21:11:56.778Z pid=6 tid=3c3u WARN: ArgumentError: ArgumentError
sidekiq_1    | 2021-05-05T21:11:56.779Z pid=6 tid=3c3u WARN: /opt/mastodon/app/lib/request.rb:28:in `initialize'

It was because of a permission issue in the system directory chmod 777 ./public/system/ fixed it.

It’s interesting that both S3 and Swift are supported.

  • Optional: Object storage provider. Mastodon can save files that you and your users upload on the hard disk drive of the VPS it runs on, however, the hard disk drive is usually not infinite and difficult to upgrade later. An object storage provider gives you practically infinite metered file storage.

How to get: Amazon S3, Exoscale, Wasabi, Google Cloud, anything that exposes either an S3-compatible or OpenStack Swift-compatible API. Comes with a monthly cost based on the amount of files stored as well as how often they are accessed.

Mastodon itself forces https which is inconvenient in a CI environment. Unless Rails.env.production is not set.

Adding

RAILS_ENV=development
NODE_ENV=development

to .env.production leads to an error early on:

$ docker-compose up -d db redis
$ docker-compose run --rm -e SKIP_POST_DEPLOYMENT_MIGRATIONS=true web env RAILS_ENV=development rails db:migrate
...
NameError: uninitialized constant Annotate
...

I feel this is going in the wrong direction.

Although there are instructions in the mastodon documention on how to run behind tor it does not work because mastodon forces https (which is not something tor services can work with).

docker-compose build won’t work on any tagged versions because a dependency disappeared (licensing issues).



A hack was implemented to fix the problem for the test environment:

It builds from the main branch:

$ docker-compose build
...
Fetching mimemagic 0.3.10
Installing mimemagic 0.3.10 with native extensions

Using the image built from sources, the migration fails with:

$ docker-compose up -d db redis
$ docker-compose run --rm -e SKIP_POST_DEPLOYMENT_MIGRATIONS=true web rails db:migrate
...
PG::AmbiguousColumn: ERROR:  column reference "reblogs_count" is ambiguous                                                                                           
LINE 23:          sum(reblogs_count + favourites_count) / (1.0 + sum(...                                                                                              
...

I will try with postgres 12 because it is the version used in .circleci and therefore likely to be a good match.

It fails with the same error on postgres 12.6