-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ruby.html.markerb
187 lines (131 loc) · 6.1 KB
/
ruby.html.markerb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
title: "Run a Ruby App"
layout: language-and-framework-docs
sitemap: false
redirect_from: /docs/getting-started/ruby/
---
Deploying a Ruby application on Fly.io requires two essential ingredients:
a [Gemfile](/docs/languages-and-frameworks/ruby/) and a [config.ru](https://github.com/rack/rack/wiki/(tutorial)-rackup-howto) file.
Full-stack frameworks like Rails, Padrino, and Hanami provide both of these for you.
Micro-frameworks like Sinatra, Camping, and Rack itself require you to create your own.
## Gemfile
If you don't have a gemfile, the best way to get started is to run:
```cmd
bundle init
```
Once this file is created, proceed to add gems needed by your application, for example:
```cmd
bundle add rackup
```
The Gemfile needs to include the framework you may be using, so if you are using, for example, Sinatra or Camping, add that gem too.
Finally add a web server, like puma, thin, or falcon. If you are not sure what web server to use, puma is a safe bet:
```cmd
bundle add puma
```
## config.ru
The most basic `config.ru` file would be the following:
```ruby
run do |env|
[200, {}, ["Hello World"]]
end
```
Phusion Passenger guides provide a [helpful list](https://www.phusionpassenger.com/docs/advanced_guides/deployment_and_scaling/apache/config_ru.html) of starter `config.ru`
files for various Ruby web frameworks.
We're now ready to run the app locally.
## _Running The Application_
Run `bundle exec rackup` to start the application
```cmd
bundle exec rackup
```
```output
Puma starting in single mode...
* Puma version: 6.1.1 (ruby 3.2.1-p31) ("The Way Up")
* Min threads: 0
* Max threads: 5
* Environment: development
* PID: 26873
* Listening on http://127.0.0.1:9292
* Listening on http://[::1]:9292
Use Ctrl-C to stop
```
If you see a message suggesting that you need to run `bundle binstub rack`, that message can be safely ignored.
And connect to localhost:9292 to confirm that you have a working Ruby application. Now to package it up for Fly.
## _Install Flyctl and Login_
We are ready to start working with Fly and that means we need `flyctl`, our CLI app for managing apps on Fly. If you've already installed it, carry on. If not, hop over to [our installation guide](/docs/hands-on/install-flyctl/). Once that's installed you'll want to [log in to Fly](/docs/getting-started/log-in-to-fly/).
## _Launch the app on Fly_
To launch an app on fly, run `flyctl launch` in the directory with your source code. This will create and configure a fly app for you by inspecting your source code, then prompt you to deploy.
```cmd
flyctl launch
```
```output
Creating app in /Users/rubys/tmp/snapshot
Scanning source code
Detected a Ruby app
? Choose an app name (leave blank to generate one):
? Select Organization: Sam Ruby (personal)
Some regions require a paid plan (fra, maa).
See https://fly.io/plans to set up a plan.
? Choose a region for deployment: Ashburn, Virginia (US) (iad)
Created app 'late-bird-1771' in organization 'personal'
Admin URL: https://fly.io/apps/late-bird-1771
Hostname: late-bird-1771.fly.dev
? Would you like to set up a Postgresql database now? No
? Would you like to set up an Upstash Redis database now? No
Wrote config file fly.toml
Your Ruby app is prepared for deployment.
If you need custom packages installed, or have problems with your deployment
build, you may need to edit the Dockerfile for app-specific changes. If you
need help, please post on https://community.fly.io.
Now: run 'fly deploy' to deploy your Ruby app.
...
```
First, this command scans your source code to determine if it meets the requirements for a deployable Ruby app.
After your source code is scanned and the results are printed, you'll be prompted for an organization. Organizations are a way of sharing application and resources between Fly users. Every fly account has a personal organization, called `personal`, which is only visible to your account. Let's select that for this guide.
Next, you'll be prompted to select a region to deploy in. The closest region to you is selected by default. You can use this or change to another region.
Finally you will be given the option to start a Postgres and/or a Redis database. If you need one or both, it is convenient to set them up now. Otherwise you can always add them later.
At this point, `flyctl` creates an app for you and writes your configuration to a `fly.toml` file. You'll then be prompted to build and deploy your app. Once complete, your app will be running on fly.
## _Config First!_
Most Dockerfiles expect some configuration settings through `ENV`. The generated `fly.toml` file has a place for you to add your custom `ENV` settings. It's the `[env]` block.
```toml
[env]
MY_SPECIAL_ENV = "some_value"
MAX_PLAYER_COUNT = "15"
```
Add whatever values your Dockerfile or container requires.
Sometimes you have secrets that shouldn't be checked in to `git` or shared publicly. For those settings, you can set them using [`fly secrets`](https://fly.io/docs/reference/secrets/#setting-secrets).
```cmd
fly secrets set MY_SECRET=romance
```
```output
Secrets are staged for the first deployment
```
You can list the secrets you've already set using `fly secrets list`
```cmd
fly secrets list
```
```
NAME DIGEST DATE
MY_SECRET b9e37b7b239ee4aefc75352fe3fa6dc6 1m20s ago
```
The values aren't displayed since they are secret!
## _Deploying to Fly_
To deploy changes to your app, just run just run:
```cmd
fly deploy
```
This will lookup our `fly.toml` file, and get the app name from there. Then `fly` will start the process of deploying our application to the Fly platform. Flyctl will return you to the command line when it's done.
## _Connecting to the App_
The quickest way to browse your newly deployed application is with the `flyctl open` command.
```cmd
fly apps open
```
```output
Opening http://helloruby.fly.dev/
```
Your browser will be sent to the displayed URL. Fly will auto-upgrade this URL to a HTTPS secured URL.
## _Arrived at Destination_
You have successfully built, deployed, and connected to your first Ruby application on Fly.
You can monitor and explore your app with the following command:
```cmd
fly dashboard
```