Skip to content

Commit

Permalink
add setEnv()
Browse files Browse the repository at this point in the history
Signed-off-by: edithwuly <edithwuly@163.com>
  • Loading branch information
edithwuly committed Apr 27, 2023
1 parent 14d541a commit 1fb39b1
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions benchmarks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"path/filepath"
"testing"
"os"

dockerCli "github.com/docker/docker/client"
"github.com/pkg/errors"
Expand All @@ -21,15 +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")
paketoBuilder = "paketobuildpacks/builder:base"
additionalBuildapck = "docker://cnbs/sample-package:hello-universe"
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 @@ -96,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 1fb39b1

Please sign in to comment.