-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show detect Termui screen during detect phase
Signed-off-by: Anthony Emengo <aemengo@vmware.com>
- Loading branch information
Anthony Emengo
committed
Aug 9, 2021
1 parent
66a4f32
commit 81d6203
Showing
32 changed files
with
908 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
===> DETECTING | ||
3 of 6 buildpacks participating | ||
paketo-buildpacks/ca-certificates 2.3.2 | ||
paketo-buildpacks/go-dist 0.5.2 | ||
paketo-buildpacks/go-build 0.4.0 | ||
===> ANALYZING | ||
Previous image with name "test" not found | ||
===> RESTORING | ||
===> BUILDING | ||
|
||
Paketo CA Certificates Buildpack 2.3.2 | ||
https://github.com/paketo-buildpacks/ca-certificates | ||
Launch Helper: Contributing to layer | ||
Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper | ||
Paketo Go Distribution Buildpack 0.5.2 | ||
Resolving Go version | ||
Candidate version sources (in priority order): | ||
<unknown> -> "" | ||
|
||
Selected Go version (using <unknown>): 1.16.6 | ||
|
||
Executing build process | ||
Installing Go 1.16.6 | ||
Completed in 6.422s | ||
|
||
Paketo Go Build Buildpack 0.4.0 | ||
Executing build process | ||
Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie .' | ||
Completed in 6.21s | ||
|
||
Assigning launch processes: | ||
web: /layers/paketo-buildpacks_go-build/targets/bin/workspace | ||
workspace: /layers/paketo-buildpacks_go-build/targets/bin/workspace | ||
|
||
===> EXPORTING | ||
Adding layer 'paketo-buildpacks/ca-certificates:helper' | ||
Adding layer 'paketo-buildpacks/go-build:targets' | ||
Adding 1/1 app layer(s) | ||
Adding layer 'launcher' | ||
Adding layer 'config' | ||
Adding layer 'process-types' | ||
Adding label 'io.buildpacks.lifecycle.metadata' | ||
Adding label 'io.buildpacks.build.metadata' | ||
Adding label 'io.buildpacks.project.metadata' | ||
Setting default process type 'web' | ||
Saving test... | ||
*** Images (00a70b0025d8): | ||
test | ||
Adding cache layer 'paketo-buildpacks/go-dist:go' | ||
Adding cache layer 'paketo-buildpacks/go-build:gocache' | ||
Successfully built image 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/buildpacks/pack/internal/termui" | ||
) | ||
|
||
func main() { | ||
command := exec.Command(os.Args[1], os.Args[2:]...) | ||
|
||
reader, err := start(command) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = command.Start() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = handleOutput(reader) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = command.Wait() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log(termui.NewEvent("EXPORT", "Ending")) | ||
os.Exit(command.ProcessState.ExitCode()) | ||
} | ||
|
||
func log(evt termui.Event) { | ||
data, _ := json.Marshal(evt) | ||
fmt.Println(string(data)) | ||
} | ||
|
||
func handleOutput(reader io.Reader) error { | ||
scanner := bufio.NewScanner(reader) | ||
|
||
for scanner.Scan() { | ||
text := scanner.Text() | ||
|
||
switch { | ||
case strings.Contains(text, "===> DETECTING"): | ||
log(termui.NewEvent("DETECT", "Starting")) | ||
case strings.Contains(text, "===> ANALYZING"): | ||
log(termui.NewEvent("DETECT", "Ending")) | ||
log(termui.NewEvent("ANALYZE", "Starting")) | ||
} | ||
} | ||
|
||
return scanner.Err() | ||
} | ||
|
||
func start(command *exec.Cmd) (io.Reader, error) { | ||
stdout, err := command.StdoutPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stderr, err := command.StderrPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reader := io.MultiReader(stdout, stderr) | ||
return reader, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main_test | ||
|
||
import ( | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
h "github.com/buildpacks/pack/testhelpers" | ||
) | ||
|
||
func TestPackAgent(t *testing.T) { | ||
binaryPath := h.BuildPackAgent(t) | ||
|
||
spec.Run(t, "PackAgent", func(t *testing.T, g spec.G, s spec.S) { | ||
testPackAgent(t, g, s, binaryPath) | ||
}, spec.Report(report.Terminal{})) | ||
} | ||
|
||
func testPackAgent(t *testing.T, when spec.G, it spec.S, packAgentPath string) { | ||
var ( | ||
assert = h.NewAssertionManager(t) | ||
) | ||
|
||
when("PackAgent", func() { | ||
it("translates lifecycle output to JSON", func() { | ||
args := []string{"cat", filepath.Join("fixtures", "fake_lifecycle_build.txt")} | ||
if runtime.GOOS == "windows" { | ||
args = append([]string{"powershell.exe", "-Command"}, args...) | ||
} | ||
|
||
command := exec.Command(packAgentPath, args...) | ||
output, err := command.CombinedOutput() | ||
assert.NilWithMessage(err, string(output)) | ||
|
||
assert.ContainsAll(string(output), | ||
`{"phase":"DETECT","msg":"Starting"`, | ||
`{"phase":"DETECT","msg":"Ending"`, | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.