Skip to content

Commit 9ec2e87

Browse files
committed
build: add check example for gha
Signed-off-by: David Karlsson <[email protected]>
1 parent 3e033fc commit 9ec2e87

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

content/manuals/build/checks.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,10 @@ experimental checks, the experimental checks will still run:
278278
# syntax=docker/dockerfile:1
279279
# check=skip=all;experimental=all
280280
```
281+
282+
## Further reading
283+
284+
For more information about using build checks, see:
285+
286+
- [Build checks reference](/reference/build-checks/)
287+
- [Validating build configuration with GitHub Actions](/manuals/build/ci/github-actions/checks.md)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: Validating build configuration with GitHub Actions
3+
linkTitle: Build checks
4+
description: Discover how to validate your build configuration and identify best practice violations using build checks in GitHub Actions.
5+
keywords: github actions, gha, build, checks
6+
---
7+
8+
[Build checks](/manuals/build/checks.md) let you validate your `docker build`
9+
configuration without actually running the build.
10+
11+
## Run checks with `docker/build-push-action`
12+
13+
To run build checks in a GitHub Actions workflow with the `build-push-action`,
14+
set the `call` input parameter to `check`. With this set, the workflow fails if
15+
any check warnings are detected for your build's configuration.
16+
17+
```yaml
18+
name: ci
19+
20+
on:
21+
push:
22+
23+
jobs:
24+
docker:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Login to Docker Hub
31+
uses: docker/login-action@v3
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_TOKEN }}
35+
36+
- name: Validate build configuration
37+
uses: docker/build-push-action@v6
38+
with:
39+
call: check
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v6
43+
with:
44+
push: true
45+
tags: user/app:latest
46+
```
47+
48+
## Run checks with `docker/bake-action`
49+
50+
If you're using Bake and `docker/bake-action` to run your builds, you don't
51+
need to specify any special inputs in your GitHub Actions workflow
52+
configuration. Instead, define a Bake target that calls the `check` method,
53+
and invoke that target in your CI.
54+
55+
```hcl
56+
target "build" {
57+
dockerfile = "Dockerfile"
58+
args = {
59+
FOO = "bar"
60+
}
61+
}
62+
target "validate-build" {
63+
inherits = ["build"]
64+
call = "check"
65+
}
66+
```
67+
68+
```yaml
69+
name: ci
70+
71+
on:
72+
push:
73+
74+
env:
75+
IMAGE_NAME: user/app
76+
77+
jobs:
78+
docker:
79+
runs-on: ubuntu-latest
80+
steps:
81+
- name: Checkout
82+
uses: actions/checkout@v4
83+
84+
- name: Set up Docker Buildx
85+
uses: docker/setup-buildx-action@v3
86+
87+
- name: Login to Docker Hub
88+
uses: docker/login-action@v3
89+
with:
90+
username: ${{ vars.DOCKERHUB_USERNAME }}
91+
password: ${{ secrets.DOCKERHUB_TOKEN }}
92+
93+
- name: Validate build configuration
94+
uses: docker/bake-action@v5
95+
with:
96+
targets: validate-build
97+
98+
- name: Build
99+
uses: docker/bake-action@v5
100+
with:
101+
targets: build
102+
push: true
103+
```

0 commit comments

Comments
 (0)