Skip to content

Commit

Permalink
add buildImage by daemon
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Kumar <[email protected]>
  • Loading branch information
itsdarshankumar committed Jun 2, 2023
1 parent ca07b65 commit abdf62c
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package build
import (
"context"
"fmt"
"io"

"math/rand"
"os"
"path/filepath"
"strconv"
"time"

"github.com/BurntSushi/toml"

"github.com/buildpacks/pack/pkg/cache"

// "github.com/buildpacks/pack/pkg/archive"
"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/auth"
"github.com/docker/docker/api/types"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/pkg/errors"
Expand All @@ -24,6 +25,7 @@ import (
"github.com/buildpacks/pack/internal/builder"
"github.com/buildpacks/pack/internal/paths"
"github.com/buildpacks/pack/internal/style"
"github.com/buildpacks/pack/pkg/archive"
"github.com/buildpacks/pack/pkg/logging"
)

Expand Down Expand Up @@ -258,11 +260,10 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
} else {
group.Go(func() error {
l.logger.Info(style.Step("EXTENDING (RUN) BY DAEMON"))
return l.ExtendRunByDaemon(ctx)
return l.ExtendRunByDaemon(ctx, &currentRunImage)
})
}
}

if err := group.Wait(); err != nil {
return err
}
Expand Down Expand Up @@ -721,9 +722,10 @@ func (l *LifecycleExecution) ExtendRun(ctx context.Context, buildCache Cache, ph
return extend.Run(ctx)
}

func (l *LifecycleExecution) ExtendRunByDaemon(ctx context.Context) error {
func (l *LifecycleExecution) ExtendRunByDaemon(ctx context.Context, currentRunImage *string) error {
defaultFilterFunc := func(file string) bool { return true }
var extensions Extensions
l.logger.Debugf("extending run image %s", l.opts.RunImage)
l.logger.Debugf("extending run image %s", *currentRunImage)
fmt.Println("tmpDir: ", l.tmpDir)
extensions.SetExtensions(l.tmpDir, l.logger)
dockerfiles, err := extensions.DockerFiles(DockerfileKindRun, l.tmpDir, l.logger)
Expand All @@ -732,9 +734,36 @@ func (l *LifecycleExecution) ExtendRunByDaemon(ctx context.Context) error {
}
fmt.Println("Dockerfiles: ", dockerfiles)
fmt.Println("extend: ", dockerfiles[1].Extend)
time.Sleep(10 * time.Minute)
for _, dockerfile := range dockerfiles {
if dockerfile.Extend {
fmt.Println("dockerfile: ", dockerfile)
fmt.Println("dockerfile.Path dir: ", filepath.Dir(dockerfile.Path))
buildContext := archive.ReadDirAsTar(filepath.Dir(dockerfile.Path), "/", 0, 0, -1, true, false, defaultFilterFunc)
fmt.Println("buildContext: ", buildContext)
buildArguments := map[string]*string{}
if dockerfile.WithBase == "" {
buildArguments["base_image"] = currentRunImage
}
buildOptions := types.ImageBuildOptions{
Context: buildContext,
Dockerfile: "Dockerfile",
Tags: []string{"run-image"},
Remove: true,
BuildArgs: buildArguments,
}
response, err := l.docker.ImageBuild(ctx, buildContext, buildOptions)
if err != nil {
return err
}
defer response.Body.Close()
_, err = io.Copy(os.Stdout, response.Body)
if err != nil {
return err
}
l.logger.Debugf("build response for the extend: %v", response)
}
}
return nil
// buildContest := archive.ReadDirAsTar(filepath.Join(l.tmpDir,"generated","run"),"/",0,0,-1,true,false)
}

func determineDefaultProcessType(platformAPI *api.Version, providedValue string) string {
Expand Down

0 comments on commit abdf62c

Please sign in to comment.