Skip to content

Commit bd3cc30

Browse files
Finalized GitHub Actions guide for Rails
1 parent 54dc285 commit bd3cc30

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

content/guides/ruby/configure-github-actions.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,68 +34,66 @@ In this section, you'll learn how to set up and use GitHub Actions to build your
3434
1. Define the GitHub Actions workflow.
3535
2. Run the workflow.
3636

37-
## 1. Set up the workflow
37+
## 1. Define the GitHub Actions workflow
3838

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

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

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

4647
This takes you to a page for creating a new GitHub actions workflow file in
47-
your repository, under `.github/workflows/main.yml` by default.
48+
your repository. By default, the file is created under `.github/workflows/main.yml`, let's change it name to `build.yml`.
4849

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

51-
```yaml
52-
name: ci
52+
Add the following content to the file:
5353

54-
on:
55-
push:
56-
branches:
57-
- main
54+
```yaml
55+
name: Build and push Docker image
5856

59-
jobs:
60-
build:
61-
runs-on: ubuntu-latest
62-
steps:
63-
- name: Login to Docker Hub
64-
uses: docker/login-action@v3
65-
with:
66-
username: ${{ vars.DOCKER_USERNAME }}
67-
password: ${{ secrets.DOCKERHUB_TOKEN }}
57+
on:
58+
push:
59+
branches:
60+
- main
6861

69-
- name: Set up Docker Buildx
70-
uses: docker/setup-buildx-action@v3
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 }}
7171

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

79-
For more information about the YAML syntax for `docker/build-push-action`,
80-
refer to the [GitHub Action README](https://github.com/docker/build-push-action/blob/master/README.md).
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+
```
8181
82-
## 2. Run the workflow
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:
8383
84-
Save the workflow file and run the job.
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.
8585
86-
1. Select **Commit changes...** and push the changes to the `main` branch.
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.
8787
88-
After pushing the commit, the workflow starts automatically.
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.
8989

90-
2. Go to the **Actions** tab. It displays the workflow.
90+
## 2. Run the workflow
9191

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

94-
3. When the workflow is complete, go to your
95-
[repositories on Docker Hub](https://hub.docker.com/repositories).
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.
9695

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

10098
## Summary
10199

0 commit comments

Comments
 (0)