Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #519 capital letter in stage names #983

Merged
merged 1 commit into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions integration/dockerfiles/Dockerfile_test_from_multistage_capital
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions pkg/dockerfile/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}