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 bug in SaveStage function for multistage builds #295

Merged
merged 1 commit into from
Aug 21, 2018
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
6 changes: 4 additions & 2 deletions pkg/dockerfile/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func SaveStage(index int, stages []instructions.Stage) bool {
if stageIndex <= index {
continue
}
if stage.Name == stages[index].BaseName {
return true
if stage.BaseName == stages[index].Name {
if stage.BaseName != "" {
return true
}
}
for _, cmd := range stage.Commands {
switch c := cmd.(type) {
Expand Down
28 changes: 28 additions & 0 deletions pkg/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func Test_SaveStage(t *testing.T) {

FROM scratch
COPY --from=second /hi2 /hi3

FROM ubuntu:16.04 AS base
ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8

FROM base AS development
ENV PS1 " 🐳 \[\033[1;36m\]\W\[\033[0;35m\] # \[\033[0m\]"

FROM development AS test
ENV ORG_ENV UnitTest

FROM base AS production
COPY . /code
`,
}
if err := testutil.SetupFiles(tempDir, files); err != nil {
Expand Down Expand Up @@ -142,6 +155,21 @@ func Test_SaveStage(t *testing.T) {
index: 2,
expected: false,
},
{
name: "reference current stage in next stage",
index: 4,
expected: true,
},
{
name: "from prebuilt stage, and reference current stage in next stage",
index: 5,
expected: true,
},
{
name: "final stage",
index: 6,
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down