Skip to content

Commit

Permalink
parse emty multiply options
Browse files Browse the repository at this point in the history
  • Loading branch information
foosinn committed Apr 29, 2019
1 parent abc81a2 commit 8bb5884
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The `puppet` and the `python` image are build as they are. The php image will ge

**NOTE**: For values in `multiply`, `append`, and `namespace` one may choose to use environment variables. Substition is handled by [drone/envsubst](https://github.com/drone/envsubst)

The `multiply` can have an empty string as field. This wont be added to the images tag. Useful for default options. You can use Bash Syntax to use a default value instead: `echo ${MESSAGE}:-default`.

```yaml
# docker-matrix.yml
Expand All @@ -56,6 +57,9 @@ multiply:
OS:
- alpine
- debian
COMMAND:
- sleep 1y
- ""

append:
- { NAME: test, LANG: ${LANG} }
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ ARGUMENTS:
tag = "latest"
}
for _, key := range keyOrder {
tag = fmt.Sprintf("%s-%s", tag, scenario[key])
t := scenario[key]
if t == "" {
log.Debugf("%s skipping empty tag in name for %s", id, key)
continue
}
tag = fmt.Sprintf("%s-%s", tag, t)
}
if tag[0:1] == "-" {
tag = tag[1:]
Expand Down
12 changes: 10 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func TestBuild(t *testing.T) {
}
})

want := `build busybox -t localhost:5000/images/busybox:latest -t localhost:5000/images/busybox:7
want := `
build alpine --build-arg MESSAGE=multiply -t localhost:5000/images/alpine:multiply -t localhost:5000/images/alpine:multiply-7
build alpine --build-arg MESSAGE= -t localhost:5000/images/alpine:latest -t localhost:5000/images/alpine:7
build busybox -t localhost:5000/images/busybox:latest -t localhost:5000/images/busybox:7
build php --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
build php --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
build php --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
Expand All @@ -59,8 +62,12 @@ push docker.io/bitsbeats/image2:7.3-alpine-test
push docker.io/bitsbeats/image2:7.3-alpine-test-7
push docker.io/bitsbeats/image2:7.3-debian-test
push docker.io/bitsbeats/image2:7.3-debian-test-7
push localhost:5000/images/busybox:latest
push localhost:5000/images/alpine:7
push localhost:5000/images/alpine:latest
push localhost:5000/images/alpine:multiply
push localhost:5000/images/alpine:multiply-7
push localhost:5000/images/busybox:7
push localhost:5000/images/busybox:latest
push localhost:5000/images/php:7.2-alpine-test
push localhost:5000/images/php:7.2-alpine-test-7
push localhost:5000/images/php:7.2-debian-test
Expand All @@ -78,6 +85,7 @@ push localhost:5000/images/python:3.6-alpine-7
push localhost:5000/images/python:3.6-stretch
push localhost:5000/images/python:3.6-stretch-7
`
want = want [1:]

wantList := strings.Split(want, "\n")
gotList := strings.Split(got, "\n")
Expand Down
3 changes: 3 additions & 0 deletions testdata/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine
ARG MESSAGE="World"
RUN echo Hello ${MESSAGE:-default}
4 changes: 4 additions & 0 deletions testdata/alpine/docker-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
multiply:
MESSAGE:
- multiply
- ""

0 comments on commit 8bb5884

Please sign in to comment.