mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-21 01:28:38 +02:00
feat: kaniko dir config option (#1997)
* remove configurables from constants * add configurables to config init * add kaniko dir flag * cleanup pkg constants * replace buildcontext constants pkg occurrences with config * add KanikoDir to KanikoOptions * replace executor constants pkg occurrences with config * remove redundant KanikoDir assignment * replace constants to config for IntermediateStagesDir * fix imports * add default kaniko directory into constants * add check for kanikoDir on use * update init to use default path constant * update executor kanikoDir check Co-authored-by: Jason Hall <jasonhall@redhat.com> * alter checkKanikoDir parameter * add TestKanikoDir func * update error handling style Co-authored-by: Jason Hall <jasonhall@redhat.com> * remove shorthand flag usage from test Co-authored-by: Jason Hall <jasonhall@redhat.com> * add docstring to integration test Co-authored-by: Jason Hall <jasonhall@redhat.com> * remove shorthand flag from kaniko-dir Co-authored-by: Jason Hall <jasonhall@redhat.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-storage-blob-go/azblob"
|
||||
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
)
|
||||
@@ -55,7 +56,7 @@ func (b *AzureBlob) UnpackTarFromBuildContext() (string, error) {
|
||||
}
|
||||
|
||||
// Create directory and target file for downloading the context file
|
||||
directory := constants.BuildContextDir
|
||||
directory := kConfig.BuildContextDir
|
||||
tarPath := filepath.Join(directory, constants.ContextTar)
|
||||
file, err := util.CreateTargetTarfile(tarPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -36,7 +37,7 @@ type GCS struct {
|
||||
|
||||
func (g *GCS) UnpackTarFromBuildContext() (string, error) {
|
||||
bucket, item := util.GetBucketAndItem(g.context)
|
||||
return constants.BuildContextDir, unpackTarFromGCSBucket(bucket, item, constants.BuildContextDir)
|
||||
return kConfig.BuildContextDir, unpackTarFromGCSBucket(bucket, item, kConfig.BuildContextDir)
|
||||
}
|
||||
|
||||
func UploadToBucket(r io.Reader, dest string) error {
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
"github.com/go-git/go-billy/v5/osfs"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
@@ -31,8 +32,6 @@ import (
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/storage/filesystem"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,7 +56,7 @@ type Git struct {
|
||||
|
||||
// UnpackTarFromBuildContext will provide the directory where Git Repository is Cloned
|
||||
func (g *Git) UnpackTarFromBuildContext() (string, error) {
|
||||
directory := constants.BuildContextDir
|
||||
directory := kConfig.BuildContextDir
|
||||
parts := strings.Split(g.context, "#")
|
||||
url := getGitPullMethod() + "://" + parts[0]
|
||||
options := git.CloneOptions{
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"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"
|
||||
@@ -39,7 +40,7 @@ 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 = constants.BuildContextDir
|
||||
directory = kConfig.BuildContextDir
|
||||
tarPath := filepath.Join(directory, constants.ContextTar)
|
||||
file, err := util.CreateTargetTarfile(tarPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
@@ -56,7 +57,7 @@ func (s *S3) UnpackTarFromBuildContext() (string, error) {
|
||||
return bucket, err
|
||||
}
|
||||
downloader := s3manager.NewDownloader(sess)
|
||||
directory := constants.BuildContextDir
|
||||
directory := kConfig.BuildContextDir
|
||||
tarPath := filepath.Join(directory, constants.ContextTar)
|
||||
if err := os.MkdirAll(directory, 0750); err != nil {
|
||||
return directory, err
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
kConfig "github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -34,7 +34,7 @@ type Tar struct {
|
||||
|
||||
// UnpackTarFromBuildContext unpack the compressed tar file
|
||||
func (t *Tar) UnpackTarFromBuildContext() (string, error) {
|
||||
directory := constants.BuildContextDir
|
||||
directory := kConfig.BuildContextDir
|
||||
if err := os.MkdirAll(directory, 0750); err != nil {
|
||||
return "", errors.Wrap(err, "unpacking tar from build context")
|
||||
}
|
||||
|
||||
+23
-2
@@ -17,15 +17,36 @@ limitations under the License.
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
)
|
||||
|
||||
var RootDir string
|
||||
var KanikoDir string
|
||||
|
||||
// KanikoDir is the path to the Kaniko directory
|
||||
var KanikoDir = func() string {
|
||||
if kd, ok := os.LookupEnv("KANIKO_DIR"); ok {
|
||||
return kd
|
||||
}
|
||||
return constants.DefaultKanikoPath
|
||||
}()
|
||||
|
||||
// DockerfilePath is the path the Dockerfile is copied to
|
||||
var DockerfilePath = fmt.Sprintf("%s/Dockerfile", KanikoDir)
|
||||
|
||||
// BuildContextDir is the directory a build context will be unpacked into,
|
||||
// for example, a tarball from a GCS bucket will be unpacked here
|
||||
var BuildContextDir = fmt.Sprintf("%s/buildcontext/", KanikoDir)
|
||||
|
||||
// KanikoIntermediateStagesDir is where we will store intermediate stages
|
||||
// as tarballs in case they are needed later on
|
||||
var KanikoIntermediateStagesDir = fmt.Sprintf("%s/stages/", KanikoDir)
|
||||
|
||||
var IgnoreListPath string
|
||||
|
||||
func init() {
|
||||
RootDir = constants.RootDir
|
||||
KanikoDir = constants.KanikoDir
|
||||
IgnoreListPath = constants.IgnoreListPath
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ type KanikoOptions struct {
|
||||
CustomPlatform string
|
||||
Bucket string
|
||||
TarPath string
|
||||
KanikoDir string
|
||||
Target string
|
||||
CacheRepo string
|
||||
DigestFile string
|
||||
|
||||
@@ -20,27 +20,15 @@ const (
|
||||
// RootDir is the path to the root directory
|
||||
RootDir = "/"
|
||||
|
||||
// KanikoDir is the path to the Kaniko directory
|
||||
KanikoDir = "/kaniko"
|
||||
|
||||
IgnoreListPath = "/proc/self/mountinfo"
|
||||
|
||||
DefaultKanikoPath = "/kaniko"
|
||||
|
||||
Author = "kaniko"
|
||||
|
||||
// DockerfilePath is the path the Dockerfile is copied to
|
||||
DockerfilePath = "/kaniko/Dockerfile"
|
||||
|
||||
// ContextTar is the default name of the tar uploaded to GCS buckets
|
||||
ContextTar = "context.tar.gz"
|
||||
|
||||
// BuildContextDir is the directory a build context will be unpacked into,
|
||||
// for example, a tarball from a GCS bucket will be unpacked here
|
||||
BuildContextDir = "/kaniko/buildcontext/"
|
||||
|
||||
// KanikoIntermediateStagesDir is where we will store intermediate stages
|
||||
// as tarballs in case they are needed later on
|
||||
KanikoIntermediateStagesDir = "/kaniko/stages"
|
||||
|
||||
// Various snapshot modes:
|
||||
SnapshotModeTime = "time"
|
||||
SnapshotModeFull = "full"
|
||||
|
||||
@@ -829,7 +829,7 @@ func saveStageAsTarball(path string, image v1.Image) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tarPath := filepath.Join(constants.KanikoIntermediateStagesDir, path)
|
||||
tarPath := filepath.Join(config.KanikoIntermediateStagesDir, path)
|
||||
logrus.Infof("Storing source image from stage %s at path %s", path, tarPath)
|
||||
if err := os.MkdirAll(filepath.Dir(tarPath), 0750); err != nil {
|
||||
return err
|
||||
|
||||
@@ -177,7 +177,6 @@ func setupMultistageTests(t *testing.T) (string, func()) {
|
||||
}
|
||||
config.IgnoreListPath = mFile
|
||||
return testDir, func() {
|
||||
config.KanikoDir = constants.KanikoDir
|
||||
config.RootDir = constants.RootDir
|
||||
config.IgnoreListPath = constants.IgnoreListPath
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func RetrieveSourceImage(stage config.KanikoStage, opts *config.KanikoOptions) (
|
||||
}
|
||||
|
||||
func tarballImage(index int) (v1.Image, error) {
|
||||
tarPath := filepath.Join(constants.KanikoIntermediateStagesDir, strconv.Itoa(index))
|
||||
tarPath := filepath.Join(config.KanikoIntermediateStagesDir, strconv.Itoa(index))
|
||||
logrus.Infof("Base image from previous stage %d found, using saved tar at path %s", index, tarPath)
|
||||
return tarball.ImageFromPath(tarPath, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user