changes for buster linode
[distro-setup] / disabled / mastodon
1 ############# begin setup mastodon ##############
2
3 # main doc is Docker-Guide.md in docs repo
4
5 # I'd like to try gnu social just cuz of gnu, but it's not being
6 # well maintained, for example, simple pull requests
7 # languishing:
8 # https://git.gnu.io/gnu/gnu-social/merge_requests/143
9 # and I submitted my own bugs, basic docs are broken
10 # https://git.gnu.io/gnu/gnu-social/issues/269
11
12 # note, docker required, but we installed it earlier
13
14 # i subscrubed to https://github.com/docker/compose/releases.atom
15 # to see release notes.
16 # i had some problems upgrading. blew things away with
17 # docker-compose down
18 # docker rmi $(docker images -q)
19 # s reboot now
20 # when running docker-compose run, kernel stack traces are printed to the journal.
21 # things seem to succeed, google says nothing, so ignoring them.
22 curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-$(uname -s)-$(uname -m) | s dd of=/usr/local/bin/docker-compose
23 s chmod +x /usr/local/bin/docker-compose
24
25
26 cd ~
27 s rm -rf mastodon
28 i clone https://github.com/tootsuite/mastodon
29 cd mastodon
30 # subbed to atom feed to deal with updates
31 git checkout $(git tag | grep -v rc | tail -n1)
32
33 # per instructions, uncomment redis/postgres persistence in docker-compose.yml
34 sed -i 's/^#//' docker-compose.yml
35
36 cat >.env.production <<'EOF'
37 REDIS_HOST=redis
38 REDIS_PORT=6379
39 DB_HOST=db
40 DB_USER=postgres
41 DB_NAME=postgres
42 DB_PASS=
43 DB_PORT=5432
44
45 LOCAL_DOMAIN=mast.iankelling.org
46 LOCAL_HTTPS=true
47
48 SINGLE_USER_MODE=true
49
50 SMTP_SERVER=mail.iankelling.org
51 SMTP_PORT=25
52 SMTP_LOGIN=li
53 SMTP_FROM_ADDRESS=notifications@mast.iankelling.org
54 SMTP_DOMAIN=mast.iankelling.org
55 SMTP_DELIVERY_METHOD=smtp
56 EOF
57
58 for key in PAPERCLIP_SECRET SECRET_KEY_BASE OTP_SECRET; do
59 # 1 minute 7 seconds to run this docker command
60 # to generate a secret, and it has ^M chars at the end. wtf. really dumb
61 printf "%s=%s\n" $key "$(docker-compose run --rm web rake secret|dos2unix|tail -n1)" >>.env.production
62 done
63 found=false
64 while read -r domain _ pass; do
65 if [[ $domain == mail.iankelling.org ]]; then
66 found=true
67 # remove the username part
68 pass="${pass#*:}"
69 printf "SMTP_PASSWORD=%s\n" "$pass" >>.env.production
70 break
71 fi
72 done < <(s cat /etc/mailpass)
73 if ! $found; then
74 echo "$0: error, failed to find mailpass domain for mastadon"
75 exit 1
76 fi
77
78 # docker compose makes an interface named like br-8f3e208558f2. we need mail to
79 # get routed to us.
80 if ! s /sbin/iptables -t nat -C PREROUTING -i br-+ -p tcp -m tcp --dport 25 -j DNAT --to-destination 10.8.0.4:25; then
81 s /sbin/iptables -t nat -A PREROUTING -i br-+ -p tcp -m tcp --dport 25 -j DNAT --to-destination 10.8.0.4:25
82 fi
83
84 docker-compose run --rm web rake mastodon:webpush:generate_vapid_key | grep -E '^VAPID_PUBLIC_KEY=|^VAPID_PRIVATE_KEY=' >> .env.production
85 logq docker-compose run --rm web rake db:migrate
86 docker-compose run --rm web rails assets:precompile
87
88 # avatar failed to upload, did
89 # docker logs mastodon_web_1
90 # google lead me to this
91 s chown -R 991:991 public/system
92
93 # docker daemon takes care of starting on boot.
94 docker-compose up -d
95
96 s a2enmod proxy_wstunnel headers
97 web-conf -f 3000 - apache2 mast.iankelling.org <<'EOF'
98 ProxyPreserveHost On
99 RequestHeader set X-Forwarded-Proto "https"
100 ProxyPass /500.html !
101 ProxyPass /oops.png !
102 ProxyPass /api/v1/streaming/ ws://localhost:4000/
103 ProxyPassReverse /api/v1/streaming/ ws://localhost:4000/
104 ErrorDocument 500 /500.html
105 ErrorDocument 501 /500.html
106 ErrorDocument 502 /500.html
107 ErrorDocument 503 /500.html
108 ErrorDocument 504 /500.html
109 EOF
110
111
112 ############### !!!!!!!!!!!!!!!!!
113 ############### manual steps:
114
115 # only following a few people atm, so not bothering to figure out backups
116 # when mastodon has not documented it at all.
117 #
118 # fsf@status.fsf.org
119 # cwebber@toot.cat
120 # dbd@status.fsf.org
121 # johns@status.fsf.org
122
123 # sign in page is at https://mast.iankelling.org/auth/sign_in
124 # register as iank, then
125 # https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Administration-guide.md
126 # docker-compose run --rm web bundle exec rails mastodon:make_admin USERNAME=iank
127
128 ############# end setup mastodon ##############