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

Panic: index out of range when stage alias has the same name as base image #934

Closed
DGollings opened this issue Dec 25, 2019 · 3 comments · Fixed by #3245
Closed

Panic: index out of range when stage alias has the same name as base image #934

DGollings opened this issue Dec 25, 2019 · 3 comments · Fixed by #3245
Labels
area/dockerfile-command For all bugs related to dockerfile file commands kind/bug Something isn't working priority/p3 agreed that this would be good to have, but no one is available at the moment. work-around-available

Comments

@DGollings
Copy link

DGollings commented Dec 25, 2019

Actual behavior
A clear and concise description of what the bug is.

Kaniko panics with an index out of range when I think a image and alias are duplicates of each other. For example FROM composer AS composer

Removing AS composer fixed it

Output

INFO[0000] Resolved base name composer to composer      
INFO[0000] Resolved base name php:7.1-apache to php:7.1-apache 
INFO[0000] Resolved base name composer to composer      
INFO[0000] Resolved base name php:7.1-apache to php:7.1-apache 
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/GoogleContainerTools/kaniko/pkg/executor.CalculateDependencies(0x3082680, 0x2, 0x2, 0x3082680)
	/go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:442 +0xf12
github.com/GoogleContainerTools/kaniko/pkg/executor.DoBuild(0x3082680, 0x1, 0x0, 0x0, 0xc000624820)
	/go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:510 +0x1ca
github.com/GoogleContainerTools/kaniko/cmd/executor/cmd.glob..func2(0x3071a40, 0xc0005356e0, 0x0, 0x6)
	/go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/cmd/root.go:95 +0x11b
github.com/spf13/cobra.(*Command).execute(0x3071a40, 0xc00003a080, 0x6, 0x6, 0x3071a40, 0xc00003a080)

	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:766 +0x2ae
github.com/spf13/cobra.(*Command).ExecuteC(0x3071a40, 0x18063cd, 0xc0004fff88, 0xc000046178)
	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:800
main.main()
	/go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/main.go:26 +0x2e

Expected behavior
A clear and concise description of what you expected to happen.

Not crash

To Reproduce
Steps to reproduce the behavior:

  1. Create a dockerfile with the image and alias name being identical (ignoring why you would ever do this)
  2. Try and build it

Additional Information

  • Dockerfile
    FROM composer AS composer
    # rest doesnt matter

  • Kaniko Image (fully qualified with digest)
    Didn't specify, I assume latest as of 2019-12-25
    gcr.io/kaniko-project/executor:debug

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [no]
Please check if the build works in docker but not in kaniko
  • - [yes]
Please check if this error is seen when you use --cache flag
  • - [n/a]
Please check if your dockerfile is a multistage dockerfile
  • - [yes]
@cvgw cvgw changed the title Kaniko Panic: index out of range when stage alias has the same name as base image Dec 27, 2019
@cvgw cvgw added area/dockerfile-command For all bugs related to dockerfile file commands kind/bug Something isn't working labels Dec 27, 2019
@tejal29 tejal29 added this to the GA Release v1.0.0 milestone Jan 10, 2020
@tejal29 tejal29 added work-around-available priority/p3 agreed that this would be good to have, but no one is available at the moment. labels Jan 10, 2020
@MyIgel
Copy link
Contributor

MyIgel commented Jul 10, 2021

Alternatively: change it to FROM composer:latest AS composer

@mickvangelderen
Copy link
Contributor

mickvangelderen commented Jul 10, 2024

Reproduction on v1.23.2:

echo -e 'FROM scratch AS scratch' > Dockerfile | tar -cf - Dockerfile | gzip -9 | docker run \
  --interactive -v $(pwd):/workspace gcr.io/kaniko-project/executor:v1.23.2 \
  --context tar://stdin \
  --no-push

Emits:

INFO[0000] To simulate EOF and exit, press 'Ctrl+D'     
INFO[0000] Resolved base name scratch to scratch        
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running, locked to thread]:
github.com/GoogleContainerTools/kaniko/pkg/executor.CalculateDependencies({0xc0004260b0, 0x1, 0xc0003c3878?}, 0x2806b80, 0xc000796270)
	/src/pkg/executor/build.go:637 +0xc7a
github.com/GoogleContainerTools/kaniko/pkg/executor.DoBuild(0x2806b80)
	/src/pkg/executor/build.go:717 +0x225
github.com/GoogleContainerTools/kaniko/cmd/executor/cmd.init.func2(0xc00050ea00?, {0x196b03d?, 0x4?, 0x196b041?})
	/src/cmd/executor/cmd/root.go:190 +0x1b1
github.com/spf13/cobra.(*Command).execute(0x27f2540, {0xc000144050, 0x3, 0x3})
	/src/vendor/github.com/spf13/cobra/command.go:989 +0xab1
github.com/spf13/cobra.(*Command).ExecuteC(0x27f2540)
	/src/vendor/github.com/spf13/cobra/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0x197683e?)
	/src/vendor/github.com/spf13/cobra/command.go:1041 +0x13
main.main()
	/src/cmd/executor/main.go:31 +0x65

Array access

Maybe baseImageIndex should not be able to resolve to itself. Currently it can return the current stage index, but it should maybe already stop when i >= currentStage instead of i > currentStage.

mickvangelderen added a commit to mickvangelderen/kaniko that referenced this issue Jul 10, 2024
mickvangelderen added a commit to mickvangelderen/kaniko that referenced this issue Jul 10, 2024
@mickvangelderen
Copy link
Contributor

I created #3245 with this 1 character change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dockerfile-command For all bugs related to dockerfile file commands kind/bug Something isn't working priority/p3 agreed that this would be good to have, but no one is available at the moment. work-around-available
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants