Skip to content

Commit

Permalink
added switch to extract different sources as build context
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisz100 committed May 27, 2018
1 parent 7c5fa3b commit dc063fe
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"

"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/executor"
Expand Down Expand Up @@ -114,17 +115,34 @@ func checkDockerfilePath() error {
// 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 == "" {

buildContextPath := constants.BuildContextDir

if !strings.Contains(bucket, "://") {
return nil
}
logrus.Infof("Using GCS bucket %s as source context", bucket)
buildContextPath := constants.BuildContextDir
if err := util.UnpackTarFromGCSBucket(bucket, buildContextPath); err != nil {
return err

if strings.HasPrefix(bucket, "file://") {
logrus.Infof("Using local file %s as source context", bucket)
srcContext = strings.TrimPrefix(bucket, "file://")
return nil
}
logrus.Debugf("Unpacked tar from %s to path %s", bucket, buildContextPath)

if strings.HasPrefix(bucket, "gs://") {
logrus.Infof("Using GCS bucket %s as source context", bucket)
if err := util.UnpackTarFromGCSBucket(bucket, buildContextPath); err != nil {
return err
}
logrus.Debugf("Unpacked tar from %s to path %s", bucket, buildContextPath)
}

if strings.HasPrefix(bucket, "s3://") {
logrus.Infof("Using AWS bucket %s as source context", bucket)
return errors.New("AWS S3 is not yet implemented")
}

srcContext = buildContextPath
return nil
}

0 comments on commit dc063fe

Please sign in to comment.