Merge pull request #32997 from dnephin/fix-builder-scratch-with-name
Fix a rare case where using FROM scratch as NAME would fail
This commit is contained in:
commit
543dfde637
2 changed files with 20 additions and 3 deletions
|
@ -200,7 +200,11 @@ func from(req dispatchRequest) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if image != nil {
|
||||
switch image {
|
||||
case nil:
|
||||
req.state.imageID = ""
|
||||
req.state.noBaseImage = true
|
||||
default:
|
||||
req.builder.imageContexts.update(image.ImageID(), image.RunConfig())
|
||||
}
|
||||
req.state.baseImage = image
|
||||
|
@ -248,8 +252,6 @@ func (b *Builder) getFromImage(dispatchState *dispatchState, shlex *ShellLex, na
|
|||
if runtime.GOOS == "windows" {
|
||||
return nil, errors.New("Windows does not support FROM scratch")
|
||||
}
|
||||
dispatchState.imageID = ""
|
||||
dispatchState.noBaseImage = true
|
||||
return nil, nil
|
||||
}
|
||||
return pullOrGetImage(b, name)
|
||||
|
|
|
@ -233,6 +233,21 @@ func TestFromWithUndefinedArg(t *testing.T) {
|
|||
assert.Equal(t, expected, req.state.imageID)
|
||||
}
|
||||
|
||||
func TestFromMultiStageWithScratchNamedStage(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("Windows does not support scratch")
|
||||
}
|
||||
b := newBuilderWithMockBackend()
|
||||
req := defaultDispatchReq(b, "scratch", "AS", "base")
|
||||
|
||||
require.NoError(t, from(req))
|
||||
assert.True(t, req.state.hasFromImage())
|
||||
|
||||
req.args = []string{"base"}
|
||||
require.NoError(t, from(req))
|
||||
assert.True(t, req.state.hasFromImage())
|
||||
}
|
||||
|
||||
func TestOnbuildIllegalTriggers(t *testing.T) {
|
||||
triggers := []struct{ command, expectedError string }{
|
||||
{"ONBUILD", "Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed"},
|
||||
|
|
Loading…
Add table
Reference in a new issue