Merge pull request #979 from samos123/travis-ci-integration-testv2

Run integration tests in Travis CI
This commit is contained in:
Tejal Desai 2020-01-22 09:55:02 -08:00 committed by GitHub
commit 6e80e627ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 122 additions and 91 deletions

View File

@ -1,10 +1,21 @@
language: go
os: linux
dist: bionic
env:
- IMAGE_REPO=localhost:5000
go:
- "1.13.3"
go_import_path: github.com/GoogleContainerTools/kaniko
before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64 && chmod +x container-diff-linux-amd64 && sudo mv container-diff-linux-amd64 /usr/local/bin/container-diff
- docker run -d -p 5000:5000 --restart always --name registry registry:2
- ./integration/replace-gcr-with-local-registry.sh integration/dockerfiles
script:
- make test
- ./integration-test.sh --uploadToGCS=false
- make images

View File

@ -1,4 +1,4 @@
FROM marketplace.gcr.io/google/ubuntu1804@sha256:4649ae6b381090fba6db38137eb05e03f44bf43c40149f734241c9f96aa0e001
FROM ubuntu:18.04
ENV dir /tmp/dir/
ONBUILD RUN echo "onbuild" > /tmp/onbuild
ONBUILD RUN mkdir $dir

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
# First, try adding some regular files
ADD context/foo foo
ADD context/foo /foodir/

View File

@ -16,7 +16,7 @@
# If the image is built twice, /date should be the same in both images
# if the cache is implemented correctly
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
RUN date > /date
COPY context/foo /foo
RUN echo hey

View File

@ -16,7 +16,7 @@
# /date should be the same regardless of when this image is built
# if the cache is implemented correctly
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
WORKDIR /foo
RUN apt-get update && apt-get install -y make
COPY context/bar /context

View File

@ -1,5 +1,4 @@
FROM gcr.io/distroless/base@sha256:628939ac8bf3f49571d05c6c76b8688cb4a851af6c7088e599388259875bde20 AS first
FROM debian:10.2 AS first
CMD ["mycmd"]
FROM first
ENTRYPOINT ["myentrypoint"] # This should clear out CMD in the config metadata

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
ENV hey hey
ENV PATH /usr/local
ENV testmultipleeq="this=is a=test string=with a=lot of=equals"

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
EXPOSE 80
EXPOSE 81/udp
ENV protocol tcp

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
LABEL foo=bar
LABEL "baz"="bat"
ENV label1 "mylabel"

View File

@ -1,15 +1,16 @@
ARG REGISTRY=gcr.io
ARG REPO=google-appengine
ARG REGISTRY=docker.io
ARG IMAGE=debian
ARG TAG=9.11
ARG WORD=hello
ARG W0RD2=hey
FROM ${REGISTRY}/${REPO}/debian9 as stage1
FROM ${REGISTRY}/${IMAGE}:${TAG} as stage1
# Should evaluate WORD and create /tmp/hello
ARG WORD
RUN touch /${WORD}
FROM ${REGISTRY}/${REPO}/debian9
FROM ${REGISTRY}/${IMAGE}:${TAG}
COPY --from=stage1 /hello /tmp

View File

@ -1,4 +1,4 @@
FROM gcr.io/distroless/base@sha256:628939ac8bf3f49571d05c6c76b8688cb4a851af6c7088e599388259875bde20
FROM debian:10.2
CMD ["command", "one"]
CMD ["command", "two"]
CMD echo "hello"

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:f0159d14385afcb58a9b2fa8955c0cb64bd3abc365e8589f8c2dd38150fbfdbe as base
FROM debian:9.11 as base
COPY . .
FROM scratch as second
@ -20,4 +20,4 @@ FROM fedora@sha256:c4cc32b09c6ae3f1353e7e33a8dda93dc41676b923d6d89afa996b421cc5a
FROM fourth
ARG file
COPY --from=second /foo ${file}
COPY --from=gcr.io/google-appengine/debian9@sha256:00109fa40230a081f5ecffe0e814725042ff62a03e2d1eae0563f1f82eaeae9b /etc/os-release /new
COPY --from=debian:9.11 /etc/os-release /new

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
RUN echo "hey" > /etc/foo
RUN echo "baz" > /etc/baz
RUN cp /etc/baz /etc/bar

View File

