Skip to content

Commit 3239c3f

Browse files
committed
when DockerImageSpec.DockerfilePath points to subdir, use subdir as build ctx
1 parent 030af35 commit 3239c3f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cmd/bob/build.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"os/exec"
8+
"path/filepath"
89
"strings"
910

1011
"github.com/function61/gokit/os/osutil"
@@ -88,6 +89,11 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
8889
tagLatest := tagWithoutVersion + ":latest"
8990
dockerfilePath := dockerImage.DockerfilePath
9091

92+
// "" => "."
93+
// "Dockerfile" => "."
94+
// "subdir/Dockerfile" => "subdir"
95+
buildContextDir := filepath.Dir(dockerfilePath)
96+
9197
printHeading(fmt.Sprintf("Building %s", tag))
9298

9399
// use buildx when platforms set. it's almost same as "$ docker build" but it almost transparently
@@ -108,7 +114,7 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
108114
args = append(args, "--tag="+tagLatest)
109115
}
110116

111-
args = append(args, ".") // build context
117+
args = append(args, buildContextDir)
112118

113119
if buildCtx.PublishArtefacts {
114120
// the build command has integrated push support. we'd actually prefer to separate
@@ -126,7 +132,7 @@ func buildAndPushOneDockerImage(dockerImage DockerImageSpec, buildCtx *BuildCont
126132
"--file", dockerfilePath,
127133
"--tag", tag,
128134
"--label=org.opencontainers.image.revision="+buildCtx.RevisionId.RevisionId,
129-
"."))
135+
buildContextDir))
130136

131137
if err := buildCmd.Run(); err != nil {
132138
return err

0 commit comments

Comments
 (0)