1
0
hugo/content/blog/2023-01-09-mitra.md
2024-04-23 22:21:26 +09:00

4.4 KiB

+++ date = "2023-01-09" tags = ["rust","activitypub","sns","fly"] title = "mitraをfly.ioにdeployしてみた" slug = "mitra" +++

mitraは、rustで書かれた仮想通貨のwalletと連携可能なインスタンスです。

uiとbackendが素晴らしく、とてもシンプルです。

https://codeberg.org/silverpill/mitra

https://codeberg.org/silverpill/mitra-web

gotosocialと同じくmatrixの設計を参考にしているように感じられました。

$ git clone https://codeberg.org/silverpill/mitra
$ cd mitra
$ cp config.yaml.example config.yaml
$ cargo build --release --features production
$ cat .env.local
ENVIRONMENT=development
#ENVIRONMENT=production
CONFIG_PATH=./config.yaml
#CONFIG_PATH=/app/server/config.yaml
#VUE_APP_BACKEND_URL=https://example.com
#VUE_APP_BACKEND_URL=http://example.com:8380
#PORT=8380

$ git clone https://codeberg.org/silverpill/mitra-web
$ cd mitra-web
$ npm install --no-save
$ npx allow-scripts
$ npm run build
$ mv dist ../
database_url: postgres://mitra:mitra@127.0.0.1:55432/mitra
storage_dir: files
web_client_dir: dist
http_host: '0.0.0.0'
http_port: 8380
instance_uri: example.com
instance_title: Mitra
instance_short_description: My instance
instance_description: My instance
registrations_open: true

#http_host: '127.0.0.1'
#instance_uri: example.com:8380

fly.ioではinstance_uri: example.comを使用します。portを指定すると502になります。

また、http_host: 0.0.0.0にしてください。

$ docker-compose up -d
$ ./target/release/mitra
---
$ curl -sL http://127.0.0.1:8380/api/v1/instance

fly.ioのdockerでやろうと思うと、けっこう大変です。

.dockerignoremitra/{target,files}を追加しておいてください。

Dockerfile

FROM rust:latest as builder

WORKDIR /app
ADD mitra/ ./

RUN cargo build --release --features production
RUN mv target/release/mitra ./
RUN mv target/release/mitractl ./

RUN mkdir -p /app/files
app = "xxx"
kill_signal = "SIGINT"
kill_timeout = 10

[env]
PORT = "8380"

[experimental]
cmd = "./mitra"

[[services]]
  internal_port = 8380
  protocol = "tcp"

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

[mounts]
source="mitra_data"
destination="/app/files"

deploy

$ flyctl deploy --remote-only

node

m1だとcompileしないといけないらしいので時間がかかります。

archとかでやったほうがいいかも。

  • node : 14

  • npm : 7+

$ paru -S nvm
$ nvm install v14
$ nvm use v14
$ npm i -g npm
$ npm -v

$ node -v
$ nvm use v14

cloudflare

他のインスタンスではcname -> dns-onlyを選択しますが、mitraではcname -> proxiedを選択します。

$ fly certs create $app.fly.dev
$ fly certs create $sub.example.com
$ fly certs show $sub.example.com

cname : _acme-challenge.$app, $app.fly.dev.xxx.flydns.net, Proxied

cname : $sub, $app.fly.dev, Proxied

option

#ENVIRONMENT=development
ENVIRONMENT=production
CONFIG_PATH=./config.yaml
#VUE_APP_BACKEND_URL=https://example.com
#PORT=8380
ipfs_api_url: 'http://0.0.0.0:5001'
ipfs_gateway_url: 'http://0.0.0.0:8001'
app = "xxx"
kill_signal = "SIGINT"
kill_timeout = 10

[env]
PORT = "8380"

[experimental]
cmd = "./mitra"
allowed_public_ports = []
auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8380
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 5001

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 8001

[mounts]
source="mitra_data"
destination="/app/files"
$ fly ips list
$ flyctl ips release 12.34.56.78

web-ui/about

改行コードには\nを使えます。

instance_description: "foo\nbar"
foo
bar