Explorar el Código

support dockerfile option for source github

Alexander Belanger hace 4 años
padre
commit
fea32675fc
Se han modificado 2 ficheros con 16 adiciones y 5 borrados
  1. 2 2
      cli/cmd/deploy/build.go
  2. 14 3
      cli/cmd/deploy/deploy.go

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

@@ -20,11 +20,11 @@ type BuildAgent struct {
 }
 
 // BuildDocker uses the local Docker daemon to build the image
-func (b *BuildAgent) BuildDocker(dockerAgent *docker.Agent, dst, tag string) error {
+func (b *BuildAgent) BuildDocker(dockerAgent *docker.Agent, buildCtx, tag string) error {
 	opts := &docker.BuildOpts{
 		ImageRepo:    b.imageRepo,
 		Tag:          tag,
-		BuildContext: dst,
+		BuildContext: buildCtx,
 		Env:          b.env,
 	}
 

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

@@ -194,6 +194,7 @@ func (d *DeployAgent) WriteBuildEnv(fileDest string) error {
 func (d *DeployAgent) Build() error {
 	// if build is not local, fetch remote source
 	var dst string
+	var buildCtx string
 	var err error
 
 	if !d.opts.Local {
@@ -222,10 +223,11 @@ func (d *DeployAgent) Build() error {
 		// if the local path is set it must be a relative path, so create a filepath with the dst
 		// and the relative path
 		if d.opts.LocalPath != "" {
-			dst = filepath.Join(dst, d.opts.LocalPath)
+			buildCtx = filepath.Join(dst, d.opts.LocalPath)
 		}
 	} else {
 		dst = filepath.Dir(d.opts.LocalPath)
+		buildCtx = filepath.Dir(d.opts.LocalPath)
 	}
 
 	if d.tag == "" {
@@ -253,10 +255,19 @@ func (d *DeployAgent) Build() error {
 	}
 
 	if d.opts.Method == DeployBuildTypeDocker {
-		return buildAgent.BuildDocker(d.agent, dst, d.tag)
+		var dockerfilePath string
+
+		// if the dockerfile path is set it must also be a relative path
+		if !d.opts.Local && d.dockerfilePath != "" {
+			dockerfilePath = filepath.Join(dst, d.dockerfilePath)
+		}
+
+		buildAgent.SharedOpts.LocalDockerfile = dockerfilePath
+
+		return buildAgent.BuildDocker(d.agent, buildCtx, d.tag)
 	}
 
-	return buildAgent.BuildPack(d.agent, dst, d.tag)
+	return buildAgent.BuildPack(d.agent, buildCtx, d.tag)
 }
 
 // Push pushes a local image to the remote repository linked in the release