Explorar el Código

Use BuildConfig from API in the CLI

Mohammed Nafees hace 4 años
padre
commit
ec452d4fd1
Se han modificado 4 ficheros con 24 adiciones y 5 borrados
  1. 3 2
      cli/cmd/deploy/build.go
  2. 1 1
      cli/cmd/deploy/create.go
  3. 1 1
      cli/cmd/deploy/deploy.go
  4. 19 1
      cli/cmd/pack/pack.go

+ 3 - 2
cli/cmd/deploy/build.go

@@ -7,6 +7,7 @@ import (
 	"strings"
 
 	api "github.com/porter-dev/porter/api/client"
+	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/docker"
 	"github.com/porter-dev/porter/cli/cmd/pack"
 )
@@ -54,7 +55,7 @@ func (b *BuildAgent) BuildDocker(
 }
 
 // BuildPack uses the cloud-native buildpack client to build a container image
-func (b *BuildAgent) BuildPack(dockerAgent *docker.Agent, dst, tag string) error {
+func (b *BuildAgent) BuildPack(dockerAgent *docker.Agent, dst, tag string, buildConfig *types.BuildConfig) error {
 	// retag the image with "pack-cache" tag so that it doesn't re-pull from the registry
 	if b.imageExists {
 		err := dockerAgent.TagImage(
@@ -81,7 +82,7 @@ func (b *BuildAgent) BuildPack(dockerAgent *docker.Agent, dst, tag string) error
 	}
 
 	// call builder
-	err := packAgent.Build(opts)
+	err := packAgent.Build(opts, buildConfig)
 
 	if err != nil {
 		return err

+ 1 - 1
cli/cmd/deploy/create.go

@@ -283,7 +283,7 @@ func (c *CreateAgent) CreateFromDocker(
 	if opts.Method == DeployBuildTypeDocker {
 		err = buildAgent.BuildDocker(agent, opts.LocalPath, opts.LocalPath, opts.LocalDockerfile, "latest")
 	} else {
-		err = buildAgent.BuildPack(agent, opts.LocalPath, "latest")
+		err = buildAgent.BuildPack(agent, opts.LocalPath, "latest", nil)
 	}
 
 	if err != nil {

+ 1 - 1
cli/cmd/deploy/deploy.go

@@ -272,7 +272,7 @@ func (d *DeployAgent) Build() error {
 		)
 	}
 
-	return buildAgent.BuildPack(d.agent, buildCtx, d.tag)
+	return buildAgent.BuildPack(d.agent, buildCtx, d.tag, d.release.BuildConfig)
 }
 
 // Push pushes a local image to the remote repository linked in the release

+ 19 - 1
cli/cmd/pack/pack.go

@@ -2,16 +2,19 @@ package pack
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"path/filepath"
 
 	"github.com/buildpacks/pack"
+	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/docker"
+	"github.com/porter-dev/porter/internal/integrations/buildpacks"
 )
 
 type Agent struct{}
 
-func (a *Agent) Build(opts *docker.BuildOpts) error {
+func (a *Agent) Build(opts *docker.BuildOpts, buildConfig *types.BuildConfig) error {
 	//create a context object
 	context := context.Background()
 
@@ -40,5 +43,20 @@ func (a *Agent) Build(opts *docker.BuildOpts) error {
 		// Buildpacks:         []string{"gcr.io/paketo-buildpacks/procfile"},
 	}
 
+	if buildConfig != nil {
+		var buildpacks buildpacks.BuildpackInfo
+		err = json.Unmarshal(buildConfig.Buildpacks, &buildpacks)
+		if err == nil {
+			var packs []string
+			for i := range buildpacks.Packs {
+				packs = append(packs, fmt.Sprintf("%s@%s", buildpacks.Packs[i].ID, buildpacks.Packs[i].Version))
+			}
+			if len(packs) > 0 {
+				buildOpts.Builder = "paketobuildpacks/builder:tiny"
+				buildOpts.Buildpacks = packs
+			}
+		}
+	}
+
 	return client.Build(context, buildOpts)
 }