2022-08-31 / syui

heroku , fly , northflank / fly

fly.ioとnorthflankの感想

herokuの移行先として挙げられるfly.io, northflankの感想になります。

https://news.ycombinator.com/item?id=32599398

fly.ioが個人的には合っていると思いました。

fly.ioはdockerで動かしますが、goなどのbuild, deployが非常に快適でわかりやすかったです。mastodonはredisが入っているため動かすには工夫が必要ですが、go, rust, phoenixなどはそれらが必要ない場合が多く、go, rustはsingle-binaryなので、fly.tomlも書きやすい。

gitea

例えば、giteaはfly.ioで簡単に動きました。dockerを利用するので当たり前かもしれませんが、herokuでは相当の工夫が必要でした。

# create a directory to store fly.io application config
mkdir gitea-on-fly
# enter into the newly created directory
cd gitea-on-fly
# tell fly.io you wish to create a new application in the amsterdam region (there are many other regions you could pick too)
# pick any name for the app that you'd like, in the example we are using `gitea-on-fly`
flyctl launch --name gitea-on-fly --no-deploy --region ams
# give the newely create application persistant storage, so your data persists between app updates
flyctl volumes create gitea_data --size 1 --region ams --app gitea-on-fly
app = "gitea-on-fly"

kill_timeout = 5

[build]
  image = "gitea/gitea:latest" # latest is the most recent stable release

[env]
  GITEA__database__DB_TYPE="sqlite3"
  GITEA__database__PATH="/data/gitea/gitea.db"
  GITEA__server__DOMAIN="gitea-on-fly.fly.dev"
  GITEA__server__SSH_DOMAIN="gitea-on-fly.fly.dev"
  GITEA__server__ROOT_URL="https://gitea-on-fly.fly.dev"
  GITEA__security__INSTALL_LOCK="true" # Don't show installer
  # GITEA__service__DISABLE_REGISTRATION="true" # TODO: uncomment once you have created your first user

# persist data
[[mounts]]
  destination = "/data"
  source = "gitea_data"

# ssh traffic
[[services]]
  internal_port = 22
  protocol = "tcp"
  [[services.ports]]
    port = 22

# https traffic
[[services]]
  internal_port = 3000
  protocol = "tcp"
  
  [[services.ports]]
    handlers = ["http"]
    force_https = true
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443
$ flyctl deploy
$ flyctl open

https://blog.gitea.io/2022/04/running-gitea-on-fly.io/

cloudflare + fly.io + gitea(ssh)

cloudflare : dns -> cname -> disable proxy(dns only)

# add key
$ ssh-keygen -t ed25519 -f ~/.ssh/xxx
$ cat ~/.ssh/xxx|pbcopy
# gitea -> account -> ssh -> key -> paste 

$ ssh -vT [email protected]
$ ssh -vT [email protected]
$ git remote add ssh [email protected]:syui/repo.git
$ git remote add origin [email protected]:syui/repo.git
$ git remote add http https://example.com/syui/repo.git
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "ssh"]
	url = [email protected]:user/repo.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"]
	url = [email protected]:user/repo.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[remote "http"]
	url = https://example.com/user/repo.git
	fetch = +refs/heads/*:refs/remotes/http/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
$ git push ssh main
$ git push origin main
$ git push http main

ent-ogent

fly.ioではent-ogentも簡単でした。

https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/

app = "ent-ogent"
kill_signal = "SIGINT"
kill_timeout = 5

[build]
  builder = "paketobuildpacks/builder:base"
  buildpacks = ["gcr.io/paketo-buildpacks/go"]

[env]
  PORT = "8080"

[processes]
  api = "bin/t"

[[services]]
  internal_port = 8080
  processes = ["api"]
  protocol = "tcp"

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

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

ただし、freeで運用するとなると、fly.ioはvmが3つまでです。

そこでnorthflankを試してみることにしました。

northflankはwebUIをポチポチやってればできます。大体はわかると思います。

goの場合、buildpackを選択し、build-contextを/にしました。

  • addons : postgresを追加し、connectionを確認します。のちにenvのDATABASE_URLに入れます。いくつかenvが設定されるのでコードのほうを変更してもいい。

  • services/port&dns : custom domainでcnameします。verifyしたら、後にselectします。

  • services/cmd-overide : binaryを指定します。/bin/t

  • services/environment : DATABASE_URLを追加します。postgres-connection

  • services/builds : ここでコードをbuildします。

  • services/instances(continer) : logはここから確認します。

ちなみに、northflank/cliも使ってみましたが、使いづらい印象があります。

$ yarn global add @northflank/cli
$ northflank login
$ sudo northflank forward addon --addonId postgres