From c825422ea1d2f97b04eae0fdd525a2ceb82ee8f1 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Fri, 30 Jun 2023 14:46:55 +0000 Subject: [PATCH] Add `DockerfileContent` to allow for an in-memory Dockerfile to be consumed --- pkg/config/options.go | 1 + pkg/dockerfile/dockerfile.go | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/config/options.go b/pkg/config/options.go index 20ec6174c4..5fa38776a8 100644 --- a/pkg/config/options.go +++ b/pkg/config/options.go @@ -53,6 +53,7 @@ type KanikoOptions struct { Git KanikoGitOptions IgnorePaths multiArg DockerfilePath string + DockerfileContent string SrcContext string SnapshotMode string SnapshotModeDeprecated string diff --git a/pkg/dockerfile/dockerfile.go b/pkg/dockerfile/dockerfile.go index 6b317d3443..f31802d487 100644 --- a/pkg/dockerfile/dockerfile.go +++ b/pkg/dockerfile/dockerfile.go @@ -38,16 +38,21 @@ import ( func ParseStages(opts *config.KanikoOptions) ([]instructions.Stage, []instructions.ArgCommand, error) { var err error var d []uint8 - match, _ := regexp.MatchString("^https?://", opts.DockerfilePath) - if match { - response, e := http.Get(opts.DockerfilePath) //nolint:noctx - if e != nil { - return nil, nil, e - } - d, err = ioutil.ReadAll(response.Body) + if opts.DockerfileContent != "" { + d = []uint8(opts.DockerfileContent) } else { - d, err = ioutil.ReadFile(opts.DockerfilePath) + match, _ := regexp.MatchString("^https?://", opts.DockerfilePath) + if match { + response, e := http.Get(opts.DockerfilePath) //nolint:noctx + if e != nil { + return nil, nil, e + } + d, err = ioutil.ReadAll(response.Body) + } else { + d, err = ioutil.ReadFile(opts.DockerfilePath) + } } + if err != nil { return nil, nil, errors.Wrap(err, fmt.Sprintf("reading dockerfile at path %s", opts.DockerfilePath))