Skip to content

Commit

Permalink
Merge pull request #21532 from dvdksn/build-check-gha
Browse files Browse the repository at this point in the history
build: add check example for gha
  • Loading branch information
dvdksn authored Nov 29, 2024
2 parents 3e033fc + 9ec2e87 commit a65dac8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
7 changes: 7 additions & 0 deletions content/manuals/build/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,10 @@ experimental checks, the experimental checks will still run:
# syntax=docker/dockerfile:1
# check=skip=all;experimental=all
```

## Further reading

For more information about using build checks, see:

- [Build checks reference](/reference/build-checks/)
- [Validating build configuration with GitHub Actions](/manuals/build/ci/github-actions/checks.md)
103 changes: 103 additions & 0 deletions content/manuals/build/ci/github-actions/checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Validating build configuration with GitHub Actions
linkTitle: Build checks
description: Discover how to validate your build configuration and identify best practice violations using build checks in GitHub Actions.
keywords: github actions, gha, build, checks
---

[Build checks](/manuals/build/checks.md) let you validate your `docker build`
configuration without actually running the build.

## Run checks with `docker/build-push-action`

To run build checks in a GitHub Actions workflow with the `build-push-action`,
set the `call` input parameter to `check`. With this set, the workflow fails if
any check warnings are detected for your build's configuration.

```yaml
name: ci

on:
push:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Validate build configuration
uses: docker/build-push-action@v6
with:
call: check

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: user/app:latest
```
## Run checks with `docker/bake-action`

If you're using Bake and `docker/bake-action` to run your builds, you don't
need to specify any special inputs in your GitHub Actions workflow
configuration. Instead, define a Bake target that calls the `check` method,
and invoke that target in your CI.

```hcl
target "build" {
dockerfile = "Dockerfile"
args = {
FOO = "bar"
}
}
target "validate-build" {
inherits = ["build"]
call = "check"
}
```

```yaml
name: ci
on:
push:
env:
IMAGE_NAME: user/app
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Validate build configuration
uses: docker/bake-action@v5
with:
targets: validate-build
- name: Build
uses: docker/bake-action@v5
with:
targets: build
push: true
```

0 comments on commit a65dac8

Please sign in to comment.