Closed shmokmt closed 1 month ago
docker build
(when using BuildKit) is no longer handled by the CLI itself, but handled through the buildx
plugin behind the scenes. Let me move this to the buildx issue tracker.
You can already do this with
$ docker build --call=check,format=json .
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 65B done
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/busybox:latest
#2 DONE 0.0s
#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s
{
"warnings": null,
"sources": [
{
"filename": "Dockerfile",
"data": "RlJPTSBidXN5Ym94ClJVTiBlY2hvIGhlbGxvCg==",
"definition": {
"def": [
"GsUBChJsb2NhbDovL2RvY2tlcmZpbGUSFAoMbG9jYWwuZGlmZmVyEgRub25lEkoKEWxvY2FsLmZvbGxvd3BhdGhzEjVbIkRvY2tlcmZpbGUiLCJEb2NrZXJmaWxlLmRvY2tlcmlnbm9yZSIsImRvY2tlcmZpbGUiXRIqCg1sb2NhbC5zZXNzaW9uEhlucDNqdnE3aGdnczc5ZnMydTdxb25vNGtqEiEKE2xvY2FsLnNoYXJlZGtleWhpbnQSCmRvY2tlcmZpbGVaAA==",
"CkkKR3NoYTI1Njo4NDFkOTcwYWYzMjk0NTE3ZjUzYzRmOGYwM2M2Y2UyYzZhOWE0NzYyYmU2MGIzNTY0ZTIwNWEwZDUzNTYyOWEz"
],
"metadata": {
"sha256:841d970af3294517f53c4f8f03c6ce2c6a9a4762be60b3564e205a0d535629a3": {
"description": {
"llb.customname": "[internal] load build definition from Dockerfile"
},
"caps": {
"source.local": true,
"source.local.followpaths": true,
"source.local.sessionid": true,
"source.local.sharedkeyhint": true
}
},
"sha256:ef84cc1cd20314a312c61980e9a9a6a70048ca3d8134256cfc11df9465e86be8": {
"caps": {
"constraints": true,
"meta.description": true,
"platform": true
}
}
},
"Source": {
"locations": {
"sha256:841d970af3294517f53c4f8f03c6ce2c6a9a4762be60b3564e205a0d535629a3": {}
}
}
},
"language": "Dockerfile"
}
]
}
Or if you want to build and have the checks, you can use the metadata file: https://docs.docker.com/reference/cli/docker/buildx/build/#metadata-file
$ BUILDX_METADATA_WARNINGS=1 docker build --metadata-file=metadata.json .
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 65B done
#1 WARN: ConsistentInstructionCasing: Command 'From' should match the case of the command majority (uppercase) (line 1)
#1 DONE 0.0s
#2 [internal] load metadata for docker.io/library/busybox:latest
#2 DONE 0.0s
#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s
#4 [1/2] FROM docker.io/library/busybox:latest
#4 DONE 0.0s
#5 [2/2] RUN echo hello
#5 CACHED
#6 exporting to image
#6 exporting layers done
#6 writing image sha256:ebb4c591f9353c8ebf8a1dab4e2326d7faaa66e34e6a161c0813a18c6dc056b6 done
#6 DONE 0.0s
#7 resolving provenance for metadata file
#7 DONE 0.0s
1 warning found (use docker --debug to expand):
- ConsistentInstructionCasing: Command 'From' should match the case of the command majority (uppercase) (line 1)
$ jq . metadata.json
{
"buildx.build.provenance": {
"buildType": "https://mobyproject.org/buildkit@v1",
"materials": [
{
"uri": "pkg:docker/busybox@latest?platform=linux%2Famd64",
"digest": {
"sha256": "49b3a50a20394e079b4b4732e1e9e434137c9dd6500a6e1976a00ca88bed4774"
}
}
],
"invocation": {
"configSource": {
"entryPoint": "Dockerfile"
},
"parameters": {
"frontend": "dockerfile.v0",
"locals": [
{
"name": "context"
},
{
"name": "dockerfile"
}
]
},
"environment": {
"platform": "linux/amd64"
}
}
},
"buildx.build.ref": "default/default/4xo2x0xqqx87upmbn3woi4v25",
"buildx.build.warnings": [
{
"vertex": "sha256:39e3cbe3056bae8e5f634372f698d30c4563506aade14047533f6c622c684b1e",
"level": 1,
"short": "Q29uc2lzdGVudEluc3RydWN0aW9uQ2FzaW5nOiBDb21tYW5kICdGcm9tJyBzaG91bGQgbWF0Y2ggdGhlIGNhc2Ugb2YgdGhlIGNvbW1hbmQgbWFqb3JpdHkgKHVwcGVyY2FzZSkgKGxpbmUgMSk=",
"detail": [
"QWxsIGNvbW1hbmRzIHdpdGhpbiB0aGUgRG9ja2VyZmlsZSBzaG91bGQgdXNlIHRoZSBzYW1lIGNhc2luZyAoZWl0aGVyIHVwcGVyIG9yIGxvd2VyKQ=="
],
"url": "https://docs.docker.com/go/dockerfile/rule/consistent-instruction-casing/",
"sourceInfo": {
"filename": "Dockerfile",
"data": "RnJvbSBidXN5Ym94ClJVTiBlY2hvIGhlbGxvCg==",
"language": "Dockerfile"
},
"range": [
{
"start": {
"line": 1
},
"end": {
"line": 1
}
}
]
}
],
"containerimage.config.digest": "sha256:ebb4c591f9353c8ebf8a1dab4e2326d7faaa66e34e6a161c0813a18c6dc056b6",
"containerimage.digest": "sha256:ebb4c591f9353c8ebf8a1dab4e2326d7faaa66e34e6a161c0813a18c6dc056b6"
}
Description
I would like to propose a feature request for
docker build --check
to support JSON output. This would allow for seamless integration with tools like reviewdog, enabling automated linting and code quality checks directly within the Pull Request workflow. Thanks!