Merge pull request #295 from priyawadhwa/multistage
Fix bug in SaveStage function for multistage builds
This commit is contained in:
commit
8f71b7fb26
|
|
@ -116,9 +116,11 @@ func SaveStage(index int, stages []instructions.Stage) bool {
|
||||||
if stageIndex <= index {
|
if stageIndex <= index {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if stage.Name == stages[index].BaseName {
|
if stage.BaseName == stages[index].Name {
|
||||||
|
if stage.BaseName != "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for _, cmd := range stage.Commands {
|
for _, cmd := range stage.Commands {
|
||||||
switch c := cmd.(type) {
|
switch c := cmd.(type) {
|
||||||
case *instructions.CopyCommand:
|
case *instructions.CopyCommand:
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,19 @@ func Test_SaveStage(t *testing.T) {
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=second /hi2 /hi3
|
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 {
|
if err := testutil.SetupFiles(tempDir, files); err != nil {
|
||||||
|
|
@ -142,6 +155,21 @@ func Test_SaveStage(t *testing.T) {
|
||||||
index: 2,
|
index: 2,
|
||||||
expected: false,
|
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 {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue