How to deploy a Rails 6 application to Heroku

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey friends what's going on we have been working on building out this tool for automating parts of the video production process and getting things on youtube uh specifically being able to sync youtube uh like videos for youtube descriptions and thumbnails for youtube descriptions but today what we're going to do is show how to deploy this app to heroku so i have a heroku account already set up but i'm actually going to use the heroku tool belt which is something that you can install and it is a command lined interface for working with heroku and this is almost exclusively how i generally prefer to work with heroku is through the the tool belt here and so you can just install with homebrew if you're if you're using homebrew otherwise you can do a lot of this stuff through the the web interface for the heroku dashboard but i want to do it through the terminal so i'm going to say heroku apps create and then i'm just gonna call this one like video autumn or like auto video or something um and this is gonna create the app and give it the name auto video um and so yeah i didn't mean app create i'm in apps create so i often forget what the exact commands are but um so audio video is already taken auto video auto mate automate video let's see okay so automate video we were able to create the app and what that does is it creates a remote so i have i have the the origin which is that's where i'm pushing up my git repo to github where it's hosted but there's an a new remote called heroku and now you can just like push to heroku you can put push your git repository to heroku and that will spin up uh the heroku build pack and everything for it so i can say git push heroku main and this should create or like push all of our code up to heroku and then we should be able to see it by going to this automate video.herokuaapp.com thing the ruby version you're trying to install doesn't exist on this stack so we're trying to use 2.6.3 on heroku 20. so by default it created it on heroku 20 but it doesn't have that on there so i wonder if we need to change the build pack this i've never actually run into this issue so this is interesting so let's see what we might have to do here all right we want to look at how to change the stack so heroku stack set and then the kind that you want so let's just say we want heroku 18 and that should be fine git push roku master and let's see what happens oops main old habits die hard okay so it's pushing up again it's going to try again to build this all right looks like it got through the ruby bit now it's installing our gems okay cool so uh this is the the upload completed successfully um and now we should be able to see something here and so if we open up automate video.heroapp.com we see a big error message that says something went wrong so we need to do a couple of things number one we have to migrate the database we can say heroku run and then this allows you to just like execute a bunch of stuff on the heroku box so we're going to say rake db migrate and we'll also need to update our key our master key on heroku so that it is able to decrypt our secrets our encrypted secrets and so this is a value that's stored in config master key and when you're working in development that is the value that's used to decrypt that secrets file so if we look here and go to config credentials.yaml.encrypt right like this file is encrypted using this master key so we're gonna we're gonna cat out that master key and pipe it into or like set it on heroku as an environment variable so that we're able to decrypt those secrets all right cool so if we if we refresh the page now on automatevideo.herocoap.com we see our our video here and it's mostly up and running but this error that we're seeing here is likely because we haven't decrypted those secrets so if we ran um heroku logs t that allows us to tail the logs and then if we refresh this page we should see the the errors that are happening and so we can see the requests that are coming in this one is a 500 we don't really get very much detail other than the fact that it's a 500 so generally what i will what i'll do is i'll set up and connect an app called paper trail to to help with logging but for now i know that we still haven't set the master key for decrypting so let's do that next so what we need to do is it's like heroku let's just google it here heroku set master key for rails because i want to see if there's like a an easier way to do this other than just printing out the string um okay here we go here we go this is what i was looking for so i don't have to show you what the actual value is let's see what happens um okay well sure it printed it out there i'll have to to hide that but now that the master key is set if we come back to automate video.herokuapp.com um we should have our api keys set so if we the other thing too is that if we attempt to connect to youtube youtube doesn't know about this domain and so it's going to it's probably going to fail so if we go to like um we have to go into our youtube api console and from inside of the api console we have to set it up to no so that it knows that we are able to redirect from this specific domain right now it's only configured to work with localhost so we need to set up that that domain credentials um okay so here's where we want to add a uri okay so we're gonna say https colon slash slash and then we're gonna add in this the heroku domain that we just created for this roku app and then ultimately we'll we'll put in a uri for our actual live production domain i have not actually purchased a domain this is like one of the first times i've deployed to heroku but don't have a domain already purchased so now if we refresh this page and click on connect to youtube look at that we're brought over to youtube and now i can say yes this is the the account that i want ah but we're redirecting back to localhost 3000 so we have a bug in our um youtube sessions controller is just redirecting to localhost so we need this to be like if rails.m.development go there else and i'm just going to keep it simple i know that technically you can like i think we can use url for here let's actually let's try that let's try that url for um and then it's gonna take in the action which is uh youtube sessions and oh what was it before um callback right yeah okay so url for action is youtube sessions and or this is the controller and the action is call back all right let's see if this works so if we're running locally then the redirect uri should be bringing us back to localhost so we should be redirected back to localhost if we were and then if we deploy this change to back to heroku then this will like re-push all of our code to heroku and will allow us to hopefully redirect back without needing to set up that url for situation i i can't remember if that url4 will know actually there's no way it needs it's going to know the domain so we need to like set um we have to set up the domain i think it's part of action mailer so let's just go look around here so mailer um yeah so config action mailer default url options is i think what we need to set so let's go over here to config application no config environments production mailer so it's just it's just the host so um host is as the heroku app and we should be good to go okay so it looks like it was deployed refresh the page so every time it deploys it's going to take a little bit of time for the first request to load up and that's because it's like booting up the ephemeral box that this thing lives on so we click connect to youtube um your uri doesn't match your whatchamacallit maybe this needs to be https where did we go oh you know what we're missing the callback bit here okay save okay go here all right so now we're connected on heroku we've connected to our our youtube account so now if i ran heroku run actually yeah heroku run rake db seed that'll create some of the basic stuff so the category and some other basics that we've seen before and then the other piece that we want to do is run our task for fetching uh the youtube videos the other thing i need to do is before i actually share this episode where we're deploying is i want to put a little bit of authentication in front of in front of this page because right now if you land on the domain you're just going to like have access to change and edit and update the videos my videos and so uh yeah i do want to i want to make it so that like potentially other people could um could log in or create accounts and then sync their own videos but for now this is still like very much just in development so heroku run rake youtube fetch videos so this should run um one of the really cool things that heroku has is a tool called scheduler heroku scheduler and so you can just drop in tasks like this you can just say like run like in the scheduler you would write rake youtube fetch videos and then it would just run on a schedule like on a cron schedule that you define now the granularity isn't super great for the scheduler but we'll take a look and see what that supports it's more than enough for most folks in terms of like automated basic background tasks refresh the page and look at that automate video automate video to herokuapp.com now has all of our video so that's pretty sweet um conskit in meta programming um that's this is a video that we have that's up so this this looks good we're deployed to heroku and everything seems to be working great thumb if we go to slash thumb this is our like little tool for creating thumbnails automatically so that's looking good and yeah so that's all i want to do in this episode was show you how to deploy to heroku um how to look at heroku logs uh and yeah let's you can also open applications so if i say heroku add-ons colon open and then say scheduler i think this might be a built-in add-on i might need to add it though okay so we have to say like heroku add-ons create scheduler and let's see if that installs the scheduler for okay so it looks like that installed the scheduler and now we can open it with this yeah so we will be coming in here to create a job later that will then fetch videos and stuff like that so um yeah creating a job is pretty easy you just say like okay i want to run this thing every day and i want it to run rake youtube colon fetch videos and then um probably at oh gosh what is i don't know uh 8 a.m utc and then save the job and now that'll run every single day at eight a.m and it will attempt to fetch the videos so that's pretty handy and that's how you can create um create your own background job based on a rake task and we i think we created the rake task in like the first one of the first three videos of this series for video automation so if you wanted to head back in the playlist and just check those out you would see how to build this rake task which fetches the youtube videos from the api and then builds those out in just like this very simple list okay cool so that's how we deployed heroku this is where this thing is going to live eventually we will find a real domain and assign the domain and set that up and i want to walk through that with you but for now this is good and um yeah i know so yeah in the next one i think we're gonna do authentication because we need to protect this page so that uh folks can sign up for new accounts and then once you have an account you can connect your youtube and then start using the the tools to sync descriptions and sync thumbnails and such so um yeah so we'll see you in the next one
Info
Channel: CJ Avilla
Views: 437
Rating: 5 out of 5
Keywords: deploy to heroku, deploy rails to heroku, how to deploy rails to heroku, how to deploy ruby on rails to heroku, deploy rails 6 to heroku, how to deploy rails 6 to heroku, ruby on rails, deploy, ruby, how to deploy ruby to heroku, how to set master key on heroku, heroku tutorial, web development, rails heroku, ruby on rails tutorial, rails heroku deploy, rails heroku master key, how to deploy to heroku from terminal, how to deploy frontend and backend to heroku
Id: 3wmMtHz2zpY
Channel Id: undefined
Length: 15min 39sec (939 seconds)
Published: Fri Mar 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.