fly.io ruby on rails

Build, Deploy and Run a Ruby Application · Fly Docsicon-default.png?t=M4ADhttps://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

本地运行:$ rackup

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

在远程运行   flyctl  launch 注意在存在rb  Gemfile文件夹内,此时是错误的文件夹

第一次在远程运行会出现加载较慢的情况,后续就不会了。

创建APP的时候,注意名称不要重复,不要下划线,可以选择公开与否和地区。

fly.io ruby on rails_第1张图片

 可以发现,在本地代码文件夹,会多出一个文件: 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"

远程会出现项目,点击进入,是详情页面 可以看到详细的信息fly.io ruby on rails_第2张图片

如何做部署  flyctl deploy  (前提:需要有个  fly.toml 文件)

执行命令,报错也没关系,因为不是在本地的docker运行的

点击1234hostname的网址并不能打开页面,那么出错了,应该在hi目录下增加文件fly.toml,重新运行刚才的命令

linlin@linlin-i5:/workspace/blog_fly/hi$ flyctl  launch

fly.io ruby on rails_第3张图片



===> 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已经是绿色的可以用了,fly.io ruby on rails_第4张图片

 在详情页面也可以看到,增加了许多内容

fly.io ruby on rails_第5张图片

点击hostname进入网址,可以看到我们写的appfly.io ruby on rails_第6张图片

添加参数,也可以正常使用fly.io ruby on rails_第7张图片

 设置ssl 域名

点击图中的选项,可以进行域名的设置

fly.io ruby on rails_第8张图片

 保存之后,就可以输入域名进行访问了fly.io ruby on rails_第9张图片

不需要的项目可以进行删除,比如最先创建的错误的APP1234 fly.io ruby on rails_第10张图片

你可能感兴趣的:(ruby,on,rails,ruby,后端)