Skip to content

Commit 27bff95

Browse files
committed
output image build and healthcheck improvements
Signed-off-by: Kyle Quest <[email protected]>
1 parent 1e5f957 commit 27bff95

File tree

4 files changed

+97
-19
lines changed

4 files changed

+97
-19
lines changed

pkg/app/master/command/build/image.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,39 @@ func UpdateBuildOptionsWithSrcImageInfo(
640640
options.ImageConfig.Config.OnBuild = imageInfo.Config.OnBuild
641641
options.ImageConfig.Config.StopSignal = imageInfo.Config.StopSignal
642642

643+
options.ImageConfig.Config.ArgsEscaped = imageInfo.Config.ArgsEscaped
644+
options.ImageConfig.Config.Domainname = imageInfo.Config.Domainname
645+
options.ImageConfig.Config.Hostname = imageInfo.Config.Hostname
646+
if imageInfo.Config.StopTimeout > 0 {
647+
options.ImageConfig.Config.StopTimeout = &imageInfo.Config.StopTimeout
648+
}
649+
options.ImageConfig.Config.AttachStderr = imageInfo.Config.AttachStderr
650+
options.ImageConfig.Config.AttachStdin = imageInfo.Config.AttachStdin
651+
options.ImageConfig.Config.AttachStdout = imageInfo.Config.AttachStdout
652+
options.ImageConfig.Config.OpenStdin = imageInfo.Config.OpenStdin
653+
options.ImageConfig.Config.StdinOnce = imageInfo.Config.StdinOnce
654+
options.ImageConfig.Config.Tty = imageInfo.Config.Tty
655+
options.ImageConfig.Config.NetworkDisabled = imageInfo.Config.NetworkDisabled
656+
options.ImageConfig.Config.MacAddress = imageInfo.Config.MacAddress
657+
658+
if len(imageInfo.Config.Shell) > 0 {
659+
options.ImageConfig.Config.Shell = imageInfo.Config.Shell
660+
}
661+
if len(imageInfo.Config.OnBuild) > 0 {
662+
options.ImageConfig.Config.OnBuild = imageInfo.Config.OnBuild
663+
}
664+
665+
if imageInfo.Config.Healthcheck != nil {
666+
hc := imageInfo.Config.Healthcheck
667+
options.ImageConfig.Config.Healthcheck = &imagebuilder.HealthConfig{
668+
Test: hc.Test,
669+
Interval: hc.Interval,
670+
Timeout: hc.Timeout,
671+
StartPeriod: hc.StartPeriod,
672+
Retries: hc.Retries,
673+
}
674+
}
675+
643676
for k, v := range imageInfo.Config.ExposedPorts {
644677
options.ImageConfig.Config.ExposedPorts[string(k)] = v
645678
}

pkg/app/sensor/artifact/artifact.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,13 @@ func (p *store) prepareArtifact(artifactFileName string) {
737737

738738
case srcLinkFileInfo.Mode().IsDir():
739739
log.Debugf("prepareArtifact - is a directory (%d) - %v", len(p.dirMap)+1, artifactFileName)
740-
props.FileType = report.DirArtifactType
741-
p.dirMap[artifactFileName] = props
742-
p.rawNames[artifactFileName] = props
740+
if artifactFileName != "/" {
741+
props.FileType = report.DirArtifactType
742+
p.dirMap[artifactFileName] = props
743+
p.rawNames[artifactFileName] = props
744+
} else {
745+
log.Debug("prepareArtifact - not adding the / directory")
746+
}
743747
default:
744748
log.Debugf("prepareArtifact - other type (%d) [shouldn't see it] - %v", len(p.otherMap)+1, artifactFileName)
745749
p.otherMap[artifactFileName] = props

pkg/docker/dockerfile/reverse/reverse.go

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,20 @@ func deserialiseHealtheckInstruction(data string) (string, *docker.HealthConfig,
759759
}
760760
}
761761

762+
//new param
763+
if strings.Contains(cleanInst, "--start-interval=") {
764+
vparts := strings.SplitN(cleanInst, "--start-interval=", 2)
765+
vparts = strings.SplitN(vparts[1], " ", 2)
766+
val, err := time.ParseDuration(vparts[0])
767+
log.Debugf("[%s] config.StartInterval %v / error = %v", vparts[0], val, err)
768+
/*
769+
config.StartInterval, err = time.ParseDuration(vparts[0])
770+
if err != nil {
771+
log.Errorf("[%s] config.StartPeriod err = %v", vparts[0], err)
772+
}
773+
*/
774+
}
775+
762776
if strings.Contains(cleanInst, "--retries=") {
763777
vparts := strings.SplitN(cleanInst, "--retries=", 2)
764778
vparts = strings.SplitN(vparts[1], " ", 2)
@@ -817,17 +831,43 @@ func deserialiseHealtheckInstruction(data string) (string, *docker.HealthConfig,
817831
log.Errorf("[%s] config.StartPeriod err = %v", paramParts[2], err)
818832
}
819833

834+
//might have two params
835+
var rawStartInterval string
836+
var rawRetries string
837+
if strings.Contains(paramParts[3], " ") {
838+
pparts := strings.SplitN(paramParts[3], " ", 2)
839+
for i, p := range pparts {
840+
pparts[i] = strings.Trim(p, "\"'")
841+
}
842+
rawStartInterval = pparts[0]
843+
rawRetries = pparts[1]
844+
} else {
845+
rawRetries = paramParts[3]
846+
}
847+
848+
//new param
849+
if rawStartInterval != "" {
850+
var startInterval time.Duration
851+
//config.StartInterval
852+
startInterval, err = time.ParseDuration(rawStartInterval)
853+
if err != nil {
854+
log.Errorf("[%s] [np] config.StartInterval err = %v", rawStartInterval, err)
855+
}
856+
857+
log.Debugf("[%s] config.StartInterval %v", rawStartInterval, startInterval)
858+
}
859+
820860
var retries int64
821-
if strings.Index(paramParts[3], `\x`) != -1 {
861+
if strings.Index(rawRetries, `\x`) != -1 {
822862
// retries are hex encoded
823-
retries, err = strconv.ParseInt(strings.TrimPrefix(paramParts[3], `\x`), 16, 64)
824-
} else if strings.Index(paramParts[3], `\U`) != -1 {
863+
retries, err = strconv.ParseInt(strings.TrimPrefix(rawRetries, `\x`), 16, 64)
864+
} else if strings.Index(rawRetries, `\U`) != -1 {
825865
// retries are a unicode string
826-
retries, err = strconv.ParseInt(strings.TrimPrefix(paramParts[3], `\U`), 16, 64)
827-
} else if strings.Index(paramParts[3], `\`) == 0 {
866+
retries, err = strconv.ParseInt(strings.TrimPrefix(rawRetries, `\U`), 16, 64)
867+
} else if strings.Index(rawRetries, `\`) == 0 {
828868
// retries is printed as a C-escape
829-
if len(paramParts[3]) != 2 {
830-
err = fmt.Errorf("expected retries (%s) to be an escape sequence", paramParts[3])
869+
if len(rawRetries) != 2 {
870+
err = fmt.Errorf("expected retries (%s) to be an escape sequence", rawRetries)
831871
} else {
832872
escapeCodes := map[byte]int64{
833873
byte('a'): 7,
@@ -839,16 +879,16 @@ func deserialiseHealtheckInstruction(data string) (string, *docker.HealthConfig,
839879
byte('r'): 13,
840880
}
841881
var ok bool
842-
if retries, ok = escapeCodes[(paramParts[3])[1]]; !ok {
843-
err = fmt.Errorf("got an invalid escape sequence: %s", paramParts[3])
882+
if retries, ok = escapeCodes[(rawRetries)[1]]; !ok {
883+
err = fmt.Errorf("got an invalid escape sequence: %s", rawRetries)
844884
}
845885
}
846886
} else {
847-
retries = int64((paramParts[3])[0])
887+
retries = int64((rawRetries)[0])
848888
}
849889

850890
if err != nil {
851-
log.Errorf("[%s] config.Retries err = %v", paramParts[3], err)
891+
log.Errorf("[%s] config.Retries err = %v", rawRetries, err)
852892
} else {
853893
config.Retries = int(retries)
854894
}

pkg/imagebuilder/imagebuilder.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ type RunConfig struct {
8383
}
8484

8585
type HealthConfig struct {
86-
Test []string `json:",omitempty"`
87-
Interval time.Duration `json:",omitempty"`
88-
Timeout time.Duration `json:",omitempty"`
89-
StartPeriod time.Duration `json:",omitempty"`
90-
Retries int `json:",omitempty"`
86+
Test []string `json:",omitempty"`
87+
Interval time.Duration `json:",omitempty"`
88+
Timeout time.Duration `json:",omitempty"`
89+
StartPeriod time.Duration `json:",omitempty"`
90+
StartInterval time.Duration `json:",omitempty"`
91+
Retries int `json:",omitempty"`
9192
}
9293

9394
type SimpleBuildOptions struct {

0 commit comments

Comments
 (0)