Build, Deploy and Run a Ruby Application · Fly Docshttps://fly.io/docs/getting-started/ruby/首先使用命令在项目文件夹安装curl -L https://fly.io/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1415 0 1415 0 0 1889 0 --:--:-- --:--:-- --:--:-- 1886
######################################################################## 100.0%
set channel to shell
flyctl was installed successfully to /home/linlin/.fly/bin/flyctl
Manually add the directory to your $HOME/.bash_profile (or similar)
export FLYCTL_INSTALL="/home/linlin/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
Run '/home/linlin/.fly/bin/flyctl --help' to get started
把这些代码放进文件中vim ~/.bashrc
export FLYCTL_INSTALL="/home/linlin/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
flyctl auth login
登录进flyctl,再次运行新的APP就不需要登录了 ,直接创建运行就可以,运行命令rackup
例如一个sinatra 应用。
app.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'sinatra'
get '/' do
"Hello From Ruby on Fly!
"
end
get '/:name' do
"Hello From Ruby on Fly!
and hello to #{params[:name]}"
end
Gemfile:
source 'https://rubygems.org'
ruby '3.1.0'
gem 'sinatra'
gem 'puma'
config.ru
require './app.rb'
run Sinatra::Application
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 3.1.0-p0) ("Birdie's Version")
* Min threads: 0
* Max threads: 5
* Environment: development
* PID: 300873
* Listening on http://127.0.0.1:9292
* Listening on http://[::1]:9292
Use Ctrl-C to stop
第一次在远程运行会出现加载较慢的情况,后续就不会了。
创建APP的时候,注意名称不要重复,不要下划线,可以选择公开与否和地区。
可以发现,在本地代码文件夹,会多出一个文件: fly.toml
# fly.toml file generated for 1234 on 2022-06-02T17:17:57+08:00
app = "1234"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[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"
执行命令,报错也没关系,因为不是在本地的docker运行的
点击1234hostname的网址并不能打开页面,那么出错了,应该在hi目录下增加文件fly.toml,重新运行刚才的命令
linlin@linlin-i5:/workspace/blog_fly/hi$ flyctl launch
===> EXPORTING
Adding layer 'heroku/ruby:env'
Adding layer 'heroku/ruby:gems'
Adding layer 'heroku/ruby:ruby'
Adding 1/1 app layer(s)
Adding layer 'launcher'
Adding layer 'config'
Adding layer 'process-types'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Setting default process type 'web'
Saving registry.fly.io/1232:cache...
*** Images (dfe5ceea3db5):
registry.fly.io/1232:cache
registry.fly.io/1232:deployment-1654162525
Adding cache layer 'heroku/ruby:gems'
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/1232]
87dc756f0bc5: Pushed
a248e8c4fc0a: Pushed
195ce6778985: Pushed
b8a76ee77a47: Pushed
fd941a6af848: Pushed
70d0bf6c5fc0: Pushed
a1e3b8b5e582: Pushed
0b9d6a2b9aef: Pushed
219a884327cf: Pushed
6c6007ce9a6d: Pushed
c2fb59d1c64c: Pushed
bf8cedc62fb3: Pushed
deployment-1654162525: digest: sha256:3e73d65e03c43918798c6476038bbeefd61eab82b854c658a82c11b7e945c332 size: 2826
--> Pushing image done
image: registry.fly.io/1232:deployment-1654162525
image size: 657 MB
==> Creating release
--> release v2 created
--> You can detach the terminal anytime without stopping the deployment
==> Monitoring deployment
v0 is being deployed
运行的时间也是比较慢的,可以在远程看到新的APP已经是绿色的可以用了,
在详情页面也可以看到,增加了许多内容
设置ssl 域名
点击图中的选项,可以进行域名的设置