Ruby On Rails
Installing Ruby
Edgegap offers you a very intuitive platform to deploy a serverless web application wherever you need it. For this tutorial, we will go over the steps to deploy a Ruby on Rails. Before checking for anything else, make sure you have Ruby installed.
If youâre running on a Linux/UNIX machine, you can use the pre-installed package manager on your machine and install Ruby through your terminal. You can refer to Rubyâs official documentation to find the precise command that corresponds to your Linux/UNIX distribution.
On Windows machines, you will have to download RubyInstaller to get Ruby.
At the end of the installation, you can check Ruby is installed properly with the following command:
Now with Ruby installed, you will obviously have to install Rails. This is rather straightforward and can be done with this single command:
You can easily confirm that Rails was installed correctly in a similar way as what we used to verify Rubyâs installation.
Requirements
To follow this tutorial, you will need to have the following besides Ruby and Ruby on Rails:
Access to Edgegap's private container repository or another registry like Docker's container registry
Getting Started with Ruby on Rails
To get started with ruby on rails, you will have to create a folder for your new project and run the following command on it:
Once the process finishes installing, you will have to modify your routes.rb file, which you will find in the config folder. Your routes file should contain the following:
You may notice there is no âhello_worldâ page in your project in the âviewsâ folder. You can easily generate it with its corresponding controller. First, make sure youâre in the folder Rails generated for you when you ran the rails new
command.
If youâre using a Linux distribution, use the following command to create the HelloWorld controller:
The skip-routes option ensures this command wonât generate a new route to this controller, which is what we want since we already created one manually.
For windows, you will have to add some keywords to your command as follows:
Once the command executes successfully, you will see the HelloWorld page in the âviewsâ folder. You may have to correct the HTML syntax to get a proper section before you deploy it. The file should look like this:
The only step left to do to finish your project is deploying your Ruby on Rails app locally. Once again, the command to do so varies between Linux and Windows as follows:
Linux:
Windows:
Containerize your application
Containerizing most applications is straightforward. You must create a Dockerfile and then run that file on Docker to create the image. Visual Studio Code is a good platform to create your Dockerfile since, by default, it does not put an extension to every new file that we create. That is exactly what we need. Simply create a new file and name it Dockerfile. You will see the little docker logo appear next to it. Now, you can copy and paste this script into it to get the main dependencies. The image this dockerfile will create is around 700 MB. Of course, you can optimize it, but a container this size will run very smoothly on Edgegap:
After saving your Dockerfile, it is time to create the image. You can easily do so by running the following command:
For ARM CPU (Mac M1, M2, etc.) users, see the dedicated page.
It is preferable you put a version number following semantic versioning, but if you donât plan on updating your build on Edgegap after your first deployment, you can omit the version number entirely. But before that, you need to push your newly created docker image to the image repository of your choice. Remember that we offer private repositories through Edgegap Registry that offer you a series of security advantages you would not necessarily have by using the default Docker repository. To push your image to our repository, you will have to first log in with your credentials by using this command:
Now, the only thing left is to push your image like this:
Great! Now, you are only one step away from deploying your Nuxt app on Edgegapâs platform.
Deploy your application on Edgegap
There are two ways of deploying an application on Edgegap. For both, you will need to have an account with us, which you can create for free by clicking the link right here. First, letâs go over on how to deploy our containerized application through our website.
Deploying an application through Edgegapâs dashboard
You will have to head over to the Edgegap Platform website and enter your credentials. Once you do so, you will be automatically redirected to your dashboard. If you have just created your account, you will see an option to launch your first application right away. If not, simply head to the âApplications & Gamesâ tab on the menu on the left of your screen. You will see an option to create a new application on the right corner:
Once you click on it, the following form should appear:
You should fill all the required fields and, once youâre done, there is a few things you will need to modify from the defaults:
Port number: This application needs to have port 3000 open, so please add it in the âportsâ section of the creation form. Uncheck the option to verify the port.
Once youâve finished filling out the form with the adequate information, you simply must submit it, and you will be ready for deployment. Simply select the region and the number of players you wish to emulate.
Once youâve finished filling out the form with the adequate information, you simply must submit it, and you will be ready for deployment. Simply select the region and the number of players you wish to emulate.
Once you confirm your choices, your application will be online shortly. Hereâs what you will see once itâs been deployed. You can access it yourself by clicking on the icon weâve circled in this image.
This will open a new tab where you will find the default landing page of your Nuxt application.
Deploying an application through Edgegapâs API
While our web dashboard is the most user-friendly way of deploying an application, you can also do so through a very simple API request. For this, you can use postman. It is important you visit the dashboard to create an API token through the options on your profile.
Once you have the API token in your hands, the only thing left to do is formulate a deployment request with your application name, its version, the IP addresses, the region you want to make your deployment in and, of course, your token as part of the authorization parameters. You can see what a full request looks like on our documentation here.
Once you send the request, you should see a response on your command line or on Postman should look like this:
That is all you must do to deploy an application through a CLI. To confirm your app was deployed, you can head over to the dashboard again and see your active deployment at work by clicking on the âActive deploymentsâ tab.
Last updated
Was this helpful?