Skip to content

Commit e4b7f5a

Browse files
authored
Merge pull request #2400 from odidev/ruby_LP
Deploy Ruby on Rails on Google Cloud C4A (Arm-based Axion VMs)
2 parents 6f97b86 + df53d61 commit e4b7f5a

File tree

14 files changed

+551
-0
lines changed

14 files changed

+551
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Deploy Ruby on Rails on Google Cloud C4A (Arm-based Axion VMs)
3+
4+
draft: true
5+
cascade:
6+
draft: true
7+
8+
minutes_to_complete: 40
9+
10+
who_is_this_for: This learning path is intended for software developers deploying and optimizing Ruby on Rails workloads on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors.
11+
12+
learning_objectives:
13+
- Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors)
14+
- Install Ruby/Rails on a SUSE Arm64 (C4A) instance
15+
- Validate Ruby on Rails functionality using PostgreSQL as the database
16+
- Benchmark Rails performance using the built-in Ruby Benchmark library on Arm64 (Aarch64) architecture
17+
18+
19+
prerequisites:
20+
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
21+
- Basic familiarity with Ruby programming, the Rails framework, and [relational databases](https://www.postgresql.org/)
22+
23+
author: Pareena Verma
24+
25+
##### Tags
26+
skilllevels: Introductory
27+
subjects: Web
28+
cloud_service_providers: Google Cloud
29+
30+
armips:
31+
- Neoverse
32+
33+
tools_software_languages:
34+
- Ruby
35+
- Rails
36+
- PostgreSQL
37+
38+
operatingsystems:
39+
- Linux
40+
41+
# ================================================================================
42+
# FIXED, DO NOT MODIFY
43+
# ================================================================================
44+
further_reading:
45+
- resource:
46+
title: Google Cloud documentation
47+
link: https://cloud.google.com/docs
48+
type: documentation
49+
50+
- resource:
51+
title: Ruby on Rails documentation
52+
link: https://guides.rubyonrails.org/
53+
type: documentation
54+
55+
- resource:
56+
title: Ruby built-in Benchmark documentation
57+
link: https://github.com/ruby/benchmark?tab=readme-ov-file#benchmark
58+
type: documentation
59+
60+
weight: 1
61+
layout: "learningpathall"
62+
learning_path_main_page: "yes"
63+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# ================================================================================
3+
# FIXED, DO NOT MODIFY THIS FILE
4+
# ================================================================================
5+
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
6+
title: "Next Steps" # Always the same, html page title.
7+
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
8+
---
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Getting started with Ruby/Rails on Google Axion C4A (Arm Neoverse-V2)
3+
4+
weight: 2
5+
6+
layout: "learningpathall"
7+
---
8+
9+
## Google Axion C4A Arm instances in Google Cloud
10+
11+
Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications.
12+
13+
The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud.
14+
15+
To learn more about Google Axion, refer to the [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu) blog.
16+
17+
## Ruby on Rails
18+
19+
Ruby on Rails (Rails) is an open-source, server-side web application framework written in Ruby.
20+
21+
It allows developers to build database-backed web applications quickly using convention over configuration, MVC (Model-View-Controller) architecture, and built-in tools for routing, database migrations, and view rendering.
22+
23+
Rails is widely used for web applications, APIs, and full-stack development projects. Learn more from the [Ruby on Rails official website](https://rubyonrails.org/) and its [guides and documentation](https://guides.rubyonrails.org/).
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: Ruby on Rails Baseline Testing on Google Axion C4A Arm Virtual Machine
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Baseline Setup for Ruby on Rails with PostgreSQL
10+
This section covers the installation and configuration of **PostgreSQL** and a **Rails application** on a SUSE Arm-based GCP VM. It includes setting up PostgreSQL, creating a Rails app, configuring the database, and starting the Rails server.
11+
12+
### Install and Configure PostgreSQL
13+
PostgreSQL is used with Ruby on Rails as a robust, production-ready relational database that reliably stores and manages application data.
14+
15+
```console
16+
sudo zypper install postgresql-devel postgresql-server
17+
sudo systemctl start postgresql
18+
sudo systemctl enable postgresql
19+
```
20+
- `postgresql-devel` is required to compile the pg gem for Rails.
21+
22+
Verify that the PostgreSQL service is active and running:
23+
24+
```console
25+
systemctl status postgresql
26+
```
27+
28+
This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**.
29+
30+
```console
31+
sudo -u postgres createuser --superuser gcpuser
32+
```
33+
- `sudo -u postgres` → Runs the command as the `postgres` user (default PostgreSQL superuser).
34+
- `createuser --superuser gcpuser` → Creates a PostgreSQL role named `gcpuser` with full admin privileges.
35+
- Can create databases
36+
- Can create other roles/users
37+
- Can grant privileges
38+
39+
This role will be used by Rails to connect to the PostgreSQL database.
40+
41+
### Create a Rails App with PostgreSQL
42+
Creates a new Rails application configured to use PostgreSQL as its database.
43+
44+
```console
45+
rails new db_test_rubyapp -d postgresql
46+
cd db_test_rubyapp
47+
bundle install
48+
```
49+
- Creates a new Rails application called `db_test_app`.
50+
- `d postgresql` → Tells Rails to use PostgreSQL as the database instead of the default SQLite.
51+
- `bundle install` ensures all required gems are installed.
52+
53+
{{% notice Note %}}
54+
Check `config/database.yml` to ensure the `username` and `password` match your PostgreSQL role `(gcpuser)`.
55+
{{% /notice %}}
56+
57+
### Verify and Update Database Configuration
58+
Open the Rails database configuration file:
59+
60+
```console
61+
nano config/database.yml
62+
```
63+
Find the `default`: and `development`: sections.
64+
Ensure the username matches the PostgreSQL user you created (gcpuser):
65+
66+
You should see output similar to:
67+
```output
68+
default: &default
69+
adapter: postgresql
70+
encoding: unicode
71+
username: gcpuser
72+
password:
73+
host: localhost
74+
pool: 5
75+
76+
development:
77+
<<: *default
78+
```
79+
### Create and Initialize the Database
80+
Initializes and creates the development and test databases for your Rails app using PostgreSQL.
81+
82+
```console
83+
rails db:create
84+
```
85+
You should see output similar to:
86+
```output
87+
Created database 'db_test_rubyapp_development'
88+
Created database 'db_test_rubyapp_test'
89+
```
90+
This means Rails successfully connected to PostgreSQL and created both dev and test databases.
91+
92+
### Generate a Scaffold for Testing
93+
A database and Scaffold are required to create the actual PostgreSQL database for your Rails app and quickly generate the model, controller, views, and migrations for your data.
94+
Let’s create a small test model and table — for example, a simple Task tracker:
95+
96+
```console
97+
rails generate scaffold task title:string due_date:date
98+
```
99+
This command automatically generates:
100+
- Database migration for the tasks table
101+
- A model (task.rb)
102+
- A controller and views for CRUD operations
103+
- **Scaffold** → Automatically generates boilerplate code for CRUD operations, saving time and ensuring your app has working forms and routes.
104+
105+
Then apply the migration:
106+
107+
```console
108+
rails db:migrate
109+
```
110+
111+
You should see output similar to:
112+
```output
113+
== 20251006101717 CreateTasks: migrating ======================================
114+
-- create_table(:tasks)
115+
-> 0.0127s
116+
== 20251006101717 CreateTasks: migrated (0.0128s) =============================
117+
```
118+
119+
Database schema successfully updated.
120+
121+
### Verify Table and Database Connectivity
122+
The previous command `rails generate scaffold task title:string due_date:date` created a `tasks` table in your PostgreSQL database.
123+
124+
Now, verify that the table exists and has the correct structure following the steps below:
125+
126+
```console
127+
sudo -u postgres psql
128+
\c db_test_rubyapp_development
129+
\d tasks
130+
```
131+
- `sudo -u postgres psql` → Launches the PostgreSQL shell as the superuser `postgres`.
132+
- `\c db_test_rubyapp_development` → Connects to the Rails app’s development database.
133+
- `\d tasks` → Displays the schema (columns and types) of the `tasks` table.
134+
135+
You should see output similar to:
136+
```output
137+
psql (15.10)
138+
Type "help" for help.
139+
140+
postgres=# \c db_test_rubyapp_development
141+
You are now connected to database "db_test_rubyapp_development" as user "postgres".
142+
db_test_rubyapp_development=# \d tasks
143+
Table "public.tasks"
144+
Column | Type | Collation | Nullable | Default
145+
------------+--------------------------------+-----------+----------+-----------------------------------
146+
id | bigint | | not null | nextval('tasks_id_seq'::regclass)
147+
title | character varying | | |
148+
due_date | date | | |
149+
created_at | timestamp(6) without time zone | | not null |
150+
updated_at | timestamp(6) without time zone | | not null |
151+
Indexes:
152+
"tasks_pkey" PRIMARY KEY, btree (id)
153+
```
154+
155+
### Run Rails Server
156+
Before proceeding to run the Rails server, you need to allow port 3000 from your GCP console. Below are the steps to do that:
157+
158+
a. On the GCP console, navigate to **Firewall** -> **Create Firewall Rule**
159+
160+
![Firewall Info alt-text#center](images/firewall1.png "Figure 1: Firewall Create")
161+
162+
b. Fill in the details as below:
163+
164+
Give a **name** for your desired port (e.g., `allow-3000-ingress`).
165+
166+
![Allow Ingress alt-text#center](images/firewall2.png "Figure 2: Allow-3000-ingress ")
167+
168+
169+
Set **Direction of Traffic** to **"Ingress"**.
170+
171+
Set **Target** to **"All Instances in the Network"**. You can also choose **"Specific Tags"**.
172+
173+
Set the **Source IPv4 range** to **"0.0.0.0/0"**, for global access.
174+
175+
![Set Direction of Traffic alt-text#center](images/firewall3.png "Figure 3: Target Set")
176+
177+
In the **"Protocols and Ports"**, click on **"TCP"**, and mention the port number **"3000"**.
178+
179+
![Set Protocols and Ports alt-text#center](images/firewall4.png "Figure 4: Protocols and Ports")
180+
181+
182+
Click on **"Create"**. The Firewall rule will be created successfully and can be viewed in the Firewall Policies Page:
183+
184+
![ Create Firewall rule alt-text#center](images/firewall5.png "Figure 5: Create Firewall rule")
185+
186+
Once done, go back to the VM, and execute the below commands to allow port 3000:
187+
188+
```console
189+
sudo firewall-cmd --permanent --add-port=3000/tcp
190+
sudo firewall-cmd --reload
191+
```
192+
Now that port 3000 is allowed in your VM’s ingress firewall rules, you can start the Rails server using the following command:
193+
194+
```console
195+
rails server -b 0.0.0.0
196+
```
197+
- `rails server -b 0.0.0.0` → Starts the Rails server and binds it to all network interfaces, not just `localhost`.
198+
- Binding to `0.0.0.0` allows other machines (or your local browser) to access the Rails app running on the VM using its external IP.
199+
200+
201+
### Access the Application:
202+
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
203+
204+
```console
205+
http://[YOUR_VM_EXTERNAL_IP]:3000
206+
```
207+
- Replace `<YOUR_VM_PUBLIC_IP>` with the public IP of your GCP VM.
208+
209+
You will see a Rails welcome page in your browser if everything is set up correctly. It looks like this:
210+
211+
![Rails-info page alt-text#center](images/rails-web.png "Figure 6: Ruby/Rails Welcome Page")
212+
213+
This verifies the basic functionality of the Ruby/Rails installation before proceeding to the benchmarking.

0 commit comments

Comments
 (0)