func ResolveDockerPaths(
	basePath string,
	buildContextPath string,
	dockerfilePath string,
) (
	resBuildCtxPath string,
	resDockerfilePath string,
	isDockerfileRelative bool,
	err error,
) {
	resBuildCtxPath, err = filepath.Abs(buildContextPath)
	resDockerfilePath = dockerfilePath
	if !filepath.IsAbs(dockerfilePath) {
		resDockerfilePath = filepath.Join(basePath, dockerfilePath)
	}
	pathComp, err := filepath.Rel(resBuildCtxPath, resDockerfilePath)
	if err != nil {
		return "", "", false, err
	}
	if !strings.HasPrefix(pathComp, ".."+string(os.PathSeparator)) {
		return resBuildCtxPath, pathComp, true, nil
	}
	resDockerfilePath, err = filepath.Abs(resDockerfilePath)
	if err != nil {
		return "", "", false, err
	}
	return resBuildCtxPath, resDockerfilePath, false, nil
}
ResolveDockerPaths returns a path to the dockerfile that is either relative or absolute, and a path
to the build context that is absolute.

The return value will be relative if the dockerfile exists within the build context, absolute
otherwise. The second return value is true if the dockerfile exists within the build context,
false otherwise.
package deploy
import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	api "github.com/porter-dev/porter/api/client"
	"github.com/porter-dev/porter/cli/cmd/docker"
	"github.com/porter-dev/porter/cli/cmd/pack"
)
type BuildAgent struct {
	*SharedOpts
	client      *api.Client
	imageRepo   string
	env         map[string]string
	imageExists bool
}
func (b *BuildAgent) BuildDocker(
	dockerAgent *docker.Agent,
	basePath,
	buildCtx,
	dockerfilePath,
	tag string,
) error {
	buildCtx, dockerfilePath, isDockerfileInCtx, err := ResolveDockerPaths(
		basePath,
		buildCtx,
		dockerfilePath,
	)
	if err != nil {
		return err
	}
	opts := &docker.BuildOpts{
		ImageRepo:         b.imageRepo,
		Tag:               tag,
		BuildContext:      buildCtx,
		Env:               b.env,
		DockerfilePath:    dockerfilePath,
		IsDockerfileInCtx: isDockerfileInCtx,
	}
	return dockerAgent.BuildLocal(
		opts,
	)
}
func (b *BuildAgent) BuildPack(dockerAgent *docker.Agent, dst, tag string) error {
	if b.imageExists {
		err := dockerAgent.TagImage(
			fmt.Sprintf("%s:%s", b.imageRepo, tag),
			fmt.Sprintf("%s:%s", b.imageRepo, "pack-cache"),
		)
		if err != nil {
			return err
		}
	}
	packAgent := &pack.Agent{}
	opts := &docker.BuildOpts{
		ImageRepo: b.imageRepo,
		Tag:          "pack-cache",
		BuildContext: dst,
		Env:          b.env,
	}
	err := packAgent.Build(opts)
	if err != nil {
		return err
	}
	return dockerAgent.TagImage(
		fmt.Sprintf("%s:%s", b.imageRepo, "pack-cache"),
		fmt.Sprintf("%s:%s", b.imageRepo, tag),
	)
}