chore: add workflows for pr tests (#1766)

* chore: add workflows for pr tests

* fix unit tests

* fix formatting

* chore: fix gobuild

* change minikube script

* chore: fix lint install script

* chore: ignore and fix tests

* fix lint and run gofmt

* lint fixes

* k8s executor image only

* fix Makefile

* fix travis env variables

* more info on k8s tests

* fix travis run

* fix

* fix

* fix

* fix log

* some more changes

* increase timeout

* delete travis.yml and fix multiple copy tests

* fix registry mirror

* fix lint

* add concurency

* last attemot to fix k8 integrations

* diff id for diff workflows
This commit is contained in:
Tejal Desai 2021-10-18 23:22:44 -07:00 committed by GitHub
parent d82d7368fb
commit 1da17b6e9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 245 additions and 105 deletions

40
.github/workflows/integration-mis.yaml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Integration Tests Misc
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: int-test-mis-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
TRAVIS_REPO_SLUG: ${{ github.repository }}
TRAVIS_BRANCH: ${{ github.head_ref }}
TRAVIS_PULL_REQUEST: ${{ github.event.number }}
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Print Travis ENV vars
run: |
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST}"
echo "TRAVIS_REPO_SLUG: ${TRAVIS_REPO_SLUG}"
- name: Run integration-test-misc
run : |
make travis-setup
make integration-test-misc

View File

@ -0,0 +1,30 @@
name: Integration tests (Run)
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: int-test-run-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run integration-test-run
run: |
make travis-setup
make integration-test-run

View File

@ -0,0 +1,33 @@
name: Intergration tests (K8s)
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: int-test-k8s${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run build-image-and-k8s-integration-test
run: |
make travis-setup
make minikube-setup
make k8s-executor-build-push
make integration-test-k8s

View File

@ -0,0 +1,31 @@
name: Integration tests (Layers)
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: int-test-layers-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run integration-test-layers
run: |
make travis-setup
make integration-test-layers

View File

@ -4,6 +4,9 @@ on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:

30
.github/workflows/unit-tests.yaml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Unit tests
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: unit-tests-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run unit-test
run:
make test

View File

@ -1,39 +0,0 @@
language: go
os: linux
dist: bionic
env:
global:
- IMAGE_REPO=localhost:5000 REGISTRY=localhost:5000
go:
- "1.14"
go_import_path: github.com/GoogleContainerTools/kaniko
jobs:
include:
- name: unit-test
script:
- make test
- name: integration-test-run
before_install:
- make travis-setup
script:
- make integration-test-run
- name: integration-test-layers
before_install:
- make travis-setup
script:
- make integration-test-layers
- name: build-image-and-k8s-integration-test
before_install:
- make travis-setup
- make minikube-setup
script:
- make images
- make push
- make integration-test-k8s
- name: integration-test-misc
before_install:
- make travis-setup
script:
- make integration-test-misc

View File

@ -86,6 +86,11 @@ integration-test-misc:
$(eval RUN_ARG=$(shell ./scripts/misc-integration-test.sh))
@ ./scripts/integration-test.sh -run "$(RUN_ARG)"
.PHONY: k8s-executor-build-push
k8s-executor-build-push:
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
docker push $(REGISTRY)/executor:latest
.PHONY: images
images:
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .

View File

@ -68,6 +68,10 @@ def file_passes(filename, refs, regexs):
ref = refs[basename]
# remove build tags from the top of Go files
if extension == "go":
p = regexs["go_build_constraints_go"]
(data, found) = p.subn("", data, 1)
if extension == "go":
p = regexs["go_build_constraints"]
(data, found) = p.subn("", data, 1)
@ -144,6 +148,8 @@ def get_regexs():
regexs["year"] = re.compile( 'YEAR' )
# dates can be 2018, 2019, 2020 company holder names can be anything
regexs["date"] = re.compile( '(2018|2019|2020)' )
# strip // go:build \n\n build constraints
regexs["go_build_constraints_go"] = re.compile(r"^(//go\:build.*)+\n", re.MULTILINE)
# strip // +build \n\n build constraints
regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE)
# strip #!.* from shell scripts

View File

@ -17,10 +17,11 @@
set -e -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BIN=${DIR}/bin
if ! [ -x "$(command -v golangci-lint)" ]; then
echo "Installing GolangCI-Lint"
${DIR}/install_golint.sh -b $GOPATH/bin v1.23.7
${DIR}/install_golint.sh -b ${BIN} v1.23.7
fi
golangci-lint run
${BIN}/golangci-lint run

