-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1124 from samos123/travis-k8s-test
Travis k8s integration test
- Loading branch information
Showing
11 changed files
with
266 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scripts/integration-test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: kaniko-test-{{.Name}} | ||
spec: | ||
template: | ||
spec: | ||
hostNetwork: true | ||
containers: | ||
- name: kaniko | ||
image: localhost:5000/executor:debug | ||
args: [ "--context=dir:///workspace", | ||
"--destination={{.KanikoImage}}"] | ||
volumeMounts: | ||
- name: context | ||
mountPath: /workspace | ||
restartPolicy: Never | ||
volumes: | ||
- name: context | ||
hostPath: | ||
path: {{.Context}} | ||
backoffLimit: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
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" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
"text/template" | ||
) | ||
|
||
type K8sConfig struct { | ||
KanikoImage string | ||
Context string | ||
Name string | ||
} | ||
|
||
func TestK8s(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_k8s_with_context_"+name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if err := builder.BuildDockerImage( | ||
config.imageRepo, "", name, testDir, | ||
); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
dockerImage := GetDockerImage(config.imageRepo, name) | ||
kanikoImage := GetKanikoImage(config.imageRepo, name) | ||
|
||
tmpfile, err := ioutil.TempFile("", "k8s-job-*.yaml") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.Remove(tmpfile.Name()) // clean up | ||
tmpl := template.Must(template.ParseFiles("k8s-job.yaml")) | ||
job := K8sConfig{KanikoImage: kanikoImage, Context: testDir, Name: name} | ||
if err := tmpl.Execute(tmpfile, job); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fmt.Printf("Testing K8s based Kaniko building of dockerfile %s and push to %s \n", | ||
testDir, kanikoImage) | ||
content, err := ioutil.ReadFile(tmpfile.Name()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("K8s template %s:\n%s\n", tmpfile.Name(), content) | ||
|
||
kubeCmd := exec.Command("kubectl", "apply", "-f", tmpfile.Name()) | ||
RunCommand(kubeCmd, t) | ||
|
||
fmt.Printf("Waiting for K8s kaniko build job to finish: %s\n", | ||
"job/kaniko-test-"+job.Name) | ||
|
||
kubeWaitCmd := exec.Command("kubectl", "wait", "--for=condition=complete", "--timeout=60s", | ||
"job/kaniko-test-"+job.Name) | ||
RunCommand(kubeWaitCmd, t) | ||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
set -ex | ||
|
||
GCS_BUCKET="${GCS_BUCKET:-gs://kaniko-test-bucket}" | ||
IMAGE_REPO="${IMAGE_REPO:-gcr.io/kaniko-test}" | ||
|
||
docker version | ||
|
||
# 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..." | ||
make out/executor | ||
make out/warmer | ||
go test ./integration/... -v --bucket "${GCS_BUCKET}" --repo "${IMAGE_REPO}" --timeout 50m "$@" |
Oops, something went wrong.