Skip to content

Commit 270da2d

Browse files
authored
Merge pull request #386 from milas/fix-dockerfile-inline
2 parents 1af0f42 + 95ef165 commit 270da2d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (s set) toSlice() []string {
296296
type BuildConfig struct {
297297
Context string `yaml:",omitempty" json:"context,omitempty"`
298298
Dockerfile string `yaml:",omitempty" json:"dockerfile,omitempty"`
299-
DockerfileInline string `yaml:",omitempty" json:"dockerfile_inline,omitempty"`
299+
DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"`
300300
Args MappingWithEquals `yaml:",omitempty" json:"args,omitempty"`
301301
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
302302
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`

types/types_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package types
1818

1919
import (
20+
"bytes"
2021
"encoding/json"
22+
"fmt"
2123
"strings"
2224
"testing"
2325

@@ -329,3 +331,40 @@ func TestMarshalServiceEntrypoint(t *testing.T) {
329331
}
330332

331333
}
334+
335+
func TestMarshalBuild_DockerfileInline(t *testing.T) {
336+
b := BuildConfig{
337+
DockerfileInline: "FROM alpine\n\n# echo the env\nRUN env\n\nENTRYPOINT /bin/echo\n",
338+
}
339+
out, err := yaml.Marshal(b)
340+
assert.NilError(t, err)
341+
342+
const expected = `
343+
dockerfile_inline: |
344+
FROM alpine
345+
346+
# echo the env
347+
RUN env
348+
349+
ENTRYPOINT /bin/echo
350+
`
351+
assert.Check(t, equalTrimSpace(out, expected))
352+
353+
// round-trip
354+
var b2 BuildConfig
355+
assert.NilError(t, yaml.Unmarshal(out, &b2))
356+
assert.Check(t, equalTrimSpace(b.DockerfileInline, b2.DockerfileInline))
357+
}
358+
359+
func equalTrimSpace(x interface{}, y interface{}) is.Comparison {
360+
trim := func(v interface{}) interface{} {
361+
switch vv := v.(type) {
362+
case string:
363+
return strings.TrimSpace(vv)
364+
case []byte:
365+
return string(bytes.TrimSpace(vv))
366+
}
367+
panic(fmt.Errorf("invalid type %T (value: %+v)", v, v))
368+
}
369+
return is.DeepEqual(trim(x), trim(y))
370+
}

0 commit comments

Comments
 (0)