Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake: display read definition files in build output #2076

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Oct 14, 2023

If no bake definition are specified, it will currently consume the default ones in this specified order:

buildx/bake/bake.go

Lines 47 to 53 in 05b8821

names = append(names, composecli.DefaultFileNames...)
names = append(names, []string{
"docker-bake.json",
"docker-bake.override.json",
"docker-bake.hcl",
"docker-bake.override.hcl",
}...)

Following-up a discussion with @milas:

If you have both docker-bake.hcl AND docker-compose.yml in a directory, Bake always parses the Compose file unless you pass -f docker-bake.hcl explicitly
So if you have a syntax error in your compose file:

❯ docker buildx bake services
[+] Building 0.0s (0/0)                                                                                                                  cloud:cloud-stage
ERROR: parsing : yaml: line 3: mapping values are not allowed in this context

But:

❯ docker buildx bake -f docker-bake.hcl services
[+] Building 0.5s (10/10) FINISHED                                                                                                       cloud:cloud-stage
 => [registry internal] connected to docker's cloud service                                                                                           0.0s
 => => note: cloud builds are currently in beta                                                                                                       0.0s

I actually noticed this because I was getting this in my bake:

WARNING: The "BUILD_SERVICE_CLIENT_MTLS_CERT" variable is not set. Defaulting to a blank string.

and was SO confused because that's not part of the Dockerfile or Bake file and I thought it was actually coming FROM the builder but that's a variable in the Compose file (that it wasn't even using) and that's compose-go writing out that message to stdout

So there is an issue with compose-go writing on stdout warnings: https://github.com/compose-spec/compose-go/blob/2d32c3f774bda0ad20e8d06eae493047b728fc54/template/template.go#L206. Didn't find an easy way to disable logging via https://github.com/compose-spec/compose-go/blob/2d32c3f774bda0ad20e8d06eae493047b728fc54/template/template.go#L114-L116 without setting options.Interpolate.Substitute and redefining templating on our side. @milas @glours Is it possible to have smth easier to consume through loader.Options instead like options.Logging = false?

It also appears in his case that consuming a compose.yml and docker-bake.hcl when invoking docker buildx bake is unexpected/confusing. Maybe we could put some effort and clearly state this behavior in our docs https://docs.docker.com/build/bake/reference/#file-format (cc @dvdksn).

On the other hand it's pretty common to have a compose file just for runtime and a bake hcl file to build on a repository so I tend to agree with him.

This PR will show what bake definitions are consumed in the build output to mitigate this issue and help user figures out what is the source of the definition:

$ docker buildx bake binaries
[+] Building 2.1s (10/10) FINISHED                                                                                                                                                                             docker:default
 => [internal] load local bake definitions                                                                                                                                                                               0.0s 
 => => reading compose.yaml 954B / 954B                                                                                                                                                                                  0.0s
 => => reading docker-bake.hcl 3.68kB / 3.68kB                                                                                                                                                                           0.0s 
 => [internal] load .dockerignore                                                                                                                                                                                        0.1s
 => => transferring context: 45B                                                                                                                                                                                         0.0s 
 => [internal] load build definition from Dockerfile                                                                                                                                                                     0.1s 
 => => transferring dockerfile: 4.66kB                                                                                                                                                                                   0.0s 
 => resolve image config for docker.io/docker/dockerfile:1
...
$ docker buildx bake binaries
#0 building with "default" instance using docker driver

#1 [internal] load local bake definitions
#1 reading compose.yaml 954B / 954B done
#1 reading docker-bake.hcl 3.68kB / 3.68kB done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 4.66kB 0.0s done
#2 DONE 0.1s

#3 [internal] load .dockerignore
#3 transferring context: 45B 0.0s done
#3 DONE 0.1s

#4 resolve image config for docker.io/docker/dockerfile:1
#4 DONE 0.5s
...

@crazy-max

This comment was marked as outdated.

bake/bake.go Outdated Show resolved Hide resolved
bake/remote.go Outdated Show resolved Hide resolved
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@crazy-max crazy-max added this to the v0.12.0 milestone Oct 23, 2023
@crazy-max crazy-max merged commit ee19ce5 into docker:master Oct 24, 2023
59 checks passed
@crazy-max crazy-max deleted the bake-display-files branch October 24, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants