benchmark project added

This commit is contained in:
Tejal Desai 2020-05-25 21:21:33 -07:00
parent e0f93578b6
commit 5d013626fc
7 changed files with 134 additions and 65 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
out/ out/
.idea .idea
*.iml

View File

@ -0,0 +1,9 @@
FROM bash:4.4
ARG NUM
COPY context.txt .
COPY make.sh .
RUN ls -al make.sh
SHELL ["/usr/local/bin/bash", "-c"]
RUN ./make.sh $NUM
RUN ls -al /workdir | wc

View File

@ -0,0 +1 @@
hello world

10
integration/benchmark/make.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/local/bin/bash
mkdir /workdir
i=1
while [ $i -le $1 ]
do
cat context.txt > /workdir/somefile$i
i=$(( $i + 1 ))
done

View File

@ -0,0 +1,51 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integration
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestSnapshotBenchmark(t *testing.T) {
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
contextDir := filepath.Join(cwd, "benchmark")
nums := []int{10000, 50000, 100000, 200000, 300000, 500000, 700000, 800000}
for _, num := range nums {
t.Run("test_benchmark"+string(num), func(t *testing.T) {
t.Parallel()
dockerfile := "Dockerfile_FS_benchmark"
kanikoImage := GetKanikoImage(config.imageRepo, dockerfile)
buildArgs := []string{"--build-arg", fmt.Sprintf("NUM=%d", num)}
if _, err := buildKanikoImage("", dockerfile,
buildArgs, []string{}, kanikoImage, contextDir, config.gcsBucket, config.serviceAccount); err != nil {
t.Errorf("could not run benchmark results for num %d", num)
}
})
}
if err := logBenchmarks("benchmark"); err != nil {
t.Logf("Failed to create benchmark file: %v", err)
}
}

View File

