Skip to content

Commit

Permalink
Collapse integration test workflows into one config (#1855)
Browse files Browse the repository at this point in the history
* Collapse integration test workflows into one config

Remove last traces of Travis, including env vars and `make travis-setup`
and badges in README

* fix lint

* make integration tests pass on PRs
  • Loading branch information
imjasonh authored Dec 23, 2021
1 parent b1b6962 commit 59c2d2d
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 207 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/integration-k8s-tests.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/integration-layers-tests.yaml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/integration-misc.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/integration-run-tests.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Integration tests

on:
push:
branches: ['master']
pull_request:
branches: ['master']

concurrency:
group: integration-test-${{ github.head_ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
strategy:
fail-fast: false
matrix:
make-target:
- integration-test-layers
- integration-test-misc
- integration-test-run
- k8s-executor-build-push integration-test-k8s

steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1

- run: make install-container-diff minikube-setup
- run: make ${{ matrix.make-target }}
2 changes: 2 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Unit tests

on:
push:
branches: ['master']
pull_request:
branches: ['master']

Expand Down
4 changes: 1 addition & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ You can also run tests with `go test`, for example to run tests individually:
go test ./integration -v --repo localhost:5000 -run TestLayers/test_layer_Dockerfile_test_copy_bucket
```

These tests will be kicked off by [reviewers](#reviews) for submitted PRs by the travis task.


These tests will be kicked off by [reviewers](#reviews) for submitted PRs using GitHub Actions.

### Benchmarking

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ out/executor: $(GO_FILES)
out/warmer: $(GO_FILES)
GOARCH=$(GOARCH) GOOS=linux CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -o $@ $(WARMER_PACKAGE)

.PHONY: travis-setup
travis-setup:
@ ./scripts/travis-setup.sh
.PHONY: install-container-diff
install-container-diff:
@ curl -LO https://github.com/GoogleContainerTools/container-diff/releases/download/v0.17.0/container-diff-linux-amd64 && \
chmod +x container-diff-linux-amd64 && sudo mv container-diff-linux-amd64 /usr/local/bin/container-diff

.PHONY: minikube-setup
minikube-setup:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# kaniko - Build Images In Kubernetes

`NOTE: kaniko is not an officially supported Google product`
## 🚨NOTE: kaniko is not an officially supported Google product🚨

[![Build Status](https://travis-ci.com/GoogleContainerTools/kaniko.svg?branch=master)](https://travis-ci.com/GoogleContainerTools/kaniko) [![Go Report Card](https://goreportcard.com/badge/github.com/GoogleContainerTools/kaniko)](https://goreportcard.com/report/github.com/GoogleContainerTools/kaniko)
[![Unit tests](https://github.com/GoogleContainerTools/kaniko/actions/workflows/unit-tests.yaml/badge.svg)](https://github.com/GoogleContainerTools/kaniko/actions/workflows/unit-tests.yaml)
[![Integration tests](https://github.com/GoogleContainerTools/kaniko/actions/workflows/integration-tests.yaml/badge.svg)](https://github.com/GoogleContainerTools/kaniko/actions/workflows/integration-tests.yaml)
[![Build images](https://github.com/GoogleContainerTools/kaniko/actions/workflows/images.yaml/badge.svg)](https://github.com/GoogleContainerTools/kaniko/actions/workflows/images.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/GoogleContainerTools/kaniko)](https://goreportcard.com/report/github.com/GoogleContainerTools/kaniko)

![kaniko logo](logo/Kaniko-Logo.png)

Expand Down
78 changes: 26 additions & 52 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import (
"testing"
"time"

"github.com/go-git/go-git/v5"
gitConfig "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/pkg/errors"
Expand Down Expand Up @@ -203,53 +199,31 @@ func TestRun(t *testing.T) {
}
}

func findSHA(ref plumbing.ReferenceName, refs []*plumbing.Reference) (string, error) {
for _, ref2 := range refs {
if ref.String() == ref2.Name().String() {
return ref2.Hash().String(), nil
}
}
return "", errors.New("no ref found")
}

// getBranchSHA get a SHA commit hash for the given repo url and branch ref name.
func getBranchSHA(t *testing.T, url, branch string) string {
repo := "https://" + url
c := &gitConfig.RemoteConfig{URLs: []string{repo}}
remote := git.NewRemote(memory.NewStorage(), c)
refs, err := remote.List(&git.ListOptions{})
if err != nil {
t.Fatalf("list remote %s#%s: %s", repo, branch, err)
}
commit, err := findSHA(plumbing.NewBranchReferenceName(branch), refs)
if err != nil {
t.Fatalf("findSHA %s#%s: %s", repo, branch, err)
}
return commit
}

func getBranchAndURL() (branch, url string) {
var repoSlug string
if _, ok := os.LookupEnv("TRAVIS_PULL_REQUEST"); ok {
func getBranchCommitAndURL() (branch, commit, url string) {
repo := os.Getenv("GITHUB_REPOSITORY")
commit = os.Getenv("GITHUB_SHA")
if _, isPR := os.LookupEnv("GITHUB_HEAD_REF"); isPR {
branch = "master"
repoSlug = os.Getenv("TRAVIS_REPO_SLUG")
log.Printf("Travis CI Pull request source repo: %s branch: %s\n", repoSlug, branch)
} else if _, ok := os.LookupEnv("TRAVIS_BRANCH"); ok {
branch = os.Getenv("TRAVIS_BRANCH")
repoSlug = os.Getenv("TRAVIS_REPO_SLUG")
log.Printf("Travis CI repo: %s branch: %s\n", repoSlug, branch)
} else {
branch = os.Getenv("GITHUB_REF")
log.Printf("GITHUB_HEAD_REF is unset (not a PR); using GITHUB_REF=%q", branch)
branch = strings.TrimPrefix(branch, "refs/heads/")
}
if repo == "" {
repo = "GoogleContainerTools/kaniko"
}
if branch == "" {
branch = "master"
repoSlug = "GoogleContainerTools/kaniko"
}
url = "github.com/" + repoSlug
log.Printf("repo=%q / commit=%q / branch=%q", repo, commit, branch)
url = "github.com/" + repo
return
}

func getGitRepo(t *testing.T, explicit bool) string {
branch, url := getBranchAndURL()
if explicit {
return url + "#" + getBranchSHA(t, url, branch)
func getGitRepo(explicit bool) string {
branch, commit, url := getBranchCommitAndURL()
if explicit && commit != "" {
return url + "#" + commit
}
return url + "#refs/heads/" + branch
}
Expand Down Expand Up @@ -296,28 +270,28 @@ func testGitBuildcontextHelper(t *testing.T, repo string) {
// Example:
// git://github.com/myuser/repo#refs/heads/master
func TestGitBuildcontext(t *testing.T) {
repo := getGitRepo(t, false)
repo := getGitRepo(false)
testGitBuildcontextHelper(t, repo)
}

// TestGitBuildcontextNoRef builds without any commit / branch reference
// Example:
// git://github.com/myuser/repo
func TestGitBuildcontextNoRef(t *testing.T) {
_, repo := getBranchAndURL()
testGitBuildcontextHelper(t, repo)
_, _, url := getBranchCommitAndURL()
testGitBuildcontextHelper(t, url)
}

// TestGitBuildcontextExplicitCommit uses an explicit commit hash instead of named reference
// Example:
// git://github.com/myuser/repo#b873088c4a7b60bb7e216289c58da945d0d771b6
func TestGitBuildcontextExplicitCommit(t *testing.T) {
repo := getGitRepo(t, true)
repo := getGitRepo(true)
testGitBuildcontextHelper(t, repo)
}

func TestGitBuildcontextSubPath(t *testing.T) {
repo := getGitRepo(t, false)
repo := getGitRepo(false)
dockerfile := "Dockerfile_test_run_2"

// Build with docker
Expand Down Expand Up @@ -361,7 +335,7 @@ func TestGitBuildcontextSubPath(t *testing.T) {
}

func TestBuildViaRegistryMirrors(t *testing.T) {
repo := getGitRepo(t, false)
repo := getGitRepo(false)
dockerfile := fmt.Sprintf("%s/%s/Dockerfile_registry_mirror", integrationPath, dockerfilesPath)

// Build with docker
Expand Down Expand Up @@ -401,7 +375,7 @@ func TestBuildViaRegistryMirrors(t *testing.T) {
}

func TestBuildWithLabels(t *testing.T) {
repo := getGitRepo(t, false)
repo := getGitRepo(false)
dockerfile := fmt.Sprintf("%s/%s/Dockerfile_test_label", integrationPath, dockerfilesPath)

testLabel := "mylabel=myvalue"
Expand Down Expand Up @@ -444,7 +418,7 @@ func TestBuildWithLabels(t *testing.T) {
}

func TestBuildWithHTTPError(t *testing.T) {
repo := getGitRepo(t, false)
repo := getGitRepo(false)
dockerfile := fmt.Sprintf("%s/%s/Dockerfile_test_add_404", integrationPath, dockerfilesPath)

// Build with docker
Expand Down
25 changes: 0 additions & 25 deletions scripts/travis-setup.sh

This file was deleted.

0 comments on commit 59c2d2d

Please sign in to comment.