@ -15,6 +15,6 @@
# Test to make sure the executor builds an image correctly
# when no files are changed
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
RUN echo "hey"
MAINTAINER kaniko

View File

@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
USER testuser:testgroup

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
RUN useradd testuser
RUN groupadd testgroup
USER testuser:testgroup

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
RUN mkdir /foo
RUN echo "hello" > /foo/hey
VOLUME /foo/bar /tmp /qux/quux

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
FROM debian:9.11
VOLUME /foo1
RUN echo "hello" > /foo1/hello
WORKDIR /foo1/bar

View File

@ -1,4 +1,4 @@
FROM gcr.io/google-appengine/debian9@sha256:6b3aa04751aa2ac3b0c7be4ee71148b66d693ad212ce6d3244bd2a2a147f314a
FROM debian:9.11
COPY context/foo foo
WORKDIR /test
# Test that this will be appended on to the previous command, to create /test/workdir

View File

@ -220,8 +220,8 @@ func (d *DockerFileBuilder) BuildImage(config *gcpConfig, dockerfilesPath, docke
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", "-e", benchmarkEnv,
dockerRunFlags := []string{"run", "--net=host",
"-e", benchmarkEnv,
"-v", cwd + ":/workspace",
"-v", benchmarkDir + ":/kaniko/benchmarks",
}
@ -251,7 +251,7 @@ func populateVolumeCache() error {
_, ex, _, _ := runtime.Caller(0)
cwd := filepath.Dir(ex)
warmerCmd := exec.Command("docker",
append([]string{"run",
append([]string{"run", "--net=host",
"-d",
"-v", os.Getenv("HOME") + "/.config/gcloud:/root/.config/gcloud",
"-v", cwd + ":/workspace",
@ -284,7 +284,7 @@ func (d *DockerFileBuilder) buildCachedImages(config *gcpConfig, cacheRepo, dock
}
kanikoImage := GetVersionedKanikoImage(imageRepo, dockerfile, version)
dockerRunFlags := []string{"run",
dockerRunFlags := []string{"run", "--net=host",
"-v", cwd + ":/workspace",
"-e", benchmarkEnv}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
@ -315,7 +315,7 @@ func (d *DockerFileBuilder) buildRelativePathsImage(imageRepo, dockerfile, servi
buildContextPath := "./relative-subdirectory"
kanikoImage := GetKanikoImage(imageRepo, dockerfile)
dockerRunFlags := []string{"run", "-v", cwd + ":/workspace"}
dockerRunFlags := []string{"run", "--net=host", "-v", cwd + ":/workspace"}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, serviceAccount)
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,

View File

@ -88,6 +88,7 @@ func TestMain(m *testing.M) {
}
config = initGCPConfig()
if config.uploadToGCS {
contextFile, err := CreateIntegrationTarball()
if err != nil {
fmt.Println("Failed to create tarball of integration files for build context", err)
@ -108,6 +109,7 @@ func TestMain(m *testing.M) {
RunOnInterrupt(func() { DeleteFromBucket(fileInBucket) })
defer DeleteFromBucket(fileInBucket)
}
setupCommands := []struct {
name string
@ -197,52 +199,25 @@ func TestRun(t *testing.T) {
}
}
func TestGitBuildcontext(t *testing.T) {
repo := "github.com/GoogleContainerTools/kaniko"
dockerfile := "integration/dockerfiles/Dockerfile_test_run_2"
// Build with docker
dockerImage := GetDockerImage(config.imageRepo, "Dockerfile_test_git")
dockerCmd := exec.Command("docker",
append([]string{"build",
"-t", dockerImage,
"-f", dockerfile,
repo})...)
out, err := RunCommandWithoutTest(dockerCmd)
if err != nil {
t.Errorf("Failed to build image %s with docker command \"%s\": %s %s", dockerImage, dockerCmd.Args, err, string(out))
func getGitRepo() string {
var branch, repoSlug string
if _, ok := os.LookupEnv("TRAVIS"); ok {
if os.Getenv("TRAVIS_PULL_REQUEST") != "false" {
branch = os.Getenv("TRAVIS_PULL_REQUEST_BRANCH")
repoSlug = os.Getenv("TRAVIS_PULL_REQUEST_SLUG")
log.Printf("Travis CI Pull request source repo: %s branch: %s\n", repoSlug, branch)
} else {
branch = os.Getenv("TRAVIS_BRANCH")
repoSlug = os.Getenv("TRAVIS_REPO_SLUG")
log.Printf("Travis CI pepo: %s branch: %s\n", repoSlug, branch)
}
// Build with kaniko
kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_git")
dockerRunFlags := []string{"run"}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,
"-d", kanikoImage,
"-c", fmt.Sprintf("git://%s", repo))
kanikoCmd := exec.Command("docker", dockerRunFlags...)
out, err = RunCommandWithoutTest(kanikoCmd)
if err != nil {
t.Errorf("Failed to build image %s with kaniko command \"%s\": %v %s", dockerImage, kanikoCmd.Args, err, string(out))
return "github.com/" + repoSlug + "#refs/heads/" + branch
}
// container-diff
daemonDockerImage := daemonPrefix + dockerImage
containerdiffCmd := exec.Command("container-diff", "diff", "--no-cache",
daemonDockerImage, kanikoImage,
"-q", "--type=file", "--type=metadata", "--json")
diff := RunCommand(containerdiffCmd, t)
t.Logf("diff = %s", string(diff))
expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage)
checkContainerDiffOutput(t, diff, expected)
return "github.com/GoogleContainerTools/kaniko"
}
func TestGitBuildContextWithBranch(t *testing.T) {
repo := "github.com/GoogleContainerTools/kaniko#refs/tags/v0.10.0"
func TestGitBuildcontext(t *testing.T) {
repo := getGitRepo()
dockerfile := "integration/dockerfiles/Dockerfile_test_run_2"
// Build with docker
@ -259,7 +234,7 @@ func TestGitBuildContextWithBranch(t *testing.T) {
// Build with kaniko
kanikoImage := GetKanikoImage(config.imageRepo, "Dockerfile_test_git")
dockerRunFlags := []string{"run"}
dockerRunFlags := []string{"run", "--net=host"}
dockerRunFlags = addServiceAccountFlags(dockerRunFlags, config.serviceAccount)
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,
@ -567,6 +542,7 @@ type gcpConfig struct {
hardlinkBaseImage string
serviceAccount string
dockerMajorVersion int
uploadToGCS bool
}
type imageDetails struct {
@ -584,6 +560,7 @@ func initGCPConfig() *gcpConfig {
flag.StringVar(&c.gcsBucket, "bucket", "gs://kaniko-test-bucket", "The gcs bucket argument to uploaded the tar-ed contents of the `integration` dir to.")
flag.StringVar(&c.imageRepo, "repo", "gcr.io/kaniko-test", "The (docker) image repo to build and push images to during the test. `gcloud` must be authenticated with this repo or serviceAccount must be set.")
flag.StringVar(&c.serviceAccount, "serviceAccount", "", "The path to the service account push images to GCR and upload/download files to GCS.")
flag.BoolVar(&c.uploadToGCS, "uploadToGCS", true, "Upload the tar-ed contents of `integration` dir to GCS bucket. Default is true. Set this to false to prevent uploading.")
flag.Parse()
if len(c.serviceAccount) > 0 {

View File

@ -0,0 +1,43 @@
#!/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.
# This script is needed due to the following bug:
# https://github.com/GoogleContainerTools/kaniko/issues/966
if [ "$#" -ne 1 ]; then
echo "Please specify path to dockerfiles as first argument."
echo "Usage: `basename $0` integration/dockerfiles"
exit 2
fi
dir_with_docker_files=$1
for dockerfile in $dir_with_docker_files/*; do
cat $dockerfile | grep '^FROM' | grep "gcr" | while read -r line; do
gcr_repo=$(echo "$line" | awk '{ print $2 }')
local_repo=$(echo "$gcr_repo" | sed -e "s/^.*gcr.io\(\/.*\)$/localhost:5000\1/")
remove_digest=$(echo "$local_repo" | cut -f1 -d"@")
echo "Running docker pull $gcr_repo"
docker pull "$gcr_repo"
echo "Running docker tag $gcr_repo $remove_digest"
docker tag "$gcr_repo" "$remove_digest"
echo "Running docker push $remove_digest"
docker push "$remove_digest"
echo "Updating dockerfile $dockerfile to use local repo $local_repo"
sed -i -e "s/^\(FROM \).*gcr.io\(.*\)$/\1localhost:5000\2/" $dockerfile
done
done