-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exporter: detect if multi-platform is set
This is required now that the correspondence between platforms and refs has been broken. Without it, there's no way to detect between the following cases from the output that they emit: buildctl build --opt platform=linux/amd64 --opt attest:sbom buildctl build --opt platform=linux/amd64 --opt attest:sbom --opt build-arg:BUILDKIT_MULTI_PLATFORM=true We'd like the former to produce a flat file structure through the local exporter, and the latter to produce an explicitly nested file structure through the same exporter. However, both of these produce Refs instead of a singular Ref, so we can't just look at the Result to know which one. Similar to how we handle the SOURCE_DATE_EPOCH build-arg, we can handle the multi-platform args at the control API boundary, setting the explicit option multi-platform in the exporter if it is set. In the future, we can guide users away from the BUILDKIT_MULTI_PLATFORM args entirely, and towards the multi-platform exporter option if we want. Signed-off-by: Justin Chadwell <me@jedevc.com>
- Loading branch information
Showing
7 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package multiplatform | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
frontendMultiPlatform = "multi-platform" | ||
frontendMultiPlatformArg = "build-arg:BUILDKIT_MULTI_PLATFORM" | ||
|
||
KeyMultiPlatform = "multi-platform" | ||
) | ||
|
||
func ParseFrontend(opt map[string]string) (string, bool) { | ||
if v, ok := opt[frontendMultiPlatform]; ok { | ||
return v, true | ||
} | ||
if v, ok := opt[frontendMultiPlatformArg]; ok { | ||
return v, true | ||
} | ||
return "", false | ||
} | ||
|
||
func ParseAttr(opt map[string]string) (*bool, map[string]string, error) { | ||
rest := make(map[string]string, len(opt)) | ||
|
||
var multiPlatform *bool | ||
|
||
for k, v := range opt { | ||
switch k { | ||
case KeyMultiPlatform: | ||
b, err := strconv.ParseBool(v) | ||
if err != nil { | ||
return nil, nil, errors.Errorf("invalid boolean value %s", v) | ||
} | ||
multiPlatform = &b | ||
default: | ||
rest[k] = v | ||
} | ||
} | ||
|
||
return multiPlatform, rest, nil | ||
} |