Kaynağa Gözat

Merge pull request #1473 from porter-dev/use-docker-cache

use cache from remote registry
sunguroku 4 yıl önce
ebeveyn
işleme
544cee0495

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

@@ -29,6 +29,7 @@ func (b *BuildAgent) BuildDocker(
 	buildCtx,
 	dockerfilePath,
 	tag string,
+	currentTag string,
 ) error {
 	buildCtx, dockerfilePath, isDockerfileInCtx, err := ResolveDockerPaths(
 		basePath,
@@ -43,6 +44,7 @@ func (b *BuildAgent) BuildDocker(
 	opts := &docker.BuildOpts{
 		ImageRepo:         b.imageRepo,
 		Tag:               tag,
+		CurrentTag:        currentTag,
 		BuildContext:      buildCtx,
 		Env:               b.env,
 		DockerfilePath:    dockerfilePath,

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

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

+ 6 - 3
cli/cmd/deploy/deploy.go

@@ -238,10 +238,12 @@ func (d *DeployAgent) Build() error {
 		}
 	}
 
-	if d.tag == "" {
-		currImageSection := d.release.Config["image"].(map[string]interface{})
+	// retrieve current image to use for cache
+	currImageSection := d.release.Config["image"].(map[string]interface{})
+	currentTag := currImageSection["tag"].(string)
 
-		d.tag = currImageSection["tag"].(string)
+	if d.tag == "" {
+		d.tag = currentTag
 	}
 
 	err = d.pullCurrentReleaseImage()
@@ -269,6 +271,7 @@ func (d *DeployAgent) Build() error {
 			buildCtx,
 			d.dockerfilePath,
 			d.tag,
+			currentTag,
 		)
 	}
 

+ 4 - 0
cli/cmd/docker/builder.go

@@ -21,6 +21,7 @@ import (
 type BuildOpts struct {
 	ImageRepo         string
 	Tag               string
+	CurrentTag        string
 	BuildContext      string
 	DockerfilePath    string
 	IsDockerfileInCtx bool
@@ -67,6 +68,9 @@ func (a *Agent) BuildLocal(opts *BuildOpts) error {
 		Tags: []string{
 			fmt.Sprintf("%s:%s", opts.ImageRepo, opts.Tag),
 		},
+		CacheFrom: []string{
+			fmt.Sprintf("%s:%s", opts.ImageRepo, opts.CurrentTag),
+		},
 		Remove: true,
 	})