Files
kaniko/pkg/buildcontext/https.go
T
Joël Pepper 14ea7c4071 Fix Integration tests (#2425)
* fix(ci): Bump golangci-lint to 1.51.1

* chore(lint): fix gofmt and goimport issues

* chore(lint): fix linter issues

- Adapted error comparison according to linter recommendation
- Disabled noctx linting for http request where canceling makes no sense
- Disabled nilerror linting where nil error is returned on purpose
- Disabled makezero linter where slice is explicitly deepcopied

* chore(ci): Update go version in tests workflows

* fix(ci): Allow boilerplate years from 2000-2099

Previously the regex only allowed the copyright notice to contain the
years 2018,2019,2020,2021, or 2022. This commit widens to regex to
20\d\d allowing any year in the range [2000-2099]

* feat(ci): Replace minikube with k3s for intregration tests

The existing setup for minikube is very complicated, replicating most of
the setup steps for a full kubernetes cluster in an only partially
supported minikube configuration (driver=none). Furthermore the existing
setup has been broken for sometime, likely, at least in part due to the
changes to CNI and CRI in recent kubernetes versions.

Since what we actually need is only a running Kubernetes cluster on the
node and access to a registry on localhost:5000, we can switch the
extremely complicated minikube setup for a lightweight cluster using
k3s. Minikube came with a default addon for running a registry on every
node, but the same is not the case for k3s, instead we make use of the
package helm controller and its HelmChart CR to deploy twuni/docker-registry.helm
and expose it on localhost using the integrated LoadBalancer controller.

* fix(test-684): pin base container version

The dockerfile for the regression test connected to issue 684 used a
rolling tag as base image, making it flaky and fail since it was
introduced.

This commit pins the base image to the digest of bionic-20200219, which,
based on the date of the commit that introduced to the dockerfile would
be the most newest ubuntu build and likely what the "rolling" tag
resolved to back then. Since this also an image from the pre-oci days of
ubuntu, this circumvents a bug in container-diff as well
(https://github.com/GoogleContainerTools/container-diff/issues/389)
2023-03-21 12:30:54 -04:00

81 lines
2.1 KiB
Go

/*
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 buildcontext
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/sirupsen/logrus"
)
// HTTPSTar struct for https tar.gz files processing
type HTTPSTar struct {
context string
}
// UnpackTarFromBuildContext downloads context file from https server
func (h *HTTPSTar) UnpackTarFromBuildContext() (directory string, err error) {
logrus.Info("Retrieving https tar file")
// Create directory and target file for downloading the context file
directory = kConfig.BuildContextDir
tarPath := filepath.Join(directory, constants.ContextTar)
file, err := util.CreateTargetTarfile(tarPath)
if err != nil {
return
}
// Download tar file from remote https server
// and save it into the target tar file
resp, err := http.Get(h.context) //nolint:noctx
if err != nil {
return
}
defer func() {
if closeErr := resp.Body.Close(); err == nil && closeErr != nil {
err = closeErr
}
}()
if resp.StatusCode != http.StatusOK {
return directory, fmt.Errorf("HTTPSTar bad status from server: %s", resp.Status)
}
if _, err = io.Copy(file, resp.Body); err != nil {
return tarPath, err
}
logrus.Info("Retrieved https tar file")
if err = util.UnpackCompressedTar(tarPath, directory); err != nil {
return
}
logrus.Info("Extracted https tar file")
// Remove the tar so it doesn't interfere with subsequent commands
return directory, os.Remove(tarPath)
}