• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

nrdli/mastodon-google-cloud-storage: How to make it work.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

nrdli/mastodon-google-cloud-storage

开源软件地址(OpenSource Url):

https://github.com/nrdli/mastodon-google-cloud-storage

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

Mastodon + Google Cloud Storage = ❤️

With so many instances either relying on S3 or minio, I figured it was high time to throw some diversity into the mix, for a more resilient federation. You should probably read the whole thing before you start, as the process isn't exactly linear.

Requirements

  • Until it is officially supported by mastodon, you will need a patched version that supports using fog to upload files. I have such a patch in my fork., feel free to use it (at your own risk).
  • A google cloud account, with a CNAME bucket set up. You can get $300 of credit for a year, and on a smallish node that should last the whole year.
  • A cloudflare account set up to forward requests to google cloud storage.

Migrating existing media

There are different storage formats in use by paperclip (what mastodon uses for file uploads/storage) for diferent plugins. By setting up the patch (and some environment variable) you will be switching from the built-in filesystem plugin to the fog plugin.

There is a helper script for migrating from FS to GCS in this repo, the gist is that on the filesystem we have:

  • {mastodon}/public/system/media_attachments/files/000/000/001/original/83d9ee7311bffc6f.jpeg
  • {mastodon}/public/system/media_attachments/files/000/000/001/small/83d9ee7311bffc6f.jpeg

And when files are stored in google drive they live in:

  • {bucket}/images/media_attachments/1/files/original/img_
  • {bucket}/images/media_attachments/1/files/small/img_

You can build that folder structure by:

  1. Install node & yarn (which should alredy be done since we are running mastodon).
  2. Install our dependencies (yarn)
  3. Run the script node move-media ../path/to/live . (Puts the images directory here). You can run the above command with --dry-run to see the output of what the command will do if you don't trust the code.

Once that folder has been built you can just use Google's CLI, gsutil, to upload that folder and set the ACL to public. (gsutil -m cp -r images gs://media.nrd.li && gsutil -m acl ch -r -u AllUsers:R gs://media.nrd.li)

You probably want to do this step twice, once before you reconfigure your instance, and once again after so that you can be sure all media has been uploaded to cloud storage. I'm sure there's a way to sync the directory, but ingress is free so I just uploaded it all twice.

Setting it up so you can see images

By default there are no CORS headers sent, which needs to be rectified.

  1. Edit cors-config.json, replace "origin": "*" with "origin": "https://my.mastodon".
  2. Set the policy of the bucket you are using for media gsutil cors set config.json gs://bucket-name

You can use cors-config.json without editing it, but that is slightly less secure than specifying the origin.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap