@@ -27,7 +27,7 @@ The following GitHub Actions are available:
2727 installs [ QEMU] ( https://github.com/qemu/qemu ) static binaries for multi-arch
2828 builds.
2929- [ Docker Buildx Bake] ( https://github.com/marketplace/actions/docker-buildx-bake ) :
30- enables using high-level builds with [ Bake] ( ../../bake/index .md ) .
30+ enables using high-level builds with [ Bake] ( ../../bake/_index .md ) .
3131- [ Docker Scout] ( https://github.com/docker/scout-action ) :
3232 analyze Docker images for security vulnerabilities.
3333
@@ -44,6 +44,166 @@ refer to the following sections:
4444## Get started with GitHub Actions
4545
4646{{< include "gha-tutorial.md" >}}
47+ This tutorial walks you through the process of setting up and using Docker GitHub
48+ Actions for building Docker images, and pushing images to Docker Hub. You will
49+ complete the following steps:
50+
51+ 1 . Create a new repository on GitHub.
52+ 2 . Define the GitHub Actions workflow.
53+ 3 . Run the workflow.
54+
55+ To follow this tutorial, you need a Docker ID and a GitHub account.
56+
57+ ### Step one: Create the repository
58+
59+ Create a GitHub repository and configure the Docker Hub credentials.
60+
61+ 1 . Create a new GitHub repository using
62+ [ this template repository] ( https://github.com/dvdksn/clockbox/generate ) .
63+
64+ The repository contains a simple Dockerfile, and nothing else. Feel free to
65+ use another repository containing a working Dockerfile if you prefer.
66+
67+ 2 . Open the repository ** Settings** , and go to ** Secrets and variables** > ** Actions** .
68+
69+ 3 . Create a new ** Repository variable** named ` DOCKERHUB_USERNAME ` and your Docker ID as value.
70+
71+ 4 . Create a new
72+ [ personal access token] ( /security/for-developers/access-tokens/#create-an-access-token )
73+ for Docker Hub. You can name this token ` clockboxci ` .
74+
75+ 5 . Add the Docker Hub access token as a ** Repository secret** in your GitHub repository, with the name
76+ ` DOCKERHUB_TOKEN ` .
77+
78+ With your repository created, and credentials configured, you're now ready for
79+ action.
80+
81+ ### Step two: Set up the workflow
82+
83+ Set up your GitHub Actions workflow for building and pushing the image to Docker
84+ Hub.
85+
86+ 1 . Go to your repository on GitHub and then select the ** Actions** tab.
87+ 2 . Select ** set up a workflow yourself** .
88+
89+ This takes you to a page for creating a new GitHub actions workflow file in
90+ your repository, under ` .github/workflows/main.yml ` by default.
91+
92+ 3 . In the editor window, copy and paste the following YAML configuration.
93+
94+ ``` yaml
95+ name : ci
96+
97+ on :
98+ push :
99+ branches :
100+ - " main"
101+
102+ jobs :
103+ build :
104+ runs-on : ubuntu-latest
105+ ` ` `
106+
107+ - ` name`: the name of this workflow.
108+ - `on.push.branches` : specifies that this workflow should run on every push
109+ event for the branches in the list.
110+ - `jobs` : creates a job ID (`build`) and declares the type of machine that
111+ the job should run on.
112+
113+ For more information about the YAML syntax used here, see
114+ [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions).
115+
116+ # ## Step three: Define the workflow steps
117+
118+ Now the essentials : what steps to run, and in what order to run them.
119+
120+ ` ` ` yaml
121+ jobs:
122+ build:
123+ runs-on: ubuntu-latest
124+ steps:
125+ -
126+ name: Login to Docker Hub
127+ uses: docker/login-action@v3
128+ with:
129+ username: ${{ vars.DOCKERHUB_USERNAME }}
130+ password: ${{ secrets.DOCKERHUB_TOKEN }}
131+ -
132+ name: Set up Docker Buildx
133+ uses: docker/setup-buildx-action@v3
134+ -
135+ name: Build and push
136+ uses: docker/build-push-action@v6
137+ with:
138+ push: true
139+ tags: ${{ vars.DOCKERHUB_USERNAME }}/clockbox:latest
140+ ` ` `
141+
142+ The previous YAML snippet contains a sequence of steps that :
143+
144+ 1. Signs in to Docker Hub, using the
145+ [Docker Login](https://github.com/marketplace/actions/docker-login) action and your Docker Hub credentials.
146+ 2. Creates a BuildKit builder instance using the
147+ [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx) action.
148+ 3. Builds the container image and pushes it to the Docker Hub repository, using
149+ [Build and push Docker images](https://github.com/marketplace/actions/build-and-push-docker-images).
150+
151+ The `with` key lists a number of input parameters that configures the step :
152+
153+ - `push` : tells the action to upload the image to a registry after building
154+ it.
155+ - `tags` : tags that specify where to push the image.
156+
157+ Add these steps to your workflow file. The full workflow configuration should
158+ look as follows :
159+
160+
161+ ` ` ` yaml
162+ name: ci
163+
164+ on:
165+ push:
166+ branches:
167+ - "main"
168+
169+ jobs:
170+ build:
171+ runs-on: ubuntu-latest
172+ steps:
173+ -
174+ name: Login to Docker Hub
175+ uses: docker/login-action@v3
176+ with:
177+ username: ${{ vars.DOCKERHUB_USERNAME }}
178+ password: ${{ secrets.DOCKERHUB_TOKEN }}
179+ -
180+ name: Set up Docker Buildx
181+ uses: docker/setup-buildx-action@v3
182+ -
183+ name: Build and push
184+ uses: docker/build-push-action@v6
185+ with:
186+ push: true
187+ tags: ${{ vars.DOCKERHUB_USERNAME }}/clockbox:latest
188+ ` ` `
189+
190+ # ## Run the workflow
191+
192+ Save the workflow file and run the job.
193+
194+ 1. Select **Commit changes...** and push the changes to the `main` branch.
195+
196+ After pushing the commit, the workflow starts automatically.
197+
198+ 2. Go to the **Actions** tab. It displays the workflow.
199+
200+ Selecting the workflow shows you the breakdown of all the steps.
201+
202+ 3. When the workflow is complete, go to your
203+ [repositories on Docker Hub](https://hub.docker.com/repositories).
204+
205+ If you see the new repository in that list, it means the GitHub Actions
206+ successfully pushed the image to Docker Hub.
47207
48208# # Next steps
49209
0 commit comments