Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Deploy Ruby on Rails on Google Cloud C4A (Arm-based Axion VMs)

draft: true
cascade:
draft: true

minutes_to_complete: 40

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.

learning_objectives:
- Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors)
- Install Ruby/Rails on a SUSE Arm64 (C4A) instance
- Validate Ruby on Rails functionality using PostgreSQL as the database
- Benchmark Rails performance using the built-in Ruby Benchmark library on Arm64 (Aarch64) architecture


prerequisites:
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
- Basic familiarity with Ruby programming, the Rails framework, and [relational databases](https://www.postgresql.org/)

author: Pareena Verma

##### Tags
skilllevels: Introductory
subjects: Web
cloud_service_providers: Google Cloud

armips:
- Neoverse

tools_software_languages:
- Ruby
- Rails
- PostgreSQL

operatingsystems:
- Linux

# ================================================================================
# FIXED, DO NOT MODIFY
# ================================================================================
further_reading:
- resource:
title: Google Cloud documentation
link: https://cloud.google.com/docs
type: documentation

- resource:
title: Ruby on Rails documentation
link: https://guides.rubyonrails.org/
type: documentation

- resource:
title: Ruby built-in Benchmark documentation
link: https://github.com/ruby/benchmark?tab=readme-ov-file#benchmark
type: documentation

weight: 1
layout: "learningpathall"
learning_path_main_page: "yes"
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# ================================================================================
# FIXED, DO NOT MODIFY THIS FILE
# ================================================================================
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
title: "Next Steps" # Always the same, html page title.
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Getting started with Ruby/Rails on Google Axion C4A (Arm Neoverse-V2)

weight: 2

layout: "learningpathall"
---

## Google Axion C4A Arm instances in Google Cloud

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.

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.

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.

## Ruby on Rails

Ruby on Rails (Rails) is an open-source, server-side web application framework written in Ruby.

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.

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/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
title: Ruby on Rails Baseline Testing on Google Axion C4A Arm Virtual Machine
weight: 5

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Baseline Setup for Ruby on Rails with PostgreSQL
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.

### Install and Configure PostgreSQL
PostgreSQL is used with Ruby on Rails as a robust, production-ready relational database that reliably stores and manages application data.

```console
sudo zypper install postgresql-devel postgresql-server
sudo systemctl start postgresql
sudo systemctl enable postgresql
```
- `postgresql-devel` is required to compile the pg gem for Rails.

Verify that the PostgreSQL service is active and running:

```console
systemctl status postgresql
```

This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**.

```console
sudo -u postgres createuser --superuser gcpuser
```
- `sudo -u postgres` → Runs the command as the `postgres` user (default PostgreSQL superuser).
- `createuser --superuser gcpuser` → Creates a PostgreSQL role named `gcpuser` with full admin privileges.
- Can create databases
- Can create other roles/users
- Can grant privileges

This role will be used by Rails to connect to the PostgreSQL database.

### Create a Rails App with PostgreSQL
Creates a new Rails application configured to use PostgreSQL as its database.

```console
rails new db_test_rubyapp -d postgresql
cd db_test_rubyapp
bundle install
```
- Creates a new Rails application called `db_test_app`.
- `d postgresql` → Tells Rails to use PostgreSQL as the database instead of the default SQLite.
- `bundle install` ensures all required gems are installed.

{{% notice Note %}}
Check `config/database.yml` to ensure the `username` and `password` match your PostgreSQL role `(gcpuser)`.
{{% /notice %}}

### Verify and Update Database Configuration
Open the Rails database configuration file:

```console
nano config/database.yml
```
Find the `default`: and `development`: sections.
Ensure the username matches the PostgreSQL user you created (gcpuser):

You should see output similar to:
```output
default: &default
adapter: postgresql
encoding: unicode
username: gcpuser
password:
host: localhost
pool: 5

development:
<<: *default
```
### Create and Initialize the Database
Initializes and creates the development and test databases for your Rails app using PostgreSQL.

```console
rails db:create
```
You should see output similar to:
```output
Created database 'db_test_rubyapp_development'
Created database 'db_test_rubyapp_test'
```
This means Rails successfully connected to PostgreSQL and created both dev and test databases.

### Generate a Scaffold for Testing
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.
Let’s create a small test model and table — for example, a simple Task tracker:

```console
rails generate scaffold task title:string due_date:date
```
This command automatically generates:
- Database migration for the tasks table
- A model (task.rb)
- A controller and views for CRUD operations
- **Scaffold** → Automatically generates boilerplate code for CRUD operations, saving time and ensuring your app has working forms and routes.

Then apply the migration:

```console
rails db:migrate
```

You should see output similar to:
```output
== 20251006101717 CreateTasks: migrating ======================================
-- create_table(:tasks)
-> 0.0127s
== 20251006101717 CreateTasks: migrated (0.0128s) =============================
```

Database schema successfully updated.

### Verify Table and Database Connectivity
The previous command `rails generate scaffold task title:string due_date:date` created a `tasks` table in your PostgreSQL database.

Now, verify that the table exists and has the correct structure following the steps below:

```console
sudo -u postgres psql
\c db_test_rubyapp_development
\d tasks
```
- `sudo -u postgres psql` → Launches the PostgreSQL shell as the superuser `postgres`.
- `\c db_test_rubyapp_development` → Connects to the Rails app’s development database.
- `\d tasks` → Displays the schema (columns and types) of the `tasks` table.

You should see output similar to:
```output
psql (15.10)
Type "help" for help.

postgres=# \c db_test_rubyapp_development
You are now connected to database "db_test_rubyapp_development" as user "postgres".
db_test_rubyapp_development=# \d tasks
Table "public.tasks"
Column | Type | Collation | Nullable | Default
------------+--------------------------------+-----------+----------+-----------------------------------
id | bigint | | not null | nextval('tasks_id_seq'::regclass)
title | character varying | | |
due_date | date | | |
created_at | timestamp(6) without time zone | | not null |
updated_at | timestamp(6) without time zone | | not null |
Indexes:
"tasks_pkey" PRIMARY KEY, btree (id)
```

### Run Rails Server
Before proceeding to run the Rails server, you need to allow port 3000 from your GCP console. Below are the steps to do that:

a. On the GCP console, navigate to **Firewall** -> **Create Firewall Rule**

![Firewall Info alt-text#center](images/firewall1.png "Figure 1: Firewall Create")

b. Fill in the details as below:

Give a **name** for your desired port (e.g., `allow-3000-ingress`).

![Allow Ingress alt-text#center](images/firewall2.png "Figure 2: Allow-3000-ingress ")


Set **Direction of Traffic** to **"Ingress"**.

Set **Target** to **"All Instances in the Network"**. You can also choose **"Specific Tags"**.

Set the **Source IPv4 range** to **"0.0.0.0/0"**, for global access.

![Set Direction of Traffic alt-text#center](images/firewall3.png "Figure 3: Target Set")

In the **"Protocols and Ports"**, click on **"TCP"**, and mention the port number **"3000"**.

![Set Protocols and Ports alt-text#center](images/firewall4.png "Figure 4: Protocols and Ports")


Click on **"Create"**. The Firewall rule will be created successfully and can be viewed in the Firewall Policies Page:

![ Create Firewall rule alt-text#center](images/firewall5.png "Figure 5: Create Firewall rule")

Once done, go back to the VM, and execute the below commands to allow port 3000:

```console
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
```
Now that port 3000 is allowed in your VM’s ingress firewall rules, you can start the Rails server using the following command:

```console
rails server -b 0.0.0.0
```
- `rails server -b 0.0.0.0` → Starts the Rails server and binds it to all network interfaces, not just `localhost`.
- 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.


### Access the Application:
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:

```console
http://[YOUR_VM_EXTERNAL_IP]:3000
```
- Replace `<YOUR_VM_PUBLIC_IP>` with the public IP of your GCP VM.

You will see a Rails welcome page in your browser if everything is set up correctly. It looks like this:

![Rails-info page alt-text#center](images/rails-web.png "Figure 6: Ruby/Rails Welcome Page")

This verifies the basic functionality of the Ruby/Rails installation before proceeding to the benchmarking.
Loading