|
| 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 | +To run build checks in a GitHub Actions workflow, specify the `call: check` |
| 12 | +input for `docker/build-push-action`. With this set, the workflow fails if any |
| 13 | +check warnings are detected for your build's configuration. |
| 14 | + |
| 15 | +```yaml |
| 16 | +name: ci |
| 17 | + |
| 18 | +on: |
| 19 | + push: |
| 20 | + |
| 21 | +jobs: |
| 22 | + docker: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Set up Docker Buildx |
| 26 | + uses: docker/setup-buildx-action@v3 |
| 27 | + |
| 28 | + - name: Login to Docker Hub |
| 29 | + uses: docker/login-action@v3 |
| 30 | + with: |
| 31 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 32 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 33 | + |
| 34 | + - name: Validate build configuration |
| 35 | + uses: docker/build-push-action@v6 |
| 36 | + with: |
| 37 | + call: check |
| 38 | + |
| 39 | + - name: Build and push |
| 40 | + uses: docker/build-push-action@v6 |
| 41 | + with: |
| 42 | + push: true |
| 43 | + tags: user/app:latest |
| 44 | +``` |
| 45 | +
|
| 46 | +## Build checks with Bake |
| 47 | +
|
| 48 | +If you're using Bake and `docker/bake-action` to run your builds, you don't |
| 49 | +need to specify any special inputs in your GitHub Actions workflow |
| 50 | +configuration. Instead, define a Bake target that calls the `check` method, |
| 51 | +and invoke that target in your CI. |
| 52 | + |
| 53 | +```hcl |
| 54 | +target "validate-build" { |
| 55 | + call = "check" |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +```yaml |
| 60 | +name: ci |
| 61 | +
|
| 62 | +on: |
| 63 | + push: |
| 64 | +
|
| 65 | +env: |
| 66 | + IMAGE_NAME: user/app |
| 67 | +
|
| 68 | +jobs: |
| 69 | + docker: |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - name: Checkout |
| 73 | + uses: actions/checkout@v4 |
| 74 | +
|
| 75 | + - name: Set up Docker Buildx |
| 76 | + uses: docker/setup-buildx-action@v3 |
| 77 | +
|
| 78 | + - name: Login to Docker Hub |
| 79 | + uses: docker/login-action@v3 |
| 80 | + with: |
| 81 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 82 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 83 | +
|
| 84 | + - name: Extract metadata |
| 85 | + id: meta |
| 86 | + uses: docker/metadata-action@v5 |
| 87 | + with: |
| 88 | + images: ${{ env.IMAGE_NAME }} |
| 89 | +
|
| 90 | + - name: Validate build configuration |
| 91 | + uses: docker/bake-action@v5 |
| 92 | + with: |
| 93 | + files: | |
| 94 | + ./docker-bake.hcl |
| 95 | + ${{ steps.meta.outputs.bake-file-tags }} |
| 96 | + ${{ steps.meta.outputs.bake-file-annotations }} |
| 97 | + targets: validate-build |
| 98 | +
|
| 99 | + - name: Build |
| 100 | + uses: docker/bake-action@v5 |
| 101 | + with: |
| 102 | + files: | |
| 103 | + ./docker-bake.hcl |
| 104 | + ${{ steps.meta.outputs.bake-file-tags }} |
| 105 | + ${{ steps.meta.outputs.bake-file-annotations }} |
| 106 | + push: true |
| 107 | +``` |
0 commit comments