this post was submitted on 06 Jul 2023
12 points (92.9% liked)

Selfhosted

40183 readers
832 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS
 

Howdy folks!

I spun up my own Mastodon today and quickly realized there was a 500 character limit to posts. I googled around, found some good guides and decided to make a quick bash script for it. Replace the below values inside the carrots with your settings.

#!/bin/bash -x

docker exec -it mastodon_web sed -i 's/500/<desired_#_of_chars>/g' /opt/mastodon/app/javascript/mastodon/features/compose/components/compose_form.js
docker exec -it mastodon_web sed -i 's/500/<desired_#_of_chars>/g' /opt/mastodon/app/validators/status_length_validator.rb
docker exec -it mastodon_web bundle exec rails assets:precompile
docker container restart <mastodon_web_container> <mastodon_streaming_container> <mastodon_sidekiq_container>

you are viewing a single comment's thread
view the rest of the comments
[–] drdaeman@lemmy.zhukov.al 2 points 1 year ago* (last edited 1 year ago) (4 children)

I don't mean to discourage you - this is a good hack. But as a seasoned code monkey, I see a few things that can be possibly improved so they will have less chances of biting you in the future. Please feel free to disregard this, of course.

s/500/…/g

This is a bit overbroad, as it replaces any “500” in those files. It works now, as this is probably only occurrence is the limit you want to tweak, but it’s a crude approach that may inadvertently break at any moment.

docker exec

Those changes are ephemeral and won’t survive if container is re-created for any reason (unless /opt/mastodon is a volume - I guess this is how it survives docker container restart?). I would rather recommend building your own custom image. Start by making a patch file:

docker run -it --rm -user root <mastodon image> bash
cp -r /opt/mastodon /opt/mastodon.vanilla
sed <your-updates-here> # or you can run vi or nano or any other editor
diff -urN /opt/mastodon.vanilla /opt/mastodon
exit

Take diff’s output, save it to fix-limits.patch in a new empty directory, then write a brief Dockerfile next to it, that goes like this:

FROM <base-mastodon-image>
COPY fix-limits.patch ./
RUN patch -p2 fix-limits.patch

And finally run docker build -t my-mastodon . and use my-mastodon as a replacement image. This will ensure your changes will persist, plus you’ll have a proper patch file that you can use with any version (point is, it will warn you if something would change in a way that the patch would no longer apply cleanly).

I’m writing this on a phone, from scratch, without any testing, so you may need to tweak things a little bit. E.g. I’m not sure what’s the WORKDIR in the base image - just assuming its /opt/mastodon (which it probably is), but you may need to edit the COPY command’s second argument and/or -p parameter to patch.> docker container restart

[–] th0mcat@kbin.social 1 points 1 year ago (1 children)

Oh I know my workaround is probably the worst possible correct answer for how to do this. Thanks for that, I'll give it a shot!

[–] drdaeman@lemmy.zhukov.al 1 points 1 year ago

It's OK. I do hacks like this all the time - no shame in this. However, when sharing a recipe with others it's best to promote better practices :)

load more comments (2 replies)