add integration tests with their own context
This commit is contained in:
parent
8d2b205ef2
commit
57c97dea3e
|
|
@ -37,4 +37,4 @@ fi
|
||||||
echo "Running integration tests..."
|
echo "Running integration tests..."
|
||||||
make out/executor
|
make out/executor
|
||||||
make out/warmer
|
make out/warmer
|
||||||
go test ./integration/... -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 30m "$@"
|
go test ./integration/... -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 50m "$@"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Copyright 2020 Google, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
FROM atomist/sdm-base:0.4.1
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci \
|
||||||
|
&& npm cache clean --force
|
||||||
|
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
|
USER atomist:atomist
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "foo",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "foo",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "Don't forget to sanitize your inputs",
|
||||||
|
"author": "Little Bobby Tables",
|
||||||
|
"private": false,
|
||||||
|
"devDependencies": {},
|
||||||
|
"scripts": {},
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Copyright 2020 Google, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
ADD test.txt /tmp/
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
meow
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Copyright 2020 Google, Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
FROM phusion/baseimage:0.11
|
||||||
|
ADD test-file /etc/service/file
|
||||||
|
|
@ -189,12 +189,17 @@ func addServiceAccountFlags(flags []string, serviceAccount string) []string {
|
||||||
// The resulting image will be tagged with imageRepo. If the dockerfile will be built with
|
// The resulting image will be tagged with imageRepo. If the dockerfile will be built with
|
||||||
// context (i.e. it is in `buildContextTests`) the context will be pulled from gcsBucket.
|
// context (i.e. it is in `buildContextTests`) the context will be pulled from gcsBucket.
|
||||||
func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfilesPath, dockerfile string) error {
|
func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfilesPath, dockerfile string) error {
|
||||||
|
_, ex, _, _ := runtime.Caller(0)
|
||||||
|
cwd := filepath.Dir(ex)
|
||||||
|
|
||||||
|
return d.BuildImageWithContext(config, dockerfilesPath, dockerfile, cwd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DockerFileBuilder) BuildImageWithContext(config *integrationTestConfig, dockerfilesPath, dockerfile, contextDir string) error {
|
||||||
if _, present := d.filesBuilt[dockerfile]; present {
|
if _, present := d.filesBuilt[dockerfile]; present {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
gcsBucket, serviceAccount, imageRepo := config.gcsBucket, config.serviceAccount, config.imageRepo
|
gcsBucket, serviceAccount, imageRepo := config.gcsBucket, config.serviceAccount, config.imageRepo
|
||||||
_, ex, _, _ := runtime.Caller(0)
|
|
||||||
cwd := filepath.Dir(ex)
|
|
||||||
|
|
||||||
fmt.Printf("Building images for Dockerfile %s\n", dockerfile)
|
fmt.Printf("Building images for Dockerfile %s\n", dockerfile)
|
||||||
|
|
||||||
|
|
@ -203,16 +208,24 @@ func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfile
|
||||||
for _, arg := range argsMap[dockerfile] {
|
for _, arg := range argsMap[dockerfile] {
|
||||||
buildArgs = append(buildArgs, buildArgFlag, arg)
|
buildArgs = append(buildArgs, buildArgFlag, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// build docker image
|
// build docker image
|
||||||
additionalFlags := append(buildArgs, additionalDockerFlagsMap[dockerfile]...)
|
additionalFlags := append(buildArgs, additionalDockerFlagsMap[dockerfile]...)
|
||||||
dockerImage := strings.ToLower(imageRepo + dockerPrefix + dockerfile)
|
dockerImage := strings.ToLower(imageRepo + dockerPrefix + dockerfile)
|
||||||
dockerCmd := exec.Command("docker",
|
|
||||||
append([]string{"build",
|
dockerArgs := []string{
|
||||||
"-t", dockerImage,
|
"build",
|
||||||
"-f", path.Join(dockerfilesPath, dockerfile),
|
"-t", dockerImage,
|
||||||
"."},
|
}
|
||||||
additionalFlags...)...,
|
|
||||||
)
|
if dockerfilesPath != "" {
|
||||||
|
dockerArgs = append(dockerArgs, "-f", path.Join(dockerfilesPath, dockerfile))
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerArgs = append(dockerArgs, contextDir)
|
||||||
|
dockerArgs = append(dockerArgs, additionalFlags...)
|
||||||
|
|
||||||
|
dockerCmd := exec.Command("docker", dockerArgs...)
|
||||||
if env, ok := envsMap[dockerfile]; ok {
|
if env, ok := envsMap[dockerfile]; ok {
|
||||||
dockerCmd.Env = append(dockerCmd.Env, env...)
|
dockerCmd.Env = append(dockerCmd.Env, env...)
|
||||||
}
|
}
|
||||||
|
|
@ -259,20 +272,28 @@ func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfile
|
||||||
additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
|
additionalFlags = append(buildArgs, additionalKanikoFlagsMap[dockerfile]...)
|
||||||
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
|
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
|
||||||
fmt.Printf("Going to build image with kaniko: %s, flags: %s \n", kanikoImage, additionalFlags)
|
fmt.Printf("Going to build image with kaniko: %s, flags: %s \n", kanikoImage, additionalFlags)
|
||||||
|
|
||||||
dockerRunFlags := []string{"run", "--net=host",
|
dockerRunFlags := []string{"run", "--net=host",
|
||||||
"-e", benchmarkEnv,
|
"-e", benchmarkEnv,
|
||||||
"-v", cwd + ":/workspace",
|
"-v", contextDir + ":/workspace",
|
||||||
"-v", benchmarkDir + ":/kaniko/benchmarks",
|
"-v", benchmarkDir + ":/kaniko/benchmarks",
|
||||||
}
|
}
|
||||||
|
|
||||||
if env, ok := envsMap[dockerfile]; ok {
|
if env, ok := envsMap[dockerfile]; ok {
|
||||||
for _, envVariable := range env {
|
for _, envVariable := range env {
|
||||||
dockerRunFlags = append(dockerRunFlags, "-e", envVariable)
|
dockerRunFlags = append(dockerRunFlags, "-e", envVariable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
|
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
|
||||||
|
|
||||||
|
kanikoDockerfilePath := path.Join(buildContextPath, dockerfilesPath, dockerfile)
|
||||||
|
if dockerfilesPath == "" {
|
||||||
|
kanikoDockerfilePath = path.Join(buildContextPath, "Dockerfile")
|
||||||
|
}
|
||||||
|
|
||||||
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
|
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
|
||||||
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
|
"-f", kanikoDockerfilePath,
|
||||||
"-d", kanikoImage, reproducibleFlag,
|
"-d", kanikoImage, reproducibleFlag,
|
||||||
contextFlag, contextPath)
|
contextFlag, contextPath)
|
||||||
dockerRunFlags = append(dockerRunFlags, additionalFlags...)
|
dockerRunFlags = append(dockerRunFlags, additionalFlags...)
|
||||||
|
|
@ -282,9 +303,11 @@ func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfile
|
||||||
timer = timing.Start(dockerfile + "_kaniko")
|
timer = timing.Start(dockerfile + "_kaniko")
|
||||||
out, err = RunCommandWithoutTest(kanikoCmd)
|
out, err = RunCommandWithoutTest(kanikoCmd)
|
||||||
timing.DefaultRun.Stop(timer)
|
timing.DefaultRun.Stop(timer)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to build image %s with kaniko command \"%s\": %s %s", dockerImage, kanikoCmd.Args, err, string(out))
|
return fmt.Errorf("Failed to build image %s with kaniko command \"%s\": %s %s", dockerImage, 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", dockerImage, kanikoCmd.Args, err, string(out))
|
return fmt.Errorf("Output check failed for image %s with kaniko command \"%s\": %s %s", dockerImage, kanikoCmd.Args, err, string(out))
|
||||||
|
|
@ -292,6 +315,7 @@ func (d *DockerFileBuilder) BuildImage(config *integrationTestConfig, dockerfile
|
||||||
}
|
}
|
||||||
|
|
||||||
d.filesBuilt[dockerfile] = struct{}{}
|
d.filesBuilt[dockerfile] = struct{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
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"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWithContext(t *testing.T) {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Join(cwd, "dockerfiles-with-context")
|
||||||
|
|
||||||
|
testDirs, err := ioutil.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := NewDockerFileBuilder()
|
||||||
|
|
||||||
|
for _, tdInfo := range testDirs {
|
||||||
|
name := tdInfo.Name()
|
||||||
|
testDir := filepath.Join(dir, name)
|
||||||
|
|
||||||
|
t.Run("test_with_context_"+name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if err := builder.BuildImageWithContext(
|
||||||
|
config, "", name, testDir,
|
||||||
|
); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerImage := GetDockerImage(config.imageRepo, name)
|
||||||
|
kanikoImage := GetKanikoImage(config.imageRepo, name)
|
||||||
|
|
||||||
|
diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")
|
||||||
|
|
||||||
|
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
|
||||||
|
checkContainerDiffOutput(t, diff, expected)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := logBenchmarks("benchmark"); err != nil {
|
||||||
|
t.Logf("Failed to create benchmark file: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue