Skip to content

Commit 3d388b0

Browse files
arschlesAaron Schlesinger
authored andcommitted
feat(builder.go): porting more code over
1 parent 4b26336 commit 3d388b0

1 file changed

Lines changed: 60 additions & 2 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,16 @@ func build(conf *Config, newRev string) error {
232232
// sed -i -- "s#puturl#$PUSH_URL#g" /etc/${SLUG_NAME}.yaml
233233
// sed -i -- "s#tar-url#$TAR_URL#g" /etc/${SLUG_NAME}.yaml
234234
finalManifestFileName := fmt.Sprintf("/etc/%s", slugName)
235+
var buildPodName string
235236
var finalManifest string
236237
if usingDockerfile {
237-
finalManifest = strings.Replace(string(fileBytes), "repo_name", fmt.Sprintf("%s-%s", tmpImage, uuid.New()))
238+
buildPodName = fmt.Sprintf("%s-%s", tmpImage, uuid.New())
239+
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName)
238240
finalManifest = strings.Replace(finalManifest, "puturl", pushURL)
239241
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL)
240242
} else {
241-
finalManifest = strings.Replace(string(fileBytes), "repo_name", fmt.Sprintf("%s-%s", slugName, uuid.New()))
243+
buildPodName = fmt.Sprintf("%s-%s", slugName, uuid.New())
244+
finalManifest = strings.Replace(string(fileBytes), "repo_name", buildPodName)
242245
finalManifest = strings.Replace(finalManifest, "puturl", pushURL)
243246
finalManifest = strings.Replace(finalManifest, "tar-url", tarURL)
244247
}
@@ -342,6 +345,45 @@ func build(conf *Config, newRev string) error {
342345
// sleep 0.1
343346
// done
344347
// kubectl --namespace=${POD_NAMESPACE} logs -f ${META_NAME} 2>/dev/null &
348+
349+
// poll kubectl every 100ms to determine when the build pod is running
350+
// TODO: use the k8s client and watch the event stream instead (https://github.com/deis/builder/issues/65)
351+
getCmd := exec.Command(
352+
"kubectl",
353+
fmt.Sprintf("--namespace=%s", conf.PodNamespace),
354+
fmt.SPrintf("get"),
355+
fmt.SPrintf("pods"),
356+
"-o",
357+
"yaml",
358+
buildPodName,
359+
)
360+
for {
361+
var out bytes.Buffer
362+
getCmd.Stdout = out
363+
if err := getCmd.Run(); err != nil {
364+
log.Err("running %s while determining if builder pod %s is running (%s)", buildPodName, err)
365+
os.Exit(1)
366+
}
367+
if strings.Contains(string(out.Bytes()), "phase: Running") {
368+
break
369+
}
370+
time.Sleep(100 * time.Millisecond)
371+
}
372+
373+
// get logs from the builder pod
374+
logsCmd := exec.Command(
375+
"kubectl",
376+
fmt.Sprintf("--namespace=%s", conf.PodNamespace),
377+
"logs",
378+
"-f",
379+
buildPodName,
380+
)
381+
logsCmd.Stdout = os.Stdout
382+
if err := logsCmd.Run(); err != nil {
383+
log.Err("running %s to get builder logs (%s)", strings.Join(logsCmd.Args), err)
384+
os.Exit(1)
385+
}
386+
345387
//
346388
// #check for image creation or slug existence in S3EP
347389
//
@@ -358,12 +400,28 @@ func build(conf *Config, newRev string) error {
358400
// sleep 2
359401
// done
360402
// fi
403+
404+
// poll the s3 server to ensure the slug exists
405+
lsCmd := baseMinioCmd
406+
lsCmd.Args = append(lsCmd.Args, "ls", pushURL)
407+
for {
408+
// for now, assume the error indicates that the slug wasn't there, nothing else
409+
// TODO: implement https://github.com/deis/builder/issues/80, which will clean this up siginficantly
410+
if err := lsCmd.Run(); err == nil {
411+
break
412+
}
413+
}
414+
361415
//
362416
// # build completed
363417
//
364418
// puts-step "Build complete."
365419
// puts-step "Launching app."
366420
//
421+
422+
log.Info("Build complete.")
423+
log.Info("Launching app.")
424+
367425
// URL="http://$DEIS_WORKFLOW_SERVICE_HOST:$DEIS_WORKFLOW_SERVICE_PORT/v2/hooks/config"
368426
// RESPONSE=$(get-app-config -url="$URL" -key="{{ getv "/deis/controller/builderKey" }}" -user=$USER -app=$APP_NAME)
369427
// CODE=$?

0 commit comments

Comments
 (0)