mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 09:28:02 +02:00
Feature/contextsources (#195)
* added switch to extract different sources as build context * first rough implementation of aws s3 * added buildcontext package and interface * added GetBuildContext func to buildcontext.go added fallback to gcs renamed GC struct to GCS * improved the default behavior of build context retrieval * renamed gc:// to gs:// in order to follow common standards * renamed struct File to Dir and some cleanup work * moved context.tar suffix to the buildcontext processors where it is needed * added buildcontext retrieval as struct variable added fallback if prefix in bucket specifier is present * cleanup if structures * added prefix to s3 * WIP * Fixed build context bugs * refactored build context
This commit is contained in:
committed by
priyawadhwa
parent
7e437390af
commit
65d7b0a9aa
@@ -20,7 +20,9 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/buildcontext"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/executor"
|
||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||
@@ -121,21 +123,32 @@ func checkDockerfilePath() error {
|
||||
return errors.New("please provide a valid path to a Dockerfile within the build context")
|
||||
}
|
||||
|
||||
// resolveSourceContext unpacks the source context if it is a tar in a GCS bucket
|
||||
// resolveSourceContext unpacks the source context if it is a tar in a bucket
|
||||
// it resets srcContext to be the path to the unpacked build context within the image
|
||||
func resolveSourceContext() error {
|
||||
if srcContext == "" && bucket == "" {
|
||||
return errors.New("please specify a path to the build context with the --context flag or a GCS bucket with the --bucket flag")
|
||||
return errors.New("please specify a path to the build context with the --context flag or a bucket with the --bucket flag")
|
||||
}
|
||||
if bucket == "" {
|
||||
if srcContext != "" && !strings.Contains(srcContext, "://") {
|
||||
return nil
|
||||
}
|
||||
logrus.Infof("Using GCS bucket %s as source context", bucket)
|
||||
buildContextPath := constants.BuildContextDir
|
||||
if err := util.UnpackTarFromGCSBucket(bucket, buildContextPath); err != nil {
|
||||
if bucket != "" {
|
||||
if !strings.Contains(bucket, "://") {
|
||||
srcContext = constants.GCSBuildContextPrefix + bucket
|
||||
} else {
|
||||
srcContext = bucket
|
||||
}
|
||||
}
|
||||
// if no prefix use Google Cloud Storage as default for backwards compability
|
||||
contextExecutor, err := buildcontext.GetBuildContext(srcContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("Unpacked tar from %s to path %s", bucket, buildContextPath)
|
||||
srcContext = buildContextPath
|
||||
logrus.Debugf("Getting source context from %s", srcContext)
|
||||
srcContext, err = contextExecutor.UnpackTarFromBuildContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("Build context located at %s", srcContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user