-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of the multi-platform RFC - 0128
Signed-off-by: Juan Bustamante <[email protected]>
- Loading branch information
1 parent
67feb16
commit cb4b368
Showing
28 changed files
with
1,006 additions
and
150 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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ type BuilderCreateFlags struct { | |
Registry string | ||
Policy string | ||
Flatten []string | ||
Targets []string | ||
Label map[string]string | ||
} | ||
|
||
|
@@ -87,6 +88,15 @@ Creating a custom builder allows you to control what buildpacks are used and wha | |
return err | ||
} | ||
|
||
multiArchCfg, err := processMultiArchitectureConfig(logger, flags.Targets, builderConfig.Targets, !flags.Publish) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(multiArchCfg.Targets()) == 0 { | ||
logger.Warnf("A new '--target' flag is available to set the platform") | ||
} | ||
|
||
imageName := args[0] | ||
if err := pack.CreateBuilder(cmd.Context(), client.CreateBuilderOptions{ | ||
RelativeBaseDir: relativeBaseDir, | ||
|
@@ -98,6 +108,7 @@ Creating a custom builder allows you to control what buildpacks are used and wha | |
PullPolicy: pullPolicy, | ||
Flatten: toFlatten, | ||
Labels: flags.Label, | ||
Targets: multiArchCfg.Targets(), | ||
}); err != nil { | ||
return err | ||
} | ||
|
@@ -116,6 +127,12 @@ Creating a custom builder allows you to control what buildpacks are used and wha | |
cmd.Flags().StringVar(&flags.Policy, "pull-policy", "", "Pull policy to use. Accepted values are always, never, and if-not-present. The default is always") | ||
cmd.Flags().StringArrayVar(&flags.Flatten, "flatten", nil, "List of buildpacks to flatten together into a single layer (format: '<buildpack-id>@<buildpack-version>,<buildpack-id>@<buildpack-version>'") | ||
cmd.Flags().StringToStringVarP(&flags.Label, "label", "l", nil, "Labels to add to the builder image, in the form of '<name>=<value>'") | ||
cmd.Flags().StringSliceVarP(&flags.Targets, "target", "t", nil, | ||
`Target platforms to build for.\nTargets should be in the format '[os][/arch][/variant]:[distroname@osversion@anotherversion];[distroname@osversion]'. | ||
- To specify two different architectures : '--target "linux/amd64" --target "linux/arm64"' | ||
- To specify the distribution version: '--target "linux/arm/v6@[email protected]"' | ||
- To specify multiple distribution versions : '--target "linux/arm/v6:[email protected]" --target "linux/arm/v6:[email protected]"' | ||
`) | ||
|
||
AddHelpFlag(cmd, "create") | ||
return cmd | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ package commands | |
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
|
@@ -12,6 +13,7 @@ import ( | |
"github.com/buildpacks/pack/internal/config" | ||
"github.com/buildpacks/pack/internal/style" | ||
"github.com/buildpacks/pack/pkg/client" | ||
"github.com/buildpacks/pack/pkg/dist" | ||
"github.com/buildpacks/pack/pkg/image" | ||
"github.com/buildpacks/pack/pkg/logging" | ||
) | ||
|
@@ -24,6 +26,7 @@ type BuildpackPackageFlags struct { | |
BuildpackRegistry string | ||
Path string | ||
FlattenExclude []string | ||
Targets []string | ||
Label map[string]string | ||
Publish bool | ||
Flatten bool | ||
|
@@ -37,6 +40,7 @@ type BuildpackPackager interface { | |
// PackageConfigReader reads BuildpackPackage configs | ||
type PackageConfigReader interface { | ||
Read(path string) (pubbldpkg.Config, error) | ||
ReadBuildpackDescriptor(path string) (dist.BuildpackDescriptor, error) | ||
} | ||
|
||
// BuildpackPackage packages (a) buildpack(s) into OCI format, based on a package config | ||
|
@@ -100,6 +104,26 @@ func BuildpackPackage(logger logging.Logger, cfg config.Config, packager Buildpa | |
logger.Warn("Flattening a buildpack package could break the distribution specification. Please use it with caution.") | ||
} | ||
|
||
targets, composedBP, err := processBuildpackPackageTargets(flags.Path, packageConfigReader, bpPackageCfg) | ||
if err != nil { | ||
return err | ||
} | ||
daemon := !flags.Publish && flags.Format == "" | ||
multiArchCfg, err := processMultiArchitectureConfig(logger, flags.Targets, targets, daemon) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(multiArchCfg.Targets()) == 0 { | ||
logger.Warnf("A new '--target' flag is available to set the platform, using '%s' as default", bpPackageCfg.Platform.OS) | ||
} else if !composedBP { | ||
filesToClean, err := multiArchCfg.CopyConfigFiles(relativeBaseDir) | ||
if err != nil { | ||
return err | ||
} | ||
defer clean(filesToClean) | ||
} | ||
|
||
if err := packager.PackageBuildpack(cmd.Context(), client.PackageBuildpackOptions{ | ||
RelativeBaseDir: relativeBaseDir, | ||
Name: name, | ||
|
@@ -111,6 +135,7 @@ func BuildpackPackage(logger logging.Logger, cfg config.Config, packager Buildpa | |
Flatten: flags.Flatten, | ||
FlattenExclude: flags.FlattenExclude, | ||
Labels: flags.Label, | ||
Targets: multiArchCfg.Targets(), | ||
}); err != nil { | ||
return err | ||
} | ||
|
@@ -138,6 +163,13 @@ func BuildpackPackage(logger logging.Logger, cfg config.Config, packager Buildpa | |
cmd.Flags().BoolVar(&flags.Flatten, "flatten", false, "Flatten the buildpack into a single layer") | ||
cmd.Flags().StringSliceVarP(&flags.FlattenExclude, "flatten-exclude", "e", nil, "Buildpacks to exclude from flattening, in the form of '<buildpack-id>@<buildpack-version>'") | ||
cmd.Flags().StringToStringVarP(&flags.Label, "label", "l", nil, "Labels to add to packaged Buildpack, in the form of '<name>=<value>'") | ||
cmd.Flags().StringSliceVarP(&flags.Targets, "target", "t", nil, | ||
`Target platforms to build for. | ||
Targets should be in the format '[os][/arch][/variant]:[distroname@osversion@anotherversion];[distroname@osversion]'. | ||
- To specify two different architectures : '--target "linux/amd64" --target "linux/arm64"' | ||
- To specify the distribution version: '--target "linux/arm/v6@[email protected]"' | ||
- To specify multiple distribution versions : '--target "linux/arm/v6:[email protected]" --target "linux/arm/v6:[email protected]"' | ||
`) | ||
if !cfg.Experimental { | ||
cmd.Flags().MarkHidden("flatten") | ||
cmd.Flags().MarkHidden("flatten-exclude") | ||
|
@@ -169,3 +201,41 @@ func validateBuildpackPackageFlags(cfg config.Config, p *BuildpackPackageFlags) | |
} | ||
return nil | ||
} | ||
|
||
// processBuildpackPackageTargets returns the list of targets defined in the configuration file, it could be the buildpack.toml or | ||
// the package.toml if the buildpack is a composed buildpack | ||
func processBuildpackPackageTargets(path string, packageConfigReader PackageConfigReader, bpPackageCfg pubbldpkg.Config) ([]dist.Target, bool, error) { | ||
var ( | ||
targets []dist.Target | ||
order dist.Order | ||
composedBP bool | ||
) | ||
|
||
// Read targets from buildpack.toml | ||
pathToBuildpackToml := filepath.Join(path, "buildpack.toml") | ||
if _, err := os.Stat(pathToBuildpackToml); err == nil { | ||
buildpackCfg, err := packageConfigReader.ReadBuildpackDescriptor(pathToBuildpackToml) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
targets = buildpackCfg.Targets() | ||
order = buildpackCfg.Order() | ||
composedBP = len(order) > 0 | ||
} | ||
|
||
// When composite buildpack, targets are defined in package.toml - See RFC-0128 | ||
if composedBP { | ||
targets = bpPackageCfg.Targets | ||
} | ||
return targets, composedBP, nil | ||
} | ||
|
||
func clean(paths []string) error { | ||
// we need to clean the buildpack.toml for each place where we copied to | ||
if len(paths) > 0 { | ||
for _, path := range paths { | ||
os.Remove(path) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.