Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,36 +177,20 @@ In either case, you will need the following tools:

* [`diffoci`](https://github.com/mzihlmann/diffoci#installation)

#### GCloud
#### Registry

To run integration tests with your GCloud Storage, you will also need the following tools:
To run integration tests against a real registry, you will need:

* [`gcloud`](https://cloud.google.com/sdk/install)
* [`gsutil`](https://cloud.google.com/storage/docs/gsutil_install)
* A bucket in [GCS](https://cloud.google.com/storage/) which you have write access to via
the user currently logged into `gcloud`
* An image repo which you have write access to via the user currently logged into `gcloud`
* An image repo which you have write access to
* A docker account and a `~/.docker/config.json` with login credentials if you run
into rate limiting problems during tests.

Once this step done, you must override the project using environment variables:

* `GCS_BUCKET` - The name of your GCS bucket
* `IMAGE_REPO` - The path to your Docker image repo on your registry host

This can be done as follows:
Override the target via the `IMAGE_REPO` environment variable:

```shell
export GCS_BUCKET="gs://<your bucket>"
export IMAGE_REPO="YOUR-REGISTRY/YOUR-REPO"
```

Login for both user and application credentials
```shell
gcloud auth login
gcloud auth application-default login
```

Then you can launch integration tests as follows:

```shell
Expand Down Expand Up @@ -260,7 +244,7 @@ Additionally, the integration tests can output benchmarking information to a `be
`integration` directory if the `BENCHMARK` environment variable is set to `true.`

```shell
BENCHMARK=true go test -v --bucket $GCS_BUCKET --repo $IMAGE_REPO
BENCHMARK=true go test -v --repo $IMAGE_REPO
```

#### Profiling
Expand Down
30 changes: 11 additions & 19 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,18 @@ var RootCmd = &cobra.Command{
logrus.Warnf("Unable to write benchmark file: %s", err)
return
}
if strings.HasPrefix(benchmarkFile, "gs://") {
logrus.Info("Uploading to gcs")
if err := buildcontext.UploadToBucket(strings.NewReader(s), benchmarkFile); err != nil {
logrus.Infof("Unable to upload %s due to %v", benchmarkFile, err)
}
logrus.Infof("Benchmark file written at %s", benchmarkFile)
} else {
f, err := os.Create(benchmarkFile)
if err != nil {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
return
}
defer f.Close()
_, err = f.WriteString(s)
if err != nil {
logrus.Warnf("Unable to write to benchmarking file %s: %s", benchmarkFile, err)
return
}
logrus.Infof("Benchmark file written at %s", benchmarkFile)
f, err := os.Create(benchmarkFile)
if err != nil {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
return
}
defer f.Close()
_, err = f.WriteString(s)
if err != nil {
logrus.Warnf("Unable to write to benchmarking file %s: %s", benchmarkFile, err)
return
}
logrus.Infof("Benchmark file written at %s", benchmarkFile)
}
},
}
Expand Down
64 changes: 1 addition & 63 deletions integration/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"sync"
Expand Down Expand Up @@ -61,8 +60,7 @@ func TestSnapshotBenchmark(t *testing.T) {
buildArgs := []string{"--build-arg", fmt.Sprintf("NUM=%d", num)}
var benchmarkDir string
benchmarkDir, *err = buildKanikoImage(t.Logf, "", dockerfile,
buildArgs, []string{}, kanikoImage, contextDir, config.gcsBucket, config.gcsClient,
config.serviceAccount, false, "", "")
buildArgs, []string{}, kanikoImage, contextDir, "", "")
if *err != nil {
return
}
Expand Down Expand Up @@ -114,63 +112,3 @@ func newResult(t *testing.T, f string) result {
t.Log(r)
return r
}

func TestSnapshotBenchmarkGcloud(t *testing.T) {
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err != nil || !b {
t.SkipNow()
}
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
contextDir := filepath.Join(cwd, "benchmark_fs")

nums := []int{10000, 50000, 100000, 200000, 300000, 500000, 700000}

var wg sync.WaitGroup
t.Log("Number of Files,Total Build Time,Walking Filesystem, Resolving Files")
for _, num := range nums {
t.Run(fmt.Sprintf("test_benchmark_%d", num), func(t *testing.T) {
t.Parallel()
wg.Add(1)
go func(num int) {
dir, err := runInGcloud(contextDir, num)
if err != nil {
t.Errorf("error when running in gcloud %v", err)
return
}
r := newResult(t, filepath.Join(dir, "results"))
t.Logf("%d,%f,%f,%f, %f", num, r.totalBuildTime, r.walkingFiles, r.resolvingFiles, r.hashingFiles)
wg.Done()
defer os.Remove(dir)
defer os.Chdir(cwd)
}(num)
})
}
wg.Wait()
}

func runInGcloud(dir string, num int) (string, error) {
os.Chdir(dir)
cmd := exec.Command("gcloud", "builds",
"submit", "--config=cloudbuild.yaml",
fmt.Sprintf("--substitutions=_COUNT=%d", num))
_, err := RunCommandWithoutTest(cmd)
if err != nil {
return "", err
}

// grab gcs and to temp dir and return
tmpDir, err := os.MkdirTemp("", strconv.Itoa(num))
if err != nil {
return "", err
}
src := fmt.Sprintf("%s/gcb/benchmark_file_%d", config.gcsBucket, num)
dest := filepath.Join(tmpDir, "results")
copyCommand := exec.Command("gsutil", "cp", src, dest)
_, err = RunCommandWithoutTest(copyCommand)
if err != nil {
return "", fmt.Errorf("failed to download file to GCS bucket %s: %w", src, err)
}
return tmpDir, nil
}
37 changes: 0 additions & 37 deletions integration/cleanup.go

This file was deleted.

15 changes: 0 additions & 15 deletions integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,14 @@ limitations under the License.

package integration

import (
"strings"

"cloud.google.com/go/storage"
)

type integrationTestConfig struct {
gcsBucket string
imageRepo string
onbuildBaseImage string
onbuildCopyImage string
hardlinkBaseImage string
hijackBaseImage string
malformedOCIImage string
nvidiaOperatorBaseImage string
serviceAccount string
dockerMajorVersion int
gcsClient *storage.Client
dockerfilesPattern string
}

const gcrRepoPrefix string = "gcr.io/"

func (config *integrationTestConfig) isGcrRepository() bool {
return strings.HasPrefix(config.imageRepo, gcrRepoPrefix)
}
Loading
Loading