Open17
Fly.io 使ってみる
Deploy app servers close to your users · Fly
とりあえず、GitHub 連携でログイン。
Two Factor Auth を設定しておく。
ダッシュボード
サインイン
flyctl auth login
flyio/hellofly:latest を動かしてみる
% flyctl launch --image flyio/hellofly:latest
Creating app in /Users/oppara/sandbox/flyio/hellofly
Using image flyio/hellofly:latest
? App Name (leave blank to use an auto-generated name): hellofly
Automatically selected personal organization: oppara
? Select region: nrt (Tokyo, Japan)
Error Validation failed: Name has already been taken
アカウント毎ではなく、グローバルな名前でないとダメっぽい
面倒なので、名前は自動生成
% flyctl launch --image flyio/hellofly:latest
Creating app in /Users/oppara/sandbox/flyio/hellofly
Using image flyio/hellofly:latest
? App Name (leave blank to use an auto-generated name):
Automatically selected personal organization: oppara
? Select region: nrt (Tokyo, Japan)
Created app still-voice-2717 in organization personal
Wrote config file fly.toml
? Would you like to set up a Postgresql database now? No
? Would you like to deploy now? No
Your app is ready. Deploy with `flyctl deploy`
生成された fly.toml
fly.toml
# fly.toml file generated for still-voice-2717 on 2022-10-10T00:30:30Z
app = "still-voice-2717"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[build]
image = "flyio/hellofly:latest"
[env]
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
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.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
デプロイ
% flyctl deploy
==> Verifying app config
--> Verified app config
==> Building image
Searching for image 'flyio/hellofly:latest' remotely...
image found: img_z1nr0lpjz9v5q98w
==> Creating release
Error We need your payment information to continue! Add a credit card or buy credit: https://fly.io/dashboard/oppara/billing
クレカの登録かクレジットの購入が必要。。。
クレカを登録して再度デプロイ。
% flyctl deploy
==> Verifying app config
--> Verified app config
==> Building image
Searching for image 'flyio/hellofly:latest' remotely...
image found: img_z1nr0lpjz9v5q98w
==> Creating release
--> release v2 created
--> You can detach the terminal anytime without stopping the deployment
==> Monitoring deployment
1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
--> v0 deployed successfully
状況確認。
% flyctl status
App
Name = still-voice-2717
Owner = personal
Version = 0
Status = running
Hostname = still-voice-2717.fly.dev
Platform = nomad
Deployment Status
ID = dc1ddaef-31d5-c2c2-c910-e6edf4012136
Version = v0
Status = successful
Description = Deployment completed successfully
Instances = 1 desired, 1 placed, 1 healthy, 0 unhealthy
Instances
ID PROCESS VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
6225b279 app 0 nrt run running 1 total, 1 passing 0 1m14s ago
ブラウザで確認。
% flyctl open
opening http://still-voice-2717.fly.dev ...
ログ確認。
% flyctl logs
2022-10-10T07:47:25Z runner[6225b279] nrt [info]Starting instance
2022-10-10T07:47:25Z runner[6225b279] nrt [info]Configuring virtual machine
2022-10-10T07:47:25Z runner[6225b279] nrt [info]Pulling container image
2022-10-10T07:47:27Z runner[6225b279] nrt [info]Unpacking image
2022-10-10T07:47:27Z runner[6225b279] nrt [info]Preparing kernel init
2022-10-10T07:47:27Z runner[6225b279] nrt [info]Configuring firecracker
2022-10-10T07:47:27Z runner[6225b279] nrt [info]Starting virtual machine
2022-10-10T07:47:28Z app[6225b279] nrt [info]Starting init (commit: 249766e)...
2022-10-10T07:47:28Z app[6225b279] nrt [info]Preparing to run: `/goapp/app` as root
2022-10-10T07:47:28Z app[6225b279] nrt [info]2022/10/10 07:47:28 listening on [fdaa:0:b6fe:a7b:xxxx:xxxx:xxxx:2]:22 (DNS: [fdaa::3]:53)
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
2022-10-10T07:47:28Z app[6225b279] nrt [info] - using env: export GIN_MODE=release
2022-10-10T07:47:28Z app[6225b279] nrt [info] - using code: gin.SetMode(gin.ReleaseMode)
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] Loaded HTML Templates (2):
2022-10-10T07:47:28Z app[6225b279] nrt [info] -
2022-10-10T07:47:28Z app[6225b279] nrt [info] - hellofly.tmpl
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] GET / --> main.handleIndex (3 handlers)
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] GET /:name --> main.handleIndex (3 handlers)
2022-10-10T07:47:28Z app[6225b279] nrt [info][GIN-debug] Listening and serving HTTP on :8080
2022-10-10T07:50:01Z app[6225b279] nrt [info][GIN] 2022/10/10 - 07:50:01 | 200 | 1.637812ms | 126.55.xxx.xxx | GET /
2022-10-10T07:50:01Z app[6225b279] nrt [info][GIN] 2022/10/10 - 07:50:01 | 200 | 290.185µs | 126.55.xxx.xxx | GET /favicon.ico
動かしてるアプリにログインしようとするとエラー。
% flyctl ssh console
Connecting to top1.nearest.of.still-voice-2717.internal... complete
Error error connecting to SSH server: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
アクセストークンが必要な模様。
アクセストークンを確認する。
% flyctl auth token
xxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
アクセストークンをつけてログイン。
% flyctl ssh console -t xxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Connecting to top1.nearest.of.still-voice-2717.internal... complete
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.12.0
PRETTY_NAME="Alpine Linux v3.12"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/ # exit
後片付け
アプリの確認。
% flyctl list apps
NAME | STATUS | ORG | DEPLOYED
-------------------*---------*----------*-----------------
still-voice-2717 | running | personal | 17 minutes ago
アプリの削除。
% flyctl destroy still-voice-2717
Destroying an app is not reversible.
? Destroy app still-voice-2717? Yes
Destroyed app still-voice-2717
再度確認。
% flyctl list apps
NAME | STATUS | ORG | DEPLOYED
-------*--------*-----*-----------
+
ではなく *
なのが拘りを感じる?
あ、heroku の代替確認忘れた。。
まぁ、GAS で充分なんだけども 😅