Ruby on Rails on Section
Learn how to run a Ruby on Rails app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.
What You'll Build
Visit https://dry-dew-3573.section.app to see what you'll be building.
Step by Step
Following are step-by-step instructions to deploy a Ruby on Rails application to the edge on Section. We'll Dockerize it, and deploy it on Section.
- You need Docker installed so that you can build a docker image, and Ruby, Rails, and SQLite installed for testing locally.
Create the Ruby on Rails App
Create a new directory for your app.
Initialize the Ruby on Rails application with the following commands:
rails new hello_world
Run the Ruby on Rails application locally with the following command:
# On Windows
ruby bin/rails server
# On Linux/Mac
Now navigate to
http://localhost:3000 in your browser to see the Ruby on Rails app running.
After deploying on Section and using your own domain name(s) you will need to edit the
config.hosts setting in
my_rubyonrails_app/hello_world/config/environments/development.rb to be your domain name(s). For example, if your domain name is
example.com (or including subdomains such as
www.example.com), you would change it to the following line:
# Allow hosts
config.hosts << /[a-z0-9-.]+\.example\.com/
Let's build the container image that we'll deploy to Section. First make a
Dockerfile in your
hello_world directory with the following content.
# Use the latest Ruby image from Docker Hub (https://hub.docker.com/_/ruby)
COPY . /hello_world
# Run bundle install to install the Ruby dependencies.
RUN bundle install
# Install Yarn.
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn
RUN yarn install --check-files
# Export port 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
Build and tag it.
docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/my-rubyonrails-app:prod
Launch it locally to test it.
docker run -p 3000:3000 ghcr.io/YOUR_GITHUB_USERNAME/my-rubyonrails-app:prod
Push it to GitHub Packages. This makes it available to Section.
docker push ghcr.io/YOUR_GITHUB_USERNAME/my-rubyonrails-app:prod
Be sure to make it public. To see your packages and make this change, visit
Next, use the Create Project command in the Section Console in order to deploy your new container. Use the image name
ghcr.io/YOUR_GITHUB_USERNAME/my-rubyonrails-app:prod with port 3000.
See the pods running on Section's network with either the Kubernetes dashboard or
kubectl get pods -o wide. The
-o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.
kubectl logs POD to see the log message reporting that the server is listening on port 3000:
=> Booting Puma
=> Rails 7.0.4 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.1.3-p185) ("Birdie's Version")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 1
* Listening on http://0.0.0.0:3000
Finally, follow the instructions that configure DNS and TLS.
See What You've Built
See the sample app you've built by visiting the
YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.