|
|
@@ -3,12 +3,15 @@ package pack
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "net/url"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/buildpacks/pack"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
"github.com/porter-dev/porter/cli/cmd/docker"
|
|
|
+ "github.com/porter-dev/porter/cli/cmd/github"
|
|
|
+ "k8s.io/client-go/util/homedir"
|
|
|
)
|
|
|
|
|
|
type Agent struct{}
|
|
|
@@ -41,8 +44,34 @@ func (a *Agent) Build(opts *docker.BuildOpts, buildConfig *types.BuildConfig) er
|
|
|
|
|
|
if buildConfig != nil {
|
|
|
buildOpts.Builder = buildConfig.Builder
|
|
|
- if len(buildConfig.Buildpacks) > 0 {
|
|
|
- buildOpts.Buildpacks = buildConfig.Buildpacks
|
|
|
+ for i := range buildConfig.Buildpacks {
|
|
|
+ bp := buildConfig.Buildpacks[i]
|
|
|
+ u, err := url.Parse(bp)
|
|
|
+ if err == nil {
|
|
|
+ // could be a git repository containing the buildpack
|
|
|
+ dstDir := filepath.Join(homedir.HomeDir(), ".porter")
|
|
|
+ bpCustomName := strings.ReplaceAll(u.Path, "/", "-")
|
|
|
+ downloader := &github.ZIPDownloader{
|
|
|
+ ZipFolderDest: dstDir,
|
|
|
+ AssetFolderDest: dstDir,
|
|
|
+ ZipName: fmt.Sprintf("%s.zip", bpCustomName),
|
|
|
+ RemoveAfterDownload: true,
|
|
|
+ }
|
|
|
+
|
|
|
+ err = downloader.DownloadToFile(bp)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = downloader.UnzipToDir()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ buildOpts.Buildpacks = append(buildOpts.Buildpacks, bpCustomName)
|
|
|
+ } else {
|
|
|
+ buildOpts.Buildpacks = append(buildOpts.Buildpacks, bp)
|
|
|
+ }
|
|
|
}
|
|
|
// FIXME: use all the config vars
|
|
|
}
|