From e652f815efc5972fdb86f43be7618aaa925be3e7 Mon Sep 17 00:00:00 2001 From: cvgw Date: Mon, 20 Jan 2020 15:57:05 -0800 Subject: [PATCH] Fix #519 capital letter in stage names update stage code so that when comparing the BaseName of a stage against the recorded, lowercase version of a Stage name the BaseName is also lowercased. --- .../Dockerfile_test_from_multistage_capital | 13 +++++++++++++ pkg/dockerfile/dockerfile.go | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 integration/dockerfiles/Dockerfile_test_from_multistage_capital diff --git a/integration/dockerfiles/Dockerfile_test_from_multistage_capital b/integration/dockerfiles/Dockerfile_test_from_multistage_capital new file mode 100644 index 000000000..7bba24ad1 --- /dev/null +++ b/integration/dockerfiles/Dockerfile_test_from_multistage_capital @@ -0,0 +1,13 @@ +FROM alpine as base_stage + +RUN echo base_stage + + +FROM base_stage as BUG_stage + +RUN echo BUG_stage + + +FROM BUG_stage as final_stage + +RUN echo final_stage diff --git a/pkg/dockerfile/dockerfile.go b/pkg/dockerfile/dockerfile.go index 1f1314fb4..f41875c56 100644 --- a/pkg/dockerfile/dockerfile.go +++ b/pkg/dockerfile/dockerfile.go @@ -90,14 +90,17 @@ func Stages(opts *config.KanikoOptions) ([]config.KanikoStage, error) { // baseImageIndex returns the index of the stage the current stage is built off // returns -1 if the current stage isn't built off a previous stage func baseImageIndex(currentStage int, stages []instructions.Stage) int { + currentStageBaseName := strings.ToLower(stages[currentStage].BaseName) + for i, stage := range stages { if i > currentStage { break } - if stage.Name == stages[currentStage].BaseName { + if stage.Name == currentStageBaseName { return i } } + return -1 } @@ -245,15 +248,19 @@ func ParseCommands(cmdArray []string) ([]instructions.Command, error) { // SaveStage returns true if the current stage will be needed later in the Dockerfile func saveStage(index int, stages []instructions.Stage) bool { + currentStageName := stages[index].Name + for stageIndex, stage := range stages { if stageIndex <= index { continue } - if stage.BaseName == stages[index].Name { + + if strings.ToLower(stage.BaseName) == currentStageName { if stage.BaseName != "" { return true } } } + return false }