Requirements
- Ruby 3.2+ installed locally
- Bundler for dependency management
- Account on Vertra Cloud
Project Structure
my-app-ruby/
├── app.rb
├── Gemfile
├── Gemfile.lock
└── vertracloud.config
Configuration
Gemfile
source 'https://rubygems.org'
ruby '3.3.0'
gem 'sinatra', '~> 3.0'
gem 'rack', '~> 2.2'
gem 'pry', '~> 0.14'
gem 'pg', '~> 1.5' # For PostgreSQL
gem 'json', '~> 2.6'
group :development do
gem 'rerun', '~> 1.14'
end
The platform automatically runs bundle install. Do not include the vendor folder in the upload.
vertracloud.config
MAIN=app.rb
START=bundle exec ruby app.rb -p $PORT -o 0.0.0.0
VERSION=recommended
Example: Sinatra Application
app.rb
require 'sinatra'
require 'json'
require 'pg'
set :bind, '0.0.0.0'
set :port, ENV['PORT'] || 80
# Database configuration
def get_db_connection
begin
PG.connect(
host: ENV['DB_HOST'] || 'localhost',
dbname: ENV['DB_NAME'] || 'postgres',
user: ENV['DB_USER'] || 'postgres',
password: ENV['DB_PASSWORD'] || '',
port: ENV['DB_PORT'] || 5432
)
rescue PG::Error => e
puts "Database connection error: #{e.message}"
nil
end
end
before do
content_type :json
end
# Root route
get '/' do
{
message: 'Ruby Sinatra API on Vertra Cloud',
version: '1.0.0'
}.to_json
end
# Health check
get '/health' do
{
status: 'healthy',
service: 'ruby-api',
uptime: Time.now.to_i
}.to_json
end
# List items
get '/api/items' do
conn = get_db_connection
return { error: 'Database connection failed' }.to_json if conn.nil?
begin
result = conn.exec('SELECT id, name, description FROM items LIMIT 20')
items = result.map do |row|
{
id: row['id'].to_i,
name: row['name'],
description: row['description']
}
end
items.to_json
rescue PG::Error => e
{ error: e.message }.to_json
ensure
conn.close if conn
end
end
# Error handling
error do
status 500
{ error: 'Internal server error' }.to_json
end
not_found do
status 404
{ error: 'Not found' }.to_json
end
puts "Server starting on #{settings.bind}:#{settings.port}"
Deploy
Via Dashboard
Via GitHub
Via VSCode
- Execute
bundle install locally
- Exclude
vendor and .bundle folders from the project
- Compress into a ZIP file
- Access Dashboard → New Project → Application
- Select Ruby language and upload
- Configure memory (256MB for simple applications, 512MB+ for larger applications)
- Click “Create Application”
- Push the project to GitHub (with
Gemfile and Gemfile.lock at root)
- Access Dashboard → New Project → Application
- Select “GitHub” as source
- Choose the repository and configure resources
- Click “Create Application”
- Open the project in VSCode with Vertra Cloud extension installed
- Press
Ctrl+Shift+P and type “Vertra: Deploy”
- Select or create the target application
- Configure memory and environment variables
- Wait for automatic upload and deployment
Available Versions
| Version | Status | Description |
|---|
| 3.4 | Latest | Ruby 3.4 (latest version) |
| 3.3 | Recommended | Ruby 3.3 LTS (recommended for production) |
| 3.2 | Stable | Ruby 3.2 with extended support |
Notes
- Dependencies: Use Bundler to manage gems
- Environment variables: Access via
ENV['KEY']
- Database: Configure credentials as environment variables
- Logs: Use
puts or STDOUT.puts for logs that appear in dashboard
- GIL: Ruby uses the Global Interpreter Lock, consider multiple processes for I/O intensive work
- Listen on
0.0.0.0 on port $PORT