Skip to content

Commit d89c2e2

Browse files
committed
fix Dockerfile not relative to build path
1 parent 1949048 commit d89c2e2

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ func handleMatrix(name string, builds chan *build) {
220220
if tag == "" {
221221
tag = "latest"
222222
}
223+
dockerfile := filepath.Join(path, "Dockerfile")
223224
matrixWg.Add(1)
224225
b := build{
225226
ID: id,
226227
Namespace: c.DefaultNamespace,
227228
Name: name,
228229
Path: path,
229-
Dockerfile: "Dockerfile",
230+
Dockerfile: dockerfile,
230231
Tag: tag,
231232
Scenario: make(map[string]string),
232233
AdditionalNames: []string{},
@@ -251,6 +252,14 @@ func handleMatrix(name string, builds chan *build) {
251252
path = m.CustomPath
252253
}
253254

255+
// add directory to dockerfiles
256+
if m.CustomDockerfile == "" {
257+
m.CustomDockerfile = "Dockerfile"
258+
}
259+
if !strings.Contains(path, "://") {
260+
m.CustomDockerfile = filepath.Join(path, m.CustomDockerfile)
261+
}
262+
254263
// multiply options
255264
keyOrder := []string{}
256265
scenariosMatrix := []map[string]string{map[string]string{}}
@@ -416,11 +425,11 @@ func (b *build) tags() (combined []string) {
416425

417426
// build command argument
418427
func (b *build) args() []string {
419-
if b.Dockerfile == "" {
420-
b.Dockerfile = "Dockerfile"
428+
log.Warnf("%s Building %s from %s dockerfile:%s", b.ID, b.prettyName(), b.Path, b.Dockerfile)
429+
args := []string{"build", b.Path}
430+
if b.Dockerfile != "" {
431+
args = append(args, "-f", b.Dockerfile)
421432
}
422-
log.Warnf("%s Building %s from %s/%s", b.ID, b.prettyName(), b.Path, b.Dockerfile)
423-
args := []string{"build", b.Path, "-f", b.Dockerfile}
424433
for _, k := range b.KeyOrder {
425434
if b.Scenario[k] == "" {
426435
log.Infof("skipping empty build arg %s", k)

main_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ func TestBuild(t *testing.T) {
4040
})
4141

4242
want := `
43-
build alpine -f Dockerfile --build-arg MESSAGE=multiply -t localhost:5000/images/alpine:multiply -t localhost:5000/images/alpine:multiply-7
44-
build alpine -f Dockerfile -t localhost:5000/images/alpine:latest -t localhost:5000/images/alpine:7
45-
build busybox -f Dockerfile -t localhost:5000/images/busybox:latest -t localhost:5000/images/busybox:7
43+
build alpine -f alpine/Dockerfile --build-arg MESSAGE=multiply -t localhost:5000/images/alpine:multiply -t localhost:5000/images/alpine:multiply-7
44+
build alpine -f alpine/Dockerfile -t localhost:5000/images/alpine:latest -t localhost:5000/images/alpine:7
45+
build busybox -f busybox/Dockerfile -t localhost:5000/images/busybox:latest -t localhost:5000/images/busybox:7
4646
build https://github.com/openshift/origin-aggregated-logging.git#release-3.11:fluentd -f Dockerfile.centos7 -t localhost:5000/images/remote:latest -t localhost:5000/images/remote:7
47-
build php -f Dockerfile --build-arg VERSION=7.2 --build-arg OS=alpine --build-arg NAME=test -t docker.io/bitsbeats/image1:7.2-alpine-test -t docker.io/bitsbeats/image1:7.2-alpine-test-7 -t docker.io/bitsbeats/image2:7.2-alpine-test -t docker.io/bitsbeats/image2:7.2-alpine-test-7 -t localhost:5000/images/php:7.2-alpine-test -t localhost:5000/images/php:7.2-alpine-test-7
48-
build php -f Dockerfile --build-arg VERSION=7.2 --build-arg OS=debian --build-arg NAME=test -t docker.io/bitsbeats/image1:7.2-debian-test -t docker.io/bitsbeats/image1:7.2-debian-test-7 -t docker.io/bitsbeats/image2:7.2-debian-test -t docker.io/bitsbeats/image2:7.2-debian-test-7 -t localhost:5000/images/php:7.2-debian-test -t localhost:5000/images/php:7.2-debian-test-7
49-
build php -f Dockerfile --build-arg VERSION=7.3 --build-arg OS=alpine --build-arg NAME=test -t docker.io/bitsbeats/image1:7.3-alpine-test -t docker.io/bitsbeats/image1:7.3-alpine-test-7 -t docker.io/bitsbeats/image2:7.3-alpine-test -t docker.io/bitsbeats/image2:7.3-alpine-test-7 -t localhost:5000/images/php:7.3-alpine-test -t localhost:5000/images/php:7.3-alpine-test-7
50-
build php -f Dockerfile --build-arg VERSION=7.3 --build-arg OS=debian --build-arg NAME=test -t docker.io/bitsbeats/image1:7.3-debian-test -t docker.io/bitsbeats/image1:7.3-debian-test-7 -t docker.io/bitsbeats/image2:7.3-debian-test -t docker.io/bitsbeats/image2:7.3-debian-test-7 -t localhost:5000/images/php:7.3-debian-test -t localhost:5000/images/php:7.3-debian-test-7
51-
build python -f Dockerfile --build-arg VERSION=2.7 --build-arg OS=alpine -t localhost:5000/images/python:2.7-alpine -t localhost:5000/images/python:2.7-alpine-7
52-
build python -f Dockerfile --build-arg VERSION=2.7 --build-arg OS=stretch -t localhost:5000/images/python:2.7-stretch -t localhost:5000/images/python:2.7-stretch-7
53-
build python -f Dockerfile --build-arg VERSION=3.6 --build-arg OS=alpine -t localhost:5000/images/python:latest -t localhost:5000/images/python:3.6-alpine -t localhost:5000/images/python:3.6-alpine-7
54-
build python -f Dockerfile --build-arg VERSION=3.6 --build-arg OS=stretch -t localhost:5000/images/python:3.6-stretch -t localhost:5000/images/python:3.6-stretch-7
47+
build php -f php/Dockerfile --build-arg VERSION=7.2 --build-arg OS=alpine --build-arg NAME=test -t docker.io/bitsbeats/image1:7.2-alpine-test -t docker.io/bitsbeats/image1:7.2-alpine-test-7 -t docker.io/bitsbeats/image2:7.2-alpine-test -t docker.io/bitsbeats/image2:7.2-alpine-test-7 -t localhost:5000/images/php:7.2-alpine-test -t localhost:5000/images/php:7.2-alpine-test-7
48+
build php -f php/Dockerfile --build-arg VERSION=7.2 --build-arg OS=debian --build-arg NAME=test -t docker.io/bitsbeats/image1:7.2-debian-test -t docker.io/bitsbeats/image1:7.2-debian-test-7 -t docker.io/bitsbeats/image2:7.2-debian-test -t docker.io/bitsbeats/image2:7.2-debian-test-7 -t localhost:5000/images/php:7.2-debian-test -t localhost:5000/images/php:7.2-debian-test-7
49+
build php -f php/Dockerfile --build-arg VERSION=7.3 --build-arg OS=alpine --build-arg NAME=test -t docker.io/bitsbeats/image1:7.3-alpine-test -t docker.io/bitsbeats/image1:7.3-alpine-test-7 -t docker.io/bitsbeats/image2:7.3-alpine-test -t docker.io/bitsbeats/image2:7.3-alpine-test-7 -t localhost:5000/images/php:7.3-alpine-test -t localhost:5000/images/php:7.3-alpine-test-7
50+
build php -f php/Dockerfile --build-arg VERSION=7.3 --build-arg OS=debian --build-arg NAME=test -t docker.io/bitsbeats/image1:7.3-debian-test -t docker.io/bitsbeats/image1:7.3-debian-test-7 -t docker.io/bitsbeats/image2:7.3-debian-test -t docker.io/bitsbeats/image2:7.3-debian-test-7 -t localhost:5000/images/php:7.3-debian-test -t localhost:5000/images/php:7.3-debian-test-7
51+
build python -f python/Dockerfile --build-arg VERSION=2.7 --build-arg OS=alpine -t localhost:5000/images/python:2.7-alpine -t localhost:5000/images/python:2.7-alpine-7
52+
build python -f python/Dockerfile --build-arg VERSION=2.7 --build-arg OS=stretch -t localhost:5000/images/python:2.7-stretch -t localhost:5000/images/python:2.7-stretch-7
53+
build python -f python/Dockerfile --build-arg VERSION=3.6 --build-arg OS=alpine -t localhost:5000/images/python:latest -t localhost:5000/images/python:3.6-alpine -t localhost:5000/images/python:3.6-alpine-7
54+
build python -f python/Dockerfile --build-arg VERSION=3.6 --build-arg OS=stretch -t localhost:5000/images/python:3.6-stretch -t localhost:5000/images/python:3.6-stretch-7
5555
push docker.io/bitsbeats/image1:7.2-alpine-test
5656
push docker.io/bitsbeats/image1:7.2-alpine-test-7
5757
push docker.io/bitsbeats/image1:7.2-debian-test

testdata/python/docker-matrix.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ multiply:
22
VERSION:
33
- 2.7
44
- 3.6
5-
5+
66
OS:
77
- alpine
88
- stretch
99

1010
as_latest: 3.6-alpine
11+
custom_dockerfile: Dockerfile

0 commit comments

Comments
 (0)