Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails guide upgrade (part 2) #22114

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Finalized GitHub Actions guide for Rails
  • Loading branch information
igor-alexandrov committed Feb 27, 2025
commit bd3cc30956050e48ff2fdbe4f5a88879a8812fd8
78 changes: 38 additions & 40 deletions content/guides/ruby/configure-github-actions.md
Original file line number Diff line number Diff line change
@@ -27,75 +27,73 @@

## Overview

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.

Check warning on line 30 in content/guides/ruby/configure-github-actions.md

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.Acronyms] 'CD' has no definition. Raw Output: {"message": "[Docker.Acronyms] 'CD' has no definition.", "location": {"path": "content/guides/ruby/configure-github-actions.md", "range": {"start": {"line": 30, "column": 24}}}, "severity": "WARNING"}

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:

1. Define the GitHub Actions workflow.
2. Run the workflow.

## 1. Set up the workflow
## 1. Define the GitHub Actions workflow

Set up your GitHub Actions workflow for building, testing, and pushing the image
to Docker Hub.
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.

If you prefer to use the GitHub web interface, follow these steps:

1. Go to your repository on GitHub and then select the **Actions** tab.

2. Select **set up a workflow yourself**.

This takes you to a page for creating a new GitHub actions workflow file in

Check failure on line 47 in content/guides/ruby/configure-github-actions.md

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'GitHub( Actions)?' instead of 'GitHub actions'. Raw Output: {"message": "[Vale.Terms] Use 'GitHub( Actions)?' instead of 'GitHub actions'.", "location": {"path": "content/guides/ruby/configure-github-actions.md", "range": {"start": {"line": 47, "column": 48}}}, "severity": "ERROR"}
your repository, under `.github/workflows/main.yml` by default.
your repository. By default, the file is created under `.github/workflows/main.yml`, let's change it name to `build.yml`.

3. In the editor window, copy and paste the following YAML configuration.
If you prefer to use your text editor, create a new file named `build.yml` in the `.github/workflows/` directory of your repository.

```yaml
name: ci
Add the following content to the file:

on:
push:
branches:
- main
```yaml
name: Build and push Docker image

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
on:
push:
branches:
- main

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
```
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

For more information about the YAML syntax for `docker/build-push-action`,
refer to the [GitHub Action README](https://github.com/docker/build-push-action/blob/master/README.md).
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest
```

## 2. Run the workflow
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:

Check warning on line 82 in content/guides/ruby/configure-github-actions.md

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.RecommendedWords] Consider using 'previous' instead of 'above' Raw Output: {"message": "[Docker.RecommendedWords] Consider using 'previous' instead of 'above'", "location": {"path": "content/guides/ruby/configure-github-actions.md", "range": {"start": {"line": 82, "column": 222}}}, "severity": "INFO"}

Save the workflow file and run the job.
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.

Check warning on line 84 in content/guides/ruby/configure-github-actions.md

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.RecommendedWords] Consider using 'sign in' instead of 'Login' Raw Output: {"message": "[Docker.RecommendedWords] Consider using 'sign in' instead of 'Login'", "location": {"path": "content/guides/ruby/configure-github-actions.md", "range": {"start": {"line": 84, "column": 7}}}, "severity": "INFO"}

1. Select **Commit changes...** and push the changes to the `main` branch.
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.

After pushing the commit, the workflow starts automatically.
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.

2. Go to the **Actions** tab. It displays the workflow.
## 2. Run the workflow

Selecting the workflow shows you the breakdown of all the steps.
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).

Check warning on line 92 in content/guides/ruby/configure-github-actions.md

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Docker.RecommendedWords] Consider using 'previous' instead of 'above' Raw Output: {"message": "[Docker.RecommendedWords] Consider using 'previous' instead of 'above'", "location": {"path": "content/guides/ruby/configure-github-actions.md", "range": {"start": {"line": 92, "column": 75}}}, "severity": "INFO"}

3. When the workflow is complete, go to your
[repositories on Docker Hub](https://hub.docker.com/repositories).
Go to the **Actions** tab of you GitHub repository. It displays the workflow. Selecting the workflow shows you the breakdown of all the steps.

If you see the new repository in that list, it means the GitHub Actions
successfully pushed the image to Docker Hub.
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.

## Summary