diff --git a/.github/workflows/integration-k8s-tests.yaml b/.github/workflows/integration-k8s-tests.yaml deleted file mode 100644 index ee491b8fa9..0000000000 --- a/.github/workflows/integration-k8s-tests.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Integration tests (K8s) - -on: - pull_request: - branches: ['master'] - -concurrency: - group: int-test-k8s-${{ github.head_ref }} - cancel-in-progress: true - -jobs: - tests: - env: - IMAGE_REPO: 'localhost:5000' - REGISTRY: 'localhost:5000' - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - - name: Run build-image-and-k8s-integration-test - run: | - make travis-setup - make minikube-setup - make k8s-executor-build-push - make integration-test-k8s diff --git a/.github/workflows/integration-layers-tests.yaml b/.github/workflows/integration-layers-tests.yaml deleted file mode 100644 index 39b3c0634b..0000000000 --- a/.github/workflows/integration-layers-tests.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Integration tests (Layers) - -on: - pull_request: - branches: ['master'] - -concurrency: - group: int-test-layers-${{ github.head_ref }} - cancel-in-progress: true - -jobs: - tests: - env: - IMAGE_REPO: 'localhost:5000' - REGISTRY: 'localhost:5000' - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - - name: Run integration-test-layers - run: | - make travis-setup - make minikube-setup - make integration-test-layers diff --git a/.github/workflows/integration-misc.yaml b/.github/workflows/integration-misc.yaml deleted file mode 100644 index 9441206946..0000000000 --- a/.github/workflows/integration-misc.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: Integration Tests Misc - -on: - pull_request: - branches: ['master'] - -concurrency: - group: int-test-mis-${{ github.head_ref }} - cancel-in-progress: true - -jobs: - tests: - 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: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - - 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 minikube-setup - make integration-test-misc diff --git a/.github/workflows/integration-run-tests.yaml b/.github/workflows/integration-run-tests.yaml deleted file mode 100644 index f04b076a7d..0000000000 --- a/.github/workflows/integration-run-tests.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Integration tests (Run) - -on: - pull_request: - branches: ['master'] - -concurrency: - group: int-test-run-${{ github.head_ref }} - cancel-in-progress: true - -jobs: - tests: - env: - IMAGE_REPO: 'localhost:5000' - REGISTRY: 'localhost:5000' - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - - name: Run integration-test-run - run: | - make travis-setup - make minikube-setup - make integration-test-run diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml new file mode 100644 index 0000000000..48dee19e94 --- /dev/null +++ b/.github/workflows/integration-tests.yaml @@ -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 }} diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index e11903b001..8556416c84 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -1,6 +1,8 @@ name: Unit tests on: + push: + branches: ['master'] pull_request: branches: ['master'] diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index b96df47ed1..015c311e6d 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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 diff --git a/Makefile b/Makefile index bfdbffc2e8..1a3b87c5d9 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 827eee2893..73f83d298c 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/integration/integration_test.go b/integration/integration_test.go index 9093020c99..f311be779a 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -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" @@ -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 } @@ -296,7 +270,7 @@ 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) } @@ -304,20 +278,20 @@ func TestGitBuildcontext(t *testing.T) { // 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 @@ -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 @@ -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" @@ -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 diff --git a/scripts/travis-setup.sh b/scripts/travis-setup.sh deleted file mode 100755 index 38f0d84282..0000000000 --- a/scripts/travis-setup.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# Copyright 2020 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 - -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 - -mkdir -p $HOME/.docker/ -echo '{}' > $HOME/.docker/config.json