Skip to content

Commit

Permalink
Merge pull request #1736 from edithwuly/main
Browse files Browse the repository at this point in the history
Create benchmark.yml and add end-to-end benchmark
  • Loading branch information
jkutner authored Apr 27, 2023
2 parents 5e5a437 + b512496 commit 12bc0e2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: benchmark
on:
push:
branches:
- main

permissions:
contents: write
deployments: write

jobs:
benchmark:
name: Run Go benchmark example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up go
uses: actions/setup-go@v4
with:
go-version: "1.19"
- name: Set up go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Run benchmark
run: |
mkdir out || (exit 0)
go test -bench=. -benchtime=1s ./benchmarks/... -tags=benchmarks | tee ./out/benchmark.txt
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: 'go'
output-file-path: ./out/benchmark.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@edithwuly'
41 changes: 37 additions & 4 deletions benchmarks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package benchmarks
import (
"bytes"
"fmt"
"os"
"path/filepath"
"testing"

Expand All @@ -21,13 +22,16 @@ import (
)

var (
baseImg = "some-org/" + h.RandString(10)
trustedImg = baseImg + "-trusted-"
builder = "cnbs/sample-builder:bionic"
mockAppPath = filepath.Join("..", "acceptance", "testdata", "mock_app")
baseImg string
trustedImg string
builder string
mockAppPath string
paketoBuilder string
additionalBuildapck string
)

func BenchmarkBuild(b *testing.B) {
setEnv()
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithVersion("1.38"))
if err != nil {
b.Error(errors.Wrap(err, "creating docker client"))
Expand Down Expand Up @@ -59,6 +63,16 @@ func BenchmarkBuild(b *testing.B) {
}
})

b.Run("with Addtional Buildpack", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// perform the operation we're analyzing
cmd.SetArgs([]string{fmt.Sprintf("%s%d", trustedImg, i), "-p", mockAppPath, "-B", paketoBuilder, "--buildpack", additionalBuildapck})
if err = cmd.Execute(); err != nil {
b.Error(errors.Wrapf(err, "running build #%d", i))
}
}
})

// Cleanup
for i := 0; i < b.N; i++ {
if err = h.DockerRmi(dockerClient, fmt.Sprintf("%s%d", baseImg, i)); err != nil {
Expand All @@ -84,3 +98,22 @@ func createCmd(b *testing.B, docker *dockerCli.Client) *cobra.Command {
}
return commands.Build(logger, cfg.Config{}, packClient)
}

func setEnv() {
if baseImg = os.Getenv("baseImg"); baseImg == "" {
baseImg = "some-org/" + h.RandString(10)
}
trustedImg = baseImg + "-trusted-"
if builder = os.Getenv("builder"); builder == "" {
builder = "cnbs/sample-builder:bionic"
}
if mockAppPath = os.Getenv("mockAppPath"); mockAppPath == "" {
mockAppPath = filepath.Join("..", "acceptance", "testdata", "mock_app")
}
if paketoBuilder = os.Getenv("paketoBuilder"); paketoBuilder == "" {
paketoBuilder = "paketobuildpacks/builder:base"
}
if additionalBuildapck = os.Getenv("additionalBuildapck"); additionalBuildapck == "" {
additionalBuildapck = "docker://cnbs/sample-package:hello-universe"
}
}

0 comments on commit 12bc0e2

Please sign in to comment.