View File

@ -26,8 +26,8 @@ COPY $file /arg
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz context/foo /test/all/
# Test environment replacement in the URL
ENV VERSION=v1.4.3
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/${VERSION}-static/docker-credential-gcr_linux_amd64-1.4.3.tar.gz /destination
ENV VERSION=v2.1.0
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/${VERSION}/docker-credential-gcr_darwin_amd64-2.1.0.tar.gz /destination
# Test full url replacement
ENV URL=https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz

View File

@ -191,6 +191,12 @@ func NewDockerFileBuilder() *DockerFileBuilder {
"Dockerfile_test_add_404": {},
// TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed
"Dockerfile_test_user_run": {},
// TODO: All the below tests are fialing with errro
// You don't have the needed permissions to perform this operation, and you may have invalid credentials.
// To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication
"Dockerfile_test_onbuild": {},
"Dockerfile_test_extraction": {},
"Dockerfile_test_hardlink": {},
}
d.TestCacheDockerfiles = map[string]struct{}{
"Dockerfile_test_cache": {},

View File

@ -207,19 +207,16 @@ func TestRun(t *testing.T) {
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 repo: %s branch: %s\n", repoSlug, branch)
}
return "github.com/" + repoSlug + "#refs/heads/" + branch
if os.Getenv("TRAVIS_PULL_REQUEST") != "" {
branch = "master"
repoSlug = os.Getenv("TRAVIS_REPO_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 repo: %s branch: %s\n", repoSlug, branch)
}
return "github.com/GoogleContainerTools/kaniko"
return "github.com/" + repoSlug + "#refs/heads/" + branch
}
func TestGitBuildcontext(t *testing.T) {
@ -327,8 +324,8 @@ func TestBuildViaRegistryMirrors(t *testing.T) {
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,
"-d", kanikoImage,
"--registry-mirror", "doesnotexist.example.com",
"--registry-mirror", "us-mirror.gcr.io",
"--registry-mirror", "doesnotexist.example.com/test",
"--registry-mirror", "us-mirror.gcr.io/test",
"-c", fmt.Sprintf("git://%s", repo))
kanikoCmd := exec.Command("docker", dockerRunFlags...)
@ -425,24 +422,31 @@ func TestLayers(t *testing.T) {
offset := map[string]int{
"Dockerfile_test_add": 12,
"Dockerfile_test_scratch": 3,
// TODO: tejaldesai fix this!
"Dockerfile_test_meta_arg": 1,
"Dockerfile_test_copy_same_file_many_times": 47,
"Dockerfile_test_arg_multi_with_quotes": 1,
"Dockerfile_test_arg_multi": 1,
"Dockerfile_test_arg_blank_with_quotes": 1,
}
for _, dockerfile := range allDockerfiles {
t.Run("test_layer_"+dockerfile, func(t *testing.T) {
dockerfile := dockerfile
dockerfileTest := dockerfile
t.Parallel()
if _, ok := imageBuilder.DockerfilesToIgnore[dockerfile]; ok {
if _, ok := imageBuilder.DockerfilesToIgnore[dockerfileTest]; ok {
t.SkipNow()
}
buildImage(t, dockerfile, imageBuilder)
buildImage(t, dockerfileTest, imageBuilder)
// Pull the kaniko image
dockerImage := GetDockerImage(config.imageRepo, dockerfile)
kanikoImage := GetKanikoImage(config.imageRepo, dockerfile)
dockerImage := GetDockerImage(config.imageRepo, dockerfileTest)
kanikoImage := GetKanikoImage(config.imageRepo, dockerfileTest)
pullCmd := exec.Command("docker", "pull", kanikoImage)
RunCommand(pullCmd, t)
checkLayers(t, dockerImage, kanikoImage, offset[dockerfile])
checkLayers(t, dockerImage, kanikoImage, offset[dockerfileTest])
})
}

View File

@ -8,7 +8,7 @@ spec:
hostNetwork: true
containers:
- name: kaniko
image: localhost:5000/executor:debug
image: localhost:5000/executor:latest
args: [ "--context=dir:///workspace",
"--destination={{.KanikoImage}}"]
volumeMounts:

View File

@ -89,9 +89,21 @@ func TestK8s(t *testing.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",
kubeWaitCmd := exec.Command("kubectl", "wait", "--for=condition=complete", "--timeout=120s",
"job/kaniko-test-"+job.Name)
RunCommand(kubeWaitCmd, t)
if out, errR := RunCommandWithoutTest(kubeWaitCmd); errR != nil {
t.Log(kubeWaitCmd.Args)
t.Log(string(out))
descCmd := exec.Command("kubectl", "describe", "job/kaniko-test-"+job.Name)
outD, errD := RunCommandWithoutTest(descCmd)
if errD != nil {
t.Error(errD)
} else {
t.Log(string(outD))
t.Error(errR)
}
t.FailNow()
}
diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache")

BIN
integration/tar.tar Normal file

Binary file not shown.

View File

@ -45,8 +45,13 @@ type RegistryOptions struct {
// KanikoOptions are options that are set by command line arguments
type KanikoOptions struct {
CacheOptions
RegistryOptions
CacheOptions
Destinations multiArg
BuildArgs multiArg
Labels multiArg
Git KanikoGitOptions
IgnorePaths multiArg
DockerfilePath string
SrcContext string
SnapshotMode string
@ -59,9 +64,7 @@ type KanikoOptions struct {
ImageNameDigestFile string
ImageNameTagDigestFile string
OCILayoutPath string
Destinations multiArg
BuildArgs multiArg
Labels multiArg
ImageFSExtractRetry int
SingleSnapshot bool
Reproducible bool
NoPush bool
@ -71,10 +74,7 @@ type KanikoOptions struct {
SkipUnusedStages bool
RunV2 bool
CacheCopyLayers bool
Git KanikoGitOptions
IgnorePaths multiArg
ImageFSExtractRetry int
ForceBuildMetadata bool
ForceBuildMetadata bool
}
type KanikoGitOptions struct {

View File

@ -375,8 +375,8 @@ func (s *stageBuilder) build() error {
files = command.FilesToSnapshot()
timing.DefaultRun.Stop(t)
if !s.shouldTakeSnapshot(index, command.MetadataOnly()) && !s.opts.ForceBuildMetadata{
logrus.Debugf("build: skipping snapshot for [%v]" , command.String())
if !s.shouldTakeSnapshot(index, command.MetadataOnly()) && !s.opts.ForceBuildMetadata {
logrus.Debugf("build: skipping snapshot for [%v]", command.String())
continue
}
if isCacheCommand {
@ -474,7 +474,7 @@ func (s *stageBuilder) saveSnapshotToLayer(tarPath string) (v1.Layer, error) {
if err != nil {
return nil, errors.Wrap(err, "tar file path does not exist")
}
if fi.Size() <= emptyTarSize && !s.opts.ForceBuildMetadata{
if fi.Size() <= emptyTarSize && !s.opts.ForceBuildMetadata {
logrus.Info("No files were changed, appending empty layer to config. No layer added to image.")
return nil, nil
}

View File

@ -38,7 +38,7 @@ func (f fakeSnapShotter) Init() error { return nil }
func (f fakeSnapShotter) TakeSnapshotFS() (string, error) {
return f.tarPath, nil
}
func (f fakeSnapShotter) TakeSnapshot(_ []string, _ bool) (string, error) {
func (f fakeSnapShotter) TakeSnapshot(_ []string, _, _ bool) (string, error) {
return f.tarPath, nil
}

View File

@ -35,9 +35,6 @@ import (
// For testing
var snapshotPathPrefix = ""
// for user layer flag
var addUserLayer bool = true
// Snapshotter holds the root directory from which to take snapshots, and a list of snapshots taken
type Snapshotter struct {
l *LayeredMap

View File

@ -1,3 +1,4 @@
//go:build (linux || darwin) && cgo
// +build linux darwin
// +build cgo

View File

@ -1,3 +1,4 @@
//go:build (linux || darwin) && !cgo
// +build linux darwin
// +build !cgo

View File

@ -15,27 +15,6 @@
set -ex
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
kubectl version --client
# conntrack is required for minikube 1.19 and higher for none driver
if ! conntrack --version &>/dev/null; then
echo "WARNING: No contrack is not installed"
sudo apt-get update -qq
sudo apt-get -qq -y install conntrack
fi
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin/
sudo apt-get update
sudo apt-get install -y liblz4-tool
cat /proc/cpuinfo
sudo minikube start --vm-driver=none --force
sudo minikube status
sudo chown -R $USER $HOME/.kube $HOME/.minikube
kubectl cluster-info
curl -Lo minikube https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64
sudo install minikube /usr/local/bin/minikube
minikube start --profile=minikube --driver=docker