Skip to content

Commit

Permalink
fixing a little bug when creating a builder without target flag on da…
Browse files Browse the repository at this point in the history
…rwin

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
  • Loading branch information
jjbustamante committed May 21, 2024
1 parent 3f3b24d commit cfdcaf6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
31 changes: 25 additions & 6 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,38 @@ func (c *Client) addConfig(ctx context.Context, kind string, config pubbldr.Modu

func (c *Client) processBuilderCreateTargets(ctx context.Context, opts CreateBuilderOptions) ([]dist.Target, error) {
var targets []dist.Target
if len(opts.Targets) > 0 {
// when exporting to the daemon, we need to select just one target
if !opts.Publish {
daemonTarget, err := c.daemonTarget(ctx, opts.Targets)

// For backward compatibility, we must create a target with de default platform used in the Fetch implementation for daemon and remote
// When daemon
// OS: daemonInfo.Os,
// Architecture: daemonInfo.Arch
// When remote || layout
// OS: "linux",
// Architecture: runtime.GOARCH

if !opts.Publish {
// daemon option
info, err := c.docker.ServerVersion(ctx)
if err != nil {
return targets, err
}
if len(opts.Targets) > 0 {
// when exporting to the daemon, we need to select just one target
daemonTarget, err := c.daemonTarget(info, opts.Targets)
if err != nil {
return targets, err
}
targets = append(targets, daemonTarget)
} else {
targets = opts.Targets
targets = append(targets, dist.Target{OS: info.Os, Arch: info.Arch})
}
} else {
targets = append(targets, dist.Target{OS: runtime.GOOS, Arch: runtime.GOARCH})
// remote option
if len(opts.Targets) > 0 {
targets = opts.Targets
} else {
targets = append(targets, dist.Target{OS: "linux", Arch: runtime.GOARCH})
}
}
return targets, nil
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/client/package_buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"path/filepath"

"github.com/docker/docker/api/types"
"github.com/pkg/errors"

pubbldpkg "github.com/buildpacks/pack/buildpackage"
Expand Down Expand Up @@ -228,10 +229,14 @@ func (c *Client) downloadBuildpackFromURI(ctx context.Context, uri, relativeBase

func (c *Client) processPackageBuildpackTargets(ctx context.Context, opts PackageBuildpackOptions) ([]dist.Target, error) {
var targets []dist.Target
info, err := c.docker.ServerVersion(ctx)
if err != nil {
return targets, err
}
if len(opts.Targets) > 0 {
// when exporting to the daemon, we need to select just one target
if !opts.Publish && opts.Format == FormatImage {
daemonTarget, err := c.daemonTarget(ctx, opts.Targets)
daemonTarget, err := c.daemonTarget(info, opts.Targets)
if err != nil {
return targets, err
}
Expand Down Expand Up @@ -262,12 +267,8 @@ func (c *Client) validateOSPlatform(ctx context.Context, os string, publish bool
return nil
}

func (c *Client) daemonTarget(ctx context.Context, targets []dist.Target) (dist.Target, error) {
info, err := c.docker.ServerVersion(ctx)
if err != nil {
return dist.Target{}, err
}

// daemonTarget returns a target that matches with the given daemon os/arch
func (c *Client) daemonTarget(info types.Version, targets []dist.Target) (dist.Target, error) {
for _, t := range targets {
if t.Arch != "" && t.OS == info.Os && t.Arch == info.Arch {
return t, nil
Expand Down

0 comments on commit cfdcaf6

Please sign in to comment.