
Ruby on Rails, is a web application framework that has revolutionized the way we build modern web applications. It's known for its "convention over configuration" philosophy, which simplifies development tasks and allows programmers to focus on building exceptional features.
Acorn is a cloud computing platform with a big free sandbox that anyone can use by registering with a GitHub account. It is designed to simplify running modern cloud-native apps on the public cloud. You use familiar development and deployment workflows based on mainstream container tools without having to deal with provisioning or configuring any underlying cloud resources. Basically it provides all the power of Kubernetes and Terraform, without any of the complexity.
To deploy an application on Acorn we need to define our application as an Acornfile, which will produce the Acorn Image that we can deploy on the platform. In this tutorial, we will explore how to provision a sample Ruby on Rails Application on Acorn.
If you’re the kind of person who likes to skip to the end, you can deploy the sample application in your sandbox now and just start poking around in it. Sandbox deployments in Acorn are restricted by size, and run for two hours, so it should provide plenty of time for you to evaluate and test anything. You can start them over as often as you like, or you can upgrade to a paid Pro account if you want to run something in production.
If you want to follow along, I’ll walk through the steps to deploy the sample Articles App using Acorn, described in the Ruby on Rails official documentation.
Note: Everything shown in this tutorial can be found in this repository.
Login to the Acorn Platform using the Github Sign-In option with your Github user.
After the installation of Acorn CLI for your OS, you can login to the Acorn platform.
In this post we will create a simple RoR Articles app from the official documentation. It is a simple Articles application that provides standard CRUD features to manage your blog posts.
In the Acorn platform, there are two ways you can try this sample application.
The First way is the easiest one where, in just a few clicks you can deploy the Articles application on the platform and start using it. However, if you want to customize the application or want to understand how you can run your own RoR applications using Acorn, use the second option.
In this option you use the published Acorn application image to deploy the articles sample application in just a few clicks. It allows you to deploy your applications faster without any additional configurations. Let us see below how you can deploy the articles app to the Acorn platform dashboard.
Login to the Acorn Platform using the Github Sign-In option with your Github user.
Select the “Create Acorn” option.
Choose the source for deploying your Acorns
3.1 Select “From Acorn Image” to deploy the sample Application.
3.2 Provide a name “Ruby on Rails Sample Acorn”, use the default Region and provide the URL for the Acorn image and click Create.
ghcr.io/infracloudio/ruby-on-rails-acorn:v6.1.4-0
Note: The App will be deployed in the Acorn Sandbox Environment. As the App is provisioned on AcornPlatform in the sandbox environment it will only be available for 2 hrs and after that it will be shutdown. Upgrade to a pro account to keep it running longer.
Once the Acorn is running, you can access it by clicking the Endpoint or the redirect link.
4.1 Running Application on Acorn
4.2 Running Articles app
As mentioned previously, running the acorn application using CLI lets you understand the Acornfile. With the CLI option, you can customize the sample app to your requirement or use your Acorn knowledge to run your own Ruby on Rails application.
To run the application using CLI you first need to clone the source code repository on your machine.
Once cloned here’s how the directory structure will look.
We have the sample Rails Application ready. Now to run the application we need an Acornfile which describes the whole application without all of the boilerplate of Kubernetes YAML files. The Acorn CLI is used to build, deploy, and operate Acorn on the Acorn cloud platform. It also can work on any Kubernetes cluster running the open source Acorn Runtime.
Below is the Acornfile for deploying the Articles app that we created earlier.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/ror_acornfile_b83d96a7c6.png" alt="ror-acornfile" width="400" /></p>There are 2 requirements for running Ruby on Rails Application
The above Acornfile has the following elements:
We have already logged in using Acorn CLI now you can directly deploy applications on your sandbox on the Acorn platform. Run the following command from the root of the directory.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/acorn_run_ror_cli_c4df932062.png" alt="acorn_run_ror_cli" width="450" /></p>
Below is what the output would look like.
As it is a simple Article application it provides CRUD features. Here you can add your Articles.You need to click on New Article and provide Title and Body of Article. Once the article is created it can be edited and if you want to delete it you can use the destroy button.
Once completed you can move it to complete status and If you want to delete it you can delete it using delete button.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/ror_articles_app_with_article_7b34e8a23c.png" alt="ror_articles_app_with_article" width="400" /></p>If you are developing your application and don't want to start and stop the application everytime you make the changes you can use the incredibly helpful Acorn Dev Mode. Running in dev mode allows you to do continous development of the application, and have your running instance reflect the changes as soon as you save your changes. Run the following command.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/ror_run_dev_mode_90a5270e51.png" alt="ror-run-dev-mode" width="450" /></p>Using the Dev mode you can easily modify the application as per your requirement and once the application is working as expected and is ready to be built and packaged, push it to a registry. You can push it to any OCI registry. We will use Github Container Registry in this example. Once published, you can use the acorn image to deploy it directly in the Acorn platform using the dashboard or CLI, as described previously.
Log in to the registry with the command below and follow the prompts.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/acorn_cli_login_ghcr_c85ad84519.png" alt="acorn_cli_login_ghcr" width="450" /></p>Build and push the image with the below command.
<p align="center"><img src="https://necessary-creativity-bc071c3082.media.strapiapp.com/ror_push_to_ghcr_5101e73a78.png" alt="ror-push-to-ghcr" width="650" /></p>Once the application is built and pushed you can use those images to run your application on Acorn Platform.
The App is provisioned on Acorn Platform and is available for two hours. Upgrade to Pro account for anything you want to keep running longer. After deploying you can edit the Acorn Application or remove it if no longer needed. Click the Edit option to edit your Acorn's Image. Toggle the Advanced Options switch for additional edit options. Remove the Acorn by selecting the Remove option from your Acorn dashboard.
In this tutorial we show how we can use the Acornfile and get our Rails application up and running and it’s very easy to make changes to the Application file when you are developing it without the need of restarting your application. And If you are looking to run the application directly you can run it on Acorn Platform by providing the image name.