pack.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package pack
  2. import (
  3. "context"
  4. "fmt"
  5. "path/filepath"
  6. "github.com/buildpacks/pack"
  7. "github.com/porter-dev/porter/api/types"
  8. "github.com/porter-dev/porter/cli/cmd/docker"
  9. )
  10. type Agent struct{}
  11. func (a *Agent) Build(opts *docker.BuildOpts, buildConfig *types.BuildConfig) error {
  12. //create a context object
  13. context := context.Background()
  14. //initialize a pack client
  15. client, err := pack.NewClient()
  16. if err != nil {
  17. return err
  18. }
  19. absPath, err := filepath.Abs(opts.BuildContext)
  20. if err != nil {
  21. return err
  22. }
  23. buildOpts := pack.BuildOptions{
  24. RelativeBaseDir: filepath.Dir(absPath),
  25. Image: fmt.Sprintf("%s:%s", opts.ImageRepo, opts.Tag),
  26. Builder: "paketobuildpacks/builder:full",
  27. AppPath: opts.BuildContext,
  28. TrustBuilder: true,
  29. Env: opts.Env,
  30. }
  31. if buildConfig != nil {
  32. buildOpts.Builder = buildConfig.Builder
  33. if len(buildConfig.Buildpacks) > 0 {
  34. buildOpts.Buildpacks = buildConfig.Buildpacks
  35. }
  36. // FIXME: use all the config vars
  37. }
  38. return client.Build(context, buildOpts)
  39. }