Skip to content

Commit c3431b0

Browse files
Rails guide upgrade (part 2) (#22114)
## Description This PR has two goals. First of all it continues work that has been done in #21559. Besides this, and this is more significant, I tried to improve the structure of the documentation that is currently used for different language-specific guides like [PHP](https://docs.docker.com/guides/php/configure-ci-cd/), [Go](https://docs.docker.com/guides/golang/), [Python](https://docs.docker.com/guides/python/) and others, including, of course, Ruby itself. Each of these guides currently has a [Configure CI/CD](https://docs.docker.com/guides/python/configure-ci-cd/) section. Inside this section there is a GitHub Actions workflow example that has nothing in common with a CI/CD pipeline. It's just an example of how to build and push an image to a Docker Hub registry. We should be clear in our documentation and not mislead our users. This was the main reason why I renamed this section to "Automate your builds with GitHub Actions". I also updated the content of this section to reflect the new name and to make it more clear what the user can expect from this guide. I suggest the same be done for all other language-specific guides. Besides this, I changed the order of the sections in the Ruby guide. The "Develop your app" section has been moved down to the bottom of the guide. This makes more sense to me because of two reasons: 1. It is more important to start using Docker Hub right after you added the Dockerfile to your project (section number one in all language-specific guides). 2. I can hardly imagine anybody using Docker to run the app locally for development purposes (at least for Ruby). What is really essential and useful is to know how to run services, that are required by your app, like a database, a cache server, or a local LLM. This is why the "Develop your app" section should be rewritten to explain how to run the infrastructure services that are required by the app and not the app itself. Below there are screenshots reflecting the changes that have been made in this PR. **Before** <img width="1512" alt="Screenshot 2025-02-27 at 11 26 39" src="https://github.com/user-attachments/assets/1ca06aea-ffeb-4efb-a14d-27254d2a2110" /> **After** <img width="1512" alt="Screenshot 2025-02-27 at 11 26 01" src="https://github.com/user-attachments/assets/7abbe8b7-d1b3-480f-8105-49f967b51e47" /> ## Related issues or tickets #21559 ## Reviews - [x] Technical review - [x] Editorial review - [ ] Product review
1 parent 8c559aa commit c3431b0

File tree

6 files changed

+121
-142
lines changed

6 files changed

+121
-142
lines changed

content/guides/ruby/_index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ aliases:
1212
- /language/ruby/
1313
- /guides/language/ruby/
1414
languages: [ruby]
15+
tags: [frameworks]
1516
params:
1617
time: 20 minutes
1718
---
1819

1920
The Ruby language-specific guide teaches you how to containerize a Ruby on Rails application using Docker. In this guide, you’ll learn how to:
2021

2122
- Containerize and run a Ruby on Rails application
23+
- Configure a GitHub Actions workflow to build and push a Docker image to Docker Hub
2224
- Set up a local environment to develop a Ruby on Rails application using containers
23-
- Configure a CI/CD pipeline for a containerized Ruby on Rails application using GitHub Actions
2425
- Deploy your containerized Ruby on Rails application locally to Kubernetes to test and debug your deployment
2526

2627
Start by containerizing an existing Ruby on Rails application.

content/guides/ruby/configure-ci-cd.md

Lines changed: 0 additions & 132 deletions
This file was deleted.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: Automate your builds with GitHub Actions
3+
linkTitle: Automate your builds with GitHub Actions
4+
weight: 20
5+
keywords: ci/cd, github actions, ruby, flask
6+
description: Learn how to configure CI/CD using GitHub Actions for your Ruby on Rails application.
7+
aliases:
8+
- /language/ruby/configure-ci-cd/
9+
- /guides/language/ruby/configure-ci-cd/
10+
- /guides/ruby/configure-ci-cd/
11+
---
12+
13+
## Prerequisites
14+
15+
Complete all the previous sections of this guide, starting with [Containerize a Ruby on Rails application](containerize.md). You must have a [GitHub](https://github.com/signup) account and a [Docker](https://hub.docker.com/signup) account to complete this section.
16+
17+
If you didn't create a [GitHub repository](https://github.com/new) for your project yet, it is time to do it. After creating the repository, don't forget to [add a remote](https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories) and ensure you can commit and [push your code](https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository#about-git-push) to GitHub.
18+
19+
1. In your project's GitHub repository, open **Settings**, and go to **Secrets and variables** > **Actions**.
20+
21+
2. Under the **Variables** tab, create a new **Repository variable** named `DOCKER_USERNAME` and your Docker ID as a value.
22+
23+
3. Create a new [Personal Access Token (PAT)](/manuals/security/for-developers/access-tokens.md#create-an-access-token) for Docker Hub. You can name this token `docker-tutorial`. Make sure access permissions include Read and Write.
24+
25+
4. Add the PAT as a **Repository secret** in your GitHub repository, with the name
26+
`DOCKERHUB_TOKEN`.
27+
28+
## Overview
29+
30+
GitHub Actions is a CI/CD (Continuous Integration and Continuous Deployment) automation tool built into GitHub. It allows you to define custom workflows for building, testing, and deploying your code when specific events occur (e.g., pushing code, creating a pull request, etc.). A workflow is a YAML-based automation script that defines a sequence of steps to be executed when triggered. Workflows are stored in the `.github/workflows/` directory of a repository.
31+
32+
In this section, you'll learn how to set up and use GitHub Actions to build your Docker image as well as push it to Docker Hub. You will complete the following steps:
33+
34+
1. Define the GitHub Actions workflow.
35+
2. Run the workflow.
36+
37+
## 1. Define the GitHub Actions workflow
38+
39+
You can create a GitHub Actions workflow by creating a YAML file in the `.github/workflows/` directory of your repository. To do this use your favorite text editor or the GitHub web interface. The following steps show you how to create a workflow file using the GitHub web interface.
40+
41+
If you prefer to use the GitHub web interface, follow these steps:
42+
43+
1. Go to your repository on GitHub and then select the **Actions** tab.
44+
45+
2. Select **set up a workflow yourself**.
46+
47+
This takes you to a page for creating a new GitHub Actions workflow file in
48+
your repository. By default, the file is created under `.github/workflows/main.yml`, let's change it name to `build.yml`.
49+
50+
If you prefer to use your text editor, create a new file named `build.yml` in the `.github/workflows/` directory of your repository.
51+
52+
Add the following content to the file:
53+
54+
```yaml
55+
name: Build and push Docker image
56+
57+
on:
58+
push:
59+
branches:
60+
- main
61+
62+
jobs:
63+
build_and_push:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Login to Docker Hub
67+
uses: docker/login-action@v3
68+
with:
69+
username: ${{ vars.DOCKER_USERNAME }}
70+
password: ${{ secrets.DOCKERHUB_TOKEN }}
71+
72+
- name: Set up Docker Buildx
73+
uses: docker/setup-buildx-action@v3
74+
75+
- name: Build and push
76+
uses: docker/build-push-action@v6
77+
with:
78+
push: true
79+
tags: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
80+
```
81+
82+
Each GitHub Actions workflow includes one or several jobs. Each job consists of steps. Each step can either run a set of commands or use already [existing actions](https://github.com/marketplace?type=actions). The action above has three steps:
83+
84+
1. [**Login to Docker Hub**](https://github.com/docker/login-action): Action logs in to Docker Hub using the Docker ID and Personal Access Token (PAT) you created earlier.
85+
86+
2. [**Set up Docker Buildx**](https://github.com/docker/setup-buildx-action): Action sets up Docker [Buildx](https://github.com/docker/buildx), a CLI plugin that extends the capabilities of the Docker CLI.
87+
88+
3. [**Build and push**](https://github.com/docker/build-push-action): Action builds and pushes the Docker image to Docker Hub. The `tags` parameter specifies the image name and tag. The `latest` tag is used in this example.
89+
90+
## 2. Run the workflow
91+
92+
Let's commit the changes, push them to the `main` branch. In the workflow above, the trigger is set to `push` events on the `main` branch. This means that the workflow will run every time you push changes to the `main` branch. You can find more information about the workflow triggers [here](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows).
93+
94+
Go to the **Actions** tab of you GitHub repository. It displays the workflow. Selecting the workflow shows you the breakdown of all the steps.
95+
96+
When the workflow is complete, go to your [repositories on Docker Hub](https://hub.docker.com/repositories). If you see the new repository in that list, it means the GitHub Actions workflow successfully pushed the image to Docker Hub.
97+
98+
## Summary
99+
100+
In this section, you learned how to set up a GitHub Actions workflow for your Ruby on Rails application.
101+
102+
Related information:
103+
104+
- [Introduction to GitHub Actions](/guides/gha.md)
105+
- [Docker Build GitHub Actions](/manuals/build/ci/github-actions/_index.md)
106+
- [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
107+
108+
## Next steps
109+
110+
In the next section, you'll learn how you can develop your application using containers.
111+

content/guides/ruby/containerize.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Starting from Rails 7.1 [Docker is supported out of the box](https://guides.ruby
2424

2525
If you have an existing Rails application, you will need to create the Docker assets manually. Unfortunately `docker init` command does not yet support Rails. This means that if you are working with Rails, you'll need to copy Dockerfile and other related configurations manually from the examples below.
2626

27-
## Initialize Docker assets
27+
## 1. Initialize Docker assets
2828

2929
Rails 7.1 generates multistage Dockerfile out of the box, below is an example of such file generated from a Rails template.
3030

@@ -232,7 +232,7 @@ To learn more about the files, see the following:
232232
- [compose.yaml](/reference/compose-file/_index.md)
233233
- [docker-entrypoint](/reference/dockerfile/#entrypoint)
234234

235-
## Run the application
235+
## 2. Run the application
236236

237237
To run the application, run the following command in a terminal inside the application's directory.
238238

@@ -244,7 +244,7 @@ Open a browser and view the application at [http://localhost:3000](http://localh
244244

245245
In the terminal, press `ctrl`+`c` to stop the application.
246246

247-
### Run the application in the background
247+
## 3. Run the application in the background
248248

249249
You can run the application detached from the terminal by adding the `-d`
250250
option. Inside the `docker-ruby-on-rails` directory, run the following command
@@ -278,5 +278,4 @@ Related information:
278278

279279
## Next steps
280280

281-
In the next section, you'll learn how you can develop your application using
282-
containers.
281+
In the next section, you'll take a look at how to set up a CI/CD pipeline using GitHub Actions.

content/guides/ruby/deploy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ In your `docker-ruby-on-rails` directory, create a file named
2424
`docker-ruby-on-rails-kubernetes.yaml`. Open the file in an IDE or text editor and add
2525
the following contents. Replace `DOCKER_USERNAME/REPO_NAME` with your Docker
2626
username and the name of the repository that you created in [Configure CI/CD for
27-
your Ruby on Rails application](configure-ci-cd.md).
27+
your Ruby on Rails application](configure-github-actions.md).
2828

2929
```yaml
3030
apiVersion: apps/v1
@@ -68,7 +68,7 @@ In this Kubernetes YAML file, there are two objects, separated by the `---`:
6868
you'll get just one replica, or copy of your pod. That pod, which is
6969
described under `template`, has just one container in it. The
7070
container is created from the image built by GitHub Actions in [Configure CI/CD for
71-
your Ruby on Rails application](configure-ci-cd.md).
71+
your Ruby on Rails application](configure-github-actions.md).
7272
- A NodePort service, which will route traffic from port 30001 on your host to
7373
port 8001 inside the pods it routes to, allowing you to reach your app
7474
from the network.

content/guides/ruby/develop.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Use containers for Ruby on Rails development
33
linkTitle: Develop your app
4-
weight: 20
4+
weight: 40
55
keywords: ruby, local, development
66
description: Learn how to develop your Ruby on Rails application locally.
77
aliases:
@@ -200,4 +200,4 @@ Related information:
200200

201201
## Next steps
202202

203-
In the next section, you'll take a look at how to set up a CI/CD pipeline using GitHub Actions.
203+
In the next section, you'll learn how you can locally test and debug your workloads on Kubernetes before deploying.

0 commit comments

Comments
 (0)