Ruby on Rails
This guide explains how to create and deploy a Ruby on Rails app. To run this example, follow these steps:
-
Install the
kraftCLI tool and a container runtime engine, for example Docker. -
Clone the
examplesrepository andcdinto theexamples/ruby3.2-rails/directory:
Code(bash)
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
This guide uses fra (Frankfurt, ๐ฉ๐ช):
Code(bash)
When done, invoke the following command to deploy this app on Unikraft Cloud:
Code(bash)
The output shows the instance address and other details:
Code(ansi)
In this case, the instance name is ruby32-rails-apa93 and the address is https://aged-waterfall-qraz0s7d.fra.unikraft.app.
They're different for each run.
Use curl to query the Unikraft Cloud instance of the Python-based HTTP web server:
Code(bash)
Code(text)
You can list information about the instance by running:
Code(bash)
Code(text)
When done, you can remove the instance:
Code(bash)
Customize your app
To customize the app, update the files in the repository, listed below:
app/andconfig/: the contents to update the Rails setupKraftfile: the Unikraft Cloud specificationDockerfile: the Docker-specified app filesystem
The app/ and config/ directories contain files that are to overwrite generated Rails files:
Code(bash)
Code(text)
These files add the configuration (controller, view, route) to print the Hello, World! message in Rails.
They overwrite the generated Rails configuration to provide the app setup.
Update these files, and other files, with required contents for your own app.
Lines in the Kraftfile have the following roles:
-
spec: v0.6: The currentKraftfilespecification version is0.6. -
runtime: ruby:3.2: The Unikraft runtime kernel to use is Ruby 3.2. -
rootfs: ./Dockerfile: Build the app root filesystem using theDockerfile. -
cmd: ["/usr/bin/ruby", "/app/bin/rails", "server", "-b", "0.0.0.0"]: Use/usr/bin/ruby /app/bin/rails server -b 0.0.0.0as the starting command of the instance.
Lines in the Dockerfile have the following roles:
-
The
RUNlines install Rails and generate the default app setup for ahelloapp. -
COPY . /app/: Copies the local files (fromapp/andconfig/) to the app, overwriting generated contents to provide the user-specified app. -
FROM scratch: Build the filesystem from thescratchcontainer image, to create a base image. -
COPY --from=build /app /app: Copy the app directory to the filesystem.
The following options are available for customizing the app:
-
If you only update the implementation in the
app/orconfig/directories, or adding new directories or files to overwrite Rails generated files, you don't need to make any other changes. -
If changing the app name, change the
helloname inRUN rails generate controller helloto a new one. The file names in theapp/andconfig/directories have to be similarly updated. -
More extensive changes may require extending the
Dockerfile(seeDockerfilesyntax reference).
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Code(bash)
Or visit the CLI Reference.