@@ -3296,6 +3296,185 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
32963296 })
32973297 })
32983298 })
3299+
3300+ when ("multi-platform" , func () {
3301+ var (
3302+ tmpDir string
3303+ multiArchBuildpackPackage string
3304+ builderTomlPath string
3305+ remoteRunImage string
3306+ remoteBuildImage string
3307+ err error
3308+ )
3309+
3310+ it .Before (func () {
3311+ h .SkipIf (t , ! pack .SupportsFeature (invoke .MultiPlatformBuildersAndBuildPackages ), "multi-platform builders and buildpack packages are available since 0.34.0" )
3312+
3313+ tmpDir , err = os .MkdirTemp ("" , "multi-platform-builder-create-tests" )
3314+ assert .Nil (err )
3315+
3316+ // used to avoid authentication issues with the local registry
3317+ os .Setenv ("DOCKER_CONFIG" , registryConfig .DockerConfigDir )
3318+
3319+ // create a multi-platform buildpack and push it to a registry
3320+ multiArchBuildpackPackage = registryConfig .RepoName ("simple-multi-platform-buildpack" + h .RandString (8 ))
3321+ sourceDir := filepath .Join ("testdata" , "mock_buildpacks" )
3322+ path := filepath .Join (tmpDir , "simple-layers-buildpack" )
3323+ err = buildpacks .BpFolderSimpleLayers .Prepare (sourceDir , tmpDir )
3324+ h .AssertNil (t , err )
3325+
3326+ output := pack .RunSuccessfully (
3327+ "buildpack" , "package" , multiArchBuildpackPackage ,
3328+ "--path" , path ,
3329+ "--publish" ,
3330+ "--target" , "linux/amd64" ,
3331+ "--target" , "windows/amd64" ,
3332+ )
3333+ assertions .NewOutputAssertionManager (t , output ).ReportsPackagePublished (multiArchBuildpackPackage )
3334+ assertions .NewOutputAssertionManager (t , output ).ReportsSuccessfulIndexPushed (multiArchBuildpackPackage )
3335+ h .AssertRemoteImageIndex (t , multiArchBuildpackPackage , types .OCIImageIndex , 2 )
3336+
3337+ // runImage and buildImage are saved in the daemon, for this test we want them to be available in a registry
3338+ remoteRunImage = registryConfig .RepoName (runImage + h .RandString (8 ))
3339+ remoteBuildImage = registryConfig .RepoName (buildImage + h .RandString (8 ))
3340+
3341+ imageManager .TagImage (runImage , remoteRunImage )
3342+ imageManager .TagImage (buildImage , remoteBuildImage )
3343+
3344+ h .AssertNil (t , h .PushImage (dockerCli , remoteRunImage , registryConfig ))
3345+ h .AssertNil (t , h .PushImage (dockerCli , remoteBuildImage , registryConfig ))
3346+ })
3347+
3348+ it .After (func () {
3349+ imageManager .CleanupImages (remoteBuildImage )
3350+ imageManager .CleanupImages (remoteRunImage )
3351+ os .RemoveAll (tmpDir )
3352+ })
3353+
3354+ generateMultiPlatformBuilderToml := func (template , buildpackURI , buildImage , runImage string ) string {
3355+ t .Helper ()
3356+ buildpackToml , err := os .CreateTemp (tmpDir , "buildpack-*.toml" )
3357+ assert .Nil (err )
3358+
3359+ pack .FixtureManager ().TemplateFixtureToFile (
3360+ template ,
3361+ buildpackToml ,
3362+ map [string ]interface {}{
3363+ "BuildpackURI" : buildpackURI ,
3364+ "BuildImage" : buildImage ,
3365+ "RunImage" : runImage ,
3366+ },
3367+ )
3368+ assert .Nil (buildpackToml .Close ())
3369+ return buildpackToml .Name ()
3370+ }
3371+
3372+ when ("builder.toml has no targets but the user provides --target" , func () {
3373+ when ("--publish" , func () {
3374+ it .Before (func () {
3375+ builderName = registryConfig .RepoName ("remote-multi-platform-builder" + h .RandString (8 ))
3376+
3377+ // We need to configure our builder.toml with image references that points to our ephemeral registry
3378+ builderTomlPath = generateMultiPlatformBuilderToml ("builder_multi_platform-no-targets.toml" , multiArchBuildpackPackage , remoteBuildImage , remoteRunImage )
3379+ })
3380+
3381+ it ("publishes builder images for each requested target to the registry and creates an image index" , func () {
3382+ output := pack .RunSuccessfully (
3383+ "builder" , "create" , builderName ,
3384+ "--config" , builderTomlPath ,
3385+ "--publish" ,
3386+ "--target" , "linux/amd64" ,
3387+ "--target" , "windows/amd64" ,
3388+ )
3389+
3390+ defer imageManager .CleanupImages (builderName )
3391+ assertions .NewOutputAssertionManager (t , output ).ReportsBuilderCreated (builderName )
3392+
3393+ assertImage .CanBePulledFromRegistry (builderName )
3394+
3395+ assertions .NewOutputAssertionManager (t , output ).ReportsSuccessfulIndexPushed (builderName )
3396+ h .AssertRemoteImageIndex (t , builderName , types .OCIImageIndex , 2 )
3397+ })
3398+ })
3399+
3400+ when ("--daemon" , func () {
3401+ it .Before (func () {
3402+ builderName = registryConfig .RepoName ("local-multi-platform-builder" + h .RandString (8 ))
3403+
3404+ // We need to configure our builder.toml with image references that points to our ephemeral registry
3405+ builderTomlPath = generateMultiPlatformBuilderToml ("builder_multi_platform-no-targets.toml" , multiArchBuildpackPackage , buildImage , runImage )
3406+ })
3407+
3408+ it ("publishes builder image to the daemon for the given target" , func () {
3409+ platform := "linux/amd64"
3410+ if runtime .GOOS == "windows" {
3411+ platform = "windows/amd64"
3412+ }
3413+
3414+ output := pack .RunSuccessfully (
3415+ "builder" , "create" , builderName ,
3416+ "--config" , builderTomlPath ,
3417+ "--target" , platform ,
3418+ )
3419+
3420+ defer imageManager .CleanupImages (builderName )
3421+ assertions .NewOutputAssertionManager (t , output ).ReportsBuilderCreated (builderName )
3422+ })
3423+ })
3424+ })
3425+
3426+ when ("builder.toml has targets" , func () {
3427+ when ("--publish" , func () {
3428+ it .Before (func () {
3429+ builderName = registryConfig .RepoName ("remote-multi-platform-builder" + h .RandString (8 ))
3430+
3431+ // We need to configure our builder.toml with image references that points to our ephemeral registry
3432+ builderTomlPath = generateMultiPlatformBuilderToml ("builder_multi_platform.toml" , multiArchBuildpackPackage , remoteBuildImage , remoteRunImage )
3433+ })
3434+
3435+ it ("publishes builder images for each configured target to the registry and creates an image index" , func () {
3436+ output := pack .RunSuccessfully (
3437+ "builder" , "create" , builderName ,
3438+ "--config" , builderTomlPath ,
3439+ "--publish" ,
3440+ )
3441+
3442+ defer imageManager .CleanupImages (builderName )
3443+ assertions .NewOutputAssertionManager (t , output ).ReportsBuilderCreated (builderName )
3444+
3445+ assertImage .CanBePulledFromRegistry (builderName )
3446+
3447+ assertions .NewOutputAssertionManager (t , output ).ReportsSuccessfulIndexPushed (builderName )
3448+ h .AssertRemoteImageIndex (t , builderName , types .OCIImageIndex , 2 )
3449+ })
3450+ })
3451+
3452+ when ("--daemon" , func () {
3453+ it .Before (func () {
3454+ builderName = registryConfig .RepoName ("local-multi-platform-builder" + h .RandString (8 ))
3455+
3456+ // We need to configure our builder.toml with image references that points to our ephemeral registry
3457+ builderTomlPath = generateMultiPlatformBuilderToml ("builder_multi_platform.toml" , multiArchBuildpackPackage , buildImage , runImage )
3458+ })
3459+
3460+ it ("publishes builder image to the daemon for the given target" , func () {
3461+ platform := "linux/amd64"
3462+ if runtime .GOOS == "windows" {
3463+ platform = "windows/amd64"
3464+ }
3465+
3466+ output := pack .RunSuccessfully (
3467+ "builder" , "create" , builderName ,
3468+ "--config" , builderTomlPath ,
3469+ "--target" , platform ,
3470+ )
3471+
3472+ defer imageManager .CleanupImages (builderName )
3473+ assertions .NewOutputAssertionManager (t , output ).ReportsBuilderCreated (builderName )
3474+ })
3475+ })
3476+ })
3477+ })
32993478 })
33003479
33013480 when ("builder create" , func () {
0 commit comments