Skip to content

Commit 580c773

Browse files
Allow referencing previous stages as source in FROM (#38)
Signed-off-by: Kathryn Baldauf <[email protected]>
1 parent 1941038 commit 580c773

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/build/frontend.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func resolveStates(ctx context.Context, bopts *BOpts, platform ocispecs.Platform
129129
states := map[string]stateMeta{}
130130
stateLock := sync.Mutex{}
131131

132-
for _, stage := range stages {
132+
for i, stage := range stages {
133133
wg.Add(1)
134134
go func(stage instructions.Stage) {
135135
defer wg.Done()
@@ -145,6 +145,12 @@ func resolveStates(ctx context.Context, bopts *BOpts, platform ocispecs.Platform
145145
return
146146
}
147147

148+
// if there's another stage with this name before the current stage, that will be used as the source
149+
namedIndex, hasNamedStage := instructions.HasStage(stages, resolvedBaseStageName.Result)
150+
if hasNamedStage && namedIndex < i {
151+
return
152+
}
153+
148154
ref, err := dref.ParseAnyReference(resolvedBaseStageName.Result)
149155
if err != nil {
150156
if err == reference.ErrObjectRequired {

0 commit comments

Comments
 (0)