1
0
hugo/content/blog/2023-01-09-mitra.md

242 lines
4.4 KiB
Markdown
Raw Normal View History

2024-04-23 13:21:26 +00:00
+++
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の設計を参考にしているように感じられました。
![](https://raw.githubusercontent.com/syui/img/master/other/mitra_20230111_0001.png)
```sh
$ 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 ../
```
```yaml:config.yaml
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`にしてください。
```sh
$ docker-compose up -d
$ ./target/release/mitra
---
$ curl -sL http://127.0.0.1:8380/api/v1/instance
```
fly.ioのdockerでやろうと思うと、けっこう大変です。
`.dockerignore`に`mitra/{target,files}`を追加しておいてください。
> Dockerfile
```sh
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
```
```toml:fly.toml
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
```sh
$ flyctl deploy --remote-only
```
- https://github.com/fly-apps/hello-rust
- https://community.fly.io/t/error-deploying-fly-apps-hello-rust/5664
### node
m1だとcompileしないといけないらしいので時間がかかります。
archとかでやったほうがいいかも。
- node : 14
- npm : 7+
```sh
$ 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`を選択します。
```sh
$ 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
```sh:.env.local
#ENVIRONMENT=development
ENVIRONMENT=production
CONFIG_PATH=./config.yaml
#VUE_APP_BACKEND_URL=https://example.com
#PORT=8380
```
```yaml:config.yaml
ipfs_api_url: 'http://0.0.0.0:5001'
ipfs_gateway_url: 'http://0.0.0.0:8001'
```
```toml:fly.toml
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"
```
```sh
$ fly ips list
$ flyctl ips release 12.34.56.78
```
- https://community.fly.io/t/announcement-shared-anycast-ipv4/9384
### web-ui/about
改行コードには`\n`を使えます。
```toml:config.toml
instance_description: "foo\nbar"
```
```html:/about/index.html
foo
bar
```