@ -259,70 +259,25 @@ func (d *DockerFileBuilder) BuildImageWithContext(config *integrationTestConfig,
} }
} }
reproducibleFlag := "" additionalKanikoFlags := additionalDockerFlagsMap[dockerfile]
additionalKanikoFlags = append(additionalKanikoFlags, contextFlag, contextPath)
for _, d := range reproducibleTests { for _, d := range reproducibleTests {
if d == dockerfile { if d == dockerfile {
reproducibleFlag = "--reproducible" additionalKanikoFlags = append(additionalKanikoFlags, "--reproducible")
break break
} }
} }
benchmarkEnv := "BENCHMARK_FILE=false" kanikoImage := GetKanikoImage(imageRepo, dockerfile)
benchmarkDir, err := ioutil.TempDir("", "") out, err := buildKanikoImage(dockerfilesPath, dockerfile, buildArgs, additionalKanikoFlags, kanikoImage,
contextDir, gcsBucket, serviceAccount)
if err != nil { if err != nil {
return err return err
} }
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err == nil && b {
benchmarkEnv = "BENCHMARK_FILE=/kaniko/benchmarks/" + dockerfile
benchmarkFile := path.Join(benchmarkDir, dockerfile)
fileName := fmt.Sprintf("run_%s_%s", time.Now().Format("2006-01-02-15:04"), dockerfile)
dst := path.Join("benchmarks", fileName)
defer UploadFileToBucket(gcsBucket, benchmarkFile, dst)
}
// build kaniko image
additionalFlags := append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
fmt.Printf("Going to build image with kaniko: %s, flags: %s \n", kanikoImage, additionalFlags)
dockerRunFlags := []string{"run", "--net=host",
"-e", benchmarkEnv,
"-v", contextDir + ":/workspace",
"-v", benchmarkDir + ":/kaniko/benchmarks",
}
if env, ok := envsMap[dockerfile]; ok {
for _, envVariable := range env {
dockerRunFlags = append(dockerRunFlags, "-e", envVariable)
}
}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
kanikoDockerfilePath := path.Join(buildContextPath, dockerfilesPath, dockerfile)
if dockerfilesPath == "" {
kanikoDockerfilePath = path.Join(buildContextPath, "Dockerfile")
}
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", kanikoDockerfilePath,
"-d", kanikoImage, reproducibleFlag,
contextFlag, contextPath)
dockerRunFlags = append(dockerRunFlags, additionalFlags...)
kanikoCmd := exec.Command("docker", dockerRunFlags...)
timer = timing.Start(dockerfile + "_kaniko")
out, err := RunCommandWithoutTest(kanikoCmd)
timing.DefaultRun.Stop(timer)
if err != nil {
return fmt.Errorf("Failed to build image %s with kaniko command \"%s\": %s %s", kanikoImage, kanikoCmd.Args, err, string(out))
}
if outputCheck := outputChecks[dockerfile]; outputCheck != nil { if outputCheck := outputChecks[dockerfile]; outputCheck != nil {
if err := outputCheck(dockerfile, out); err != nil { if err := outputCheck(dockerfile, out); err != nil {
return fmt.Errorf("Output check failed for image %s with kaniko command \"%s\": %s %s", kanikoImage, kanikoCmd.Args, err, string(out)) return fmt.Errorf("Output check failed for image %s with kaniko command : %s %s", kanikoImage, err, string(out))
} }
} }
@ -435,3 +390,58 @@ func (d *DockerFileBuilder) buildRelativePathsImage(imageRepo, dockerfile, servi
return nil return nil
} }
func buildKanikoImage(dockerfilesPath string, dockerfile string, buildArgs []string, kanikoArgs []string, kanikoImage string,
contextDir string, gcsBucket string, serviceAccount string) ([]byte, error) {
benchmarkEnv := "BENCHMARK_FILE=false"
benchmarkDir, err := ioutil.TempDir("", "")
if err != nil {
return nil, err
}
if b, err := strconv.ParseBool(os.Getenv("BENCHMARK")); err == nil && b {
benchmarkEnv = "BENCHMARK_FILE=/kaniko/benchmarks/" + dockerfile
benchmarkFile := path.Join(benchmarkDir, dockerfile)
fileName := fmt.Sprintf("run_%s_%s", time.Now().Format("2006-01-02-15:04"), dockerfile)
dst := path.Join("benchmarks", fileName)
defer UploadFileToBucket(gcsBucket, benchmarkFile, dst)
}
// build kaniko image
additionalFlags := append(buildArgs, kanikoArgs...)
fmt.Printf("Going to build image with kaniko: %s, flags: %s \n", kanikoImage, additionalFlags)
dockerRunFlags := []string{"run", "--net=host",
"-e", benchmarkEnv,
"-v", contextDir + ":/workspace",
"-v", benchmarkDir + ":/kaniko/benchmarks",
}
if env, ok := envsMap[dockerfile]; ok {
for _, envVariable := range env {
dockerRunFlags = append(dockerRunFlags, "-e", envVariable)
}
}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
kanikoDockerfilePath := path.Join(buildContextPath, dockerfilesPath, dockerfile)
if dockerfilesPath == "" {
kanikoDockerfilePath = path.Join(buildContextPath, "Dockerfile")
}
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", kanikoDockerfilePath,
"-d", kanikoImage)
dockerRunFlags = append(dockerRunFlags, additionalFlags...)
kanikoCmd := exec.Command("docker", dockerRunFlags...)
timer := timing.Start(dockerfile + "_kaniko")
out, err := RunCommandWithoutTest(kanikoCmd)
timing.DefaultRun.Stop(timer)
if err != nil {
return nil, fmt.Errorf("Failed to build image %s with kaniko command \"%s\": %s %s", kanikoImage, kanikoCmd.Args, err, string(out))
}
return out, nil
}

View File

@ -21,19 +21,6 @@ IMAGE_REPO="${IMAGE_REPO:-gcr.io/kaniko-test}"
docker version docker version
# Sets up a kokoro (Google internal integration testing tool) environment # Sets up a kokoro (Google internal integration testing tool) environment
if [ -f "$KOKORO_GFILE_DIR"/common.sh ]; then
echo "Installing dependencies..."
source "$KOKORO_GFILE_DIR/common.sh"
mkdir -p /usr/local/go/src/github.com/GoogleContainerTools/
cp -r github/kaniko /usr/local/go/src/github.com/GoogleContainerTools/
pushd /usr/local/go/src/github.com/GoogleContainerTools/kaniko
echo "Installing container-diff..."
mv $KOKORO_GFILE_DIR/container-diff-linux-amd64 $KOKORO_GFILE_DIR/container-diff
chmod +x $KOKORO_GFILE_DIR/container-diff
export PATH=$PATH:$KOKORO_GFILE_DIR
cp $KOKORO_ROOT/src/keystore/72508_gcr_application_creds $HOME/.config/gcloud/application_default_credentials.json
fi
echo "Running integration tests..." echo "Running integration tests..."
make out/executor make out/executor
make out/warmer make out/warmer