Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Ruby on Rails 7!
You have completed Introduction to Ruby on Rails 7!
Preview
Take your Rails app live! Walk through the entire process of deploying your project to Fly.io. Learn how to set up an account, configure your app, and manage environment variables for a seamless production experience.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Okay, hello everyone.
0:04
In this video, we're going to
be deploying our application.
0:05
We're going to be deploying it to fly.io.
0:08
And as you can see on the screen now,
I have my deployed application.
0:11
Everything works, you can sign up,
all of the database stuff works,
0:14
you can sign up, you can create Linktrees.
0:18
And yeah, it's good, and it's all free.
0:21
So, without further ado, let's jump
right into it and finish this project.
0:24
So, the first thing that we have to do is
to change our database that we're using to
0:27
PostgreSQL.
0:30
PostgreSQL is just better, it's faster,
and it's what they use in production.
0:31
So, to do that, the first thing
that we're going to do is go in and
0:35
install PostgreSQL.
0:38
So, go to PostgreSQL, I'll include
the link in the description, but for now,
0:39
this is good.
0:44
I'm going to click on Windows,
then I'm click Download the Installer, and
0:44
that's fine.
0:49
And then I'm going to
click on Windows x86-64.
0:51
Download this one,
as you can see, it's downloading.
0:54
I already have it downloaded,
so I'm gonna open it up.
0:57
Once it's downloaded, double click it,
we're gonna click Yes.
1:00
And this is gonna take quite a bit of time
to download, so I'm probably gonna stop
1:06
the recording just so it doesn't
get too big in the middle of it.
1:10
And here's the PostgreSQL setup wizard,
click Next, then click Next.
1:13
And make sure you tick all of these,
because we want to install all of these.
1:20
So, PostgreSQL server, yes.
1:24
PgAdmin 4, yes.
1:26
Stack Builder, yes, and
Command Line Tools, yes.
1:28
Next, Next, and finally, Next.
1:31
Okay, so, now it's installing,
I will see you when it's done installing.
1:35
Okay, so I've gotten to this part and
it says launch Stack Builder at exit.
1:39
And we're just gonna launch it and
we're going to click Finish and
1:44
then click Cancel.
1:46
Now that we've successfully
installed PostgreSQL,
1:47
we can get started on
actually changing this.
1:50
So, go to Command prompt and go to your
folder, your Ruby on Rails folder.
1:53
And the command that we're going to run
is Rails DB system change to PostgreSQL.
1:57
So, hit Enter and this is obviously,
it changes the system to PostgreSQL and
2:02
there are some more things
that we're gonna have to do.
2:06
It says, yep, click, Yes.
2:09
Okay, and then it created some files.
2:12
Now, let's see what it did.
2:14
Well, this is what it did.
2:16
It went in the gem file,
it added pg, this gem and
2:17
it also got rid of SQLite,
the previous database.
2:21
And then in that file config database.yml,
it added this.
2:26
So, now we're using Postgres.
2:31
All we need to do now
is start up pgAdmin4.
2:33
So, go instead of pgAdmin4,
you can type it in here, start.
2:38
So, once pgAdmin4 is started, we're going
to click on Servers and PostgreSQL, please
2:41
enter the password for the user postgres
to connect to the server, PostgreSQL 16.
2:46
Save Password, and we're gonna enter
the password 1, 2, 3, 4 5, 6, 7, 8.
2:50
Okay, so go to Login/Group Roles and
then click on postgres and
2:56
we're gonna click on this button.
3:01
And when we're gonna go to password and
our password is gonna be 1, 2,
3:04
3, 4, 5, 6, 7, 8, Save.
3:08
Now, what we can do here is we can say
username postgres because that's the name
3:10
of the username.
3:15
Look, in Login/Group Roles we're
gonna be using the postgres, and
3:16
then the password is what we just entered.
3:21
So, 1, 2, 3, 4, 5, 6, 7, 8.
3:24
So, now, if we try to create
a new database, it should work.
3:27
So, let's do it.
3:32
Rails DB create, and
it says database link tree
3:33
development clone already exists and
that's fine.
3:37
So, we have our databases now and
we can run Rails S.
3:42
If everything works and
3:46
the Rails S works, then we've successfully
changed to PostgreSQL and that's great.
3:47
So, I'm gonna run the server,
go to 127.001 and
3:52
yeah, okay, it seems to be working.
3:58
Lemme just try and sign up.
4:02
So, now that we know this is working,
we're gonna head and
4:03
actually deploy our app.
4:06
So, this is the service that we're
gonna be using to deploy our app,
4:08
it's called fly.io.
4:11
It's a good service because it
allows us to do it for free.
4:12
Can of course use Render,
4:15
which is another tool that you
can use to host your app online.
4:17
But we're gonna be using Fly as I've
already done it and it's easy for me.
4:22
But of course you can use Render,
they're both fine.
4:26
Okay, so, the first thing that we're gonna
do is search up fly.io for Ruby on Rails.
4:29
And these are the Fly documentation.
4:36
So, we're gonna click on Rails Starter
App Guide and here's what it says.
4:38
So, the first thing that we need
to do is to download the flyctl.
4:43
This is their CLI app for managing apps.
4:47
So, this is what you need to do first go,
to their installation guide,
4:50
I already have installed,
this is the installation guide.
4:54
You can either run this, run this command.
4:57
If you're on Linux, run this, and
if you're on Windows, run this.
4:59
You have to run this in PowerShell.
5:02
PowerShell, you shouldn't
already have PowerShell,
5:04
you're gonna have to download PowerShell.
5:07
So, download PowerShell online,
go to the Windows website and
5:08
then click on PowerShell.
5:13
So, it should be down here somewhere.
5:15
Here, click on this one, .msi and
it's downloading PowerShell.
5:17
Then when you get PowerShell,
you need to run this command, and
5:23
then it will download the flyctl.
5:26
So, I'm just gonna show
you because it's easy.
5:28
So, PowerShell, and then run this command.
5:32
I believe it's just, yeah,
PowerShell, run this command, Enter,
5:38
and it should download the flyctl so
we can get started using Fly.
5:42
By the way, the first thing that you
actually have to do before you download
5:49
the flyctl is to sign up.
5:53
All you have to do is input your email and
password and that's it, just sign up.
5:54
Okay, so flyctl was successfully
installed to my drive.
5:59
What's next?
6:04
Okay, so
once you have the flyctl downloaded,
6:05
it's really easy to get this started and
your application online.
6:07
So, what you have to do is
run the command Fly Launch.
6:12
And essentially we
are launching the app now.
6:15
But after this, there's one more step and
it's gonna be called Fly Deploy.
6:18
And as you can see,
it gives us our organization, Malachi,
6:21
our name of the app, the region,
the app machines, our database, and Redis.
6:25
Redis is another type of thing,
but we're not using it right now.
6:30
So, wait for this command to run and
then I'll be back with you after it's
6:33
completely run and
then just hit Enter if it's not working.
6:37
And here's an important part,
here are your Rails credentials.
6:40
I'm gonna take a screenshot
of those credentials.
6:43
And so, screenshot that with
Windows print scheme, and okay,
6:46
now we've run Fly Launch, we have run
the command, now it's time for Fly Deploy.
6:50
After this command, the website
should be up and running online and
6:56
everything should be ready,
and it should work.
7:00
So, this is the moment of truth.
7:03
All of our work over the past hour and
a half of this course, if it works,
7:05
it works, if it doesn't work,
there's more work for me to do [LAUGH].
7:10
Of course it will work,
I have faith, but you never know.
7:16
It's almost done, we're getting there.
7:21
My God.
7:23
Need to add some tense, epic music to
cuz we're about to see a wrap online.
7:24
Everything done.
7:28
Okay, it says visit your newly
deployed app at this link.
7:29
I'm gonna copy this link into the browser.
7:34
I'm gonna give it three seconds just
to make sure everything is online.
7:37
And I'm going to try it.
7:42
Let's see if this works.
7:44
My God, it works, perfect.
7:48
All right, let's see if signing up works.
7:50
1, 2, 3, 4, 5, 6, 1, 2, 3,4, 5, 6,
create and I'm signed in, it worked.
7:52
Let's see if changing the email works.
7:59
And yep, it works,
it's actually blazing fast.
8:02
It looks like there's an issue there,
it starts the CSS every now and again
8:06
whenever I press a link, it resets the CSS
or something, but that's not a big deal.
8:10
Lemme try and create a Linktree.
8:16
So, YouTube, Instagram.
8:19
There we go, there we go, there we go,
there we go, there it is.
8:21
The friendly_id is working,
everything is working.
8:26
The Instagram takes me to Instagram and,
yeah.
8:30
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up