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: runtime error: index out of range [0] with length 0 #1271

Open
slayer opened this issue May 19, 2020 · 14 comments
Open

panic: runtime error: index out of range [0] with length 0 #1271

slayer opened this issue May 19, 2020 · 14 comments
Labels
area/behavior all bugs related to kaniko behavior like running in as root good first issue Good for newcomers help wanted Looking for a volunteer! 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

@slayer
Copy link

slayer commented May 19, 2020

Need to check slice size
https://github.com/GoogleContainerTools/kaniko/blob/master/pkg/executor/build.go#L516

 $ /kaniko/executor --dockerfile docker/Dockerfile-release --cache=true --context . --destination "${DOCKER_IMAGE?}-release"
 INFO[0000] Using dockerignore file: /builds/xxx/yyy/.dockerignore 
 panic: runtime error: index out of range [0] with length 0
 goroutine 1 [running]:
 github.com/GoogleContainerTools/kaniko/pkg/executor.CalculateDependencies(0xc0008fe090, 0x1, 0x1, 0x3133c00, 0xc0008a1530, 0x0, 0x1, 0xc0008fe090)
 	/go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:516 +0xfd4
 github.com/GoogleContainerTools/kaniko/pkg/executor.DoBuild(0x3133c00, 0x1, 0x0, 0x0, 0x7)
 	/go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:593 +0x241
 github.com/GoogleContainerTools/kaniko/cmd/executor/cmd.glob..func2(0x311c000, 0xc000146c40, 0x0, 0x7)
 	/go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/cmd/root.go:107 +0x12b
 github.com/spf13/cobra.(*Command).execute(0x311c000, 0xc00003a090, 0x7, 0x7, 0x311c000, 0xc00003a090)
 	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:830 +0x29d
 github.com/spf13/cobra.(*Command).ExecuteC(0x311c000, 0x0, 0x1a8f8a0, 0xc000042178)
 	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:914 +0x2fb
 github.com/spf13/cobra.(*Command).Execute(...)
 	/go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:864
 main.main()
 	/go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/main.go:26 +0x2d
@tejal29
Copy link
Member

tejal29 commented May 20, 2020

hmm this should not typically happen. Can you share your dockerfile.

@tejal29 tejal29 added good first issue Good for newcomers kind/bug Something isn't working labels May 20, 2020
@slayer
Copy link
Author

slayer commented May 21, 2020

Yes, actually it was happen when FROM is not defined properly

Dockerfile

ARG IMAGE
FROM ${IMAGE}

and additional --build-arg IMAGE=${DOCKER_IMAGE} solves the problem
but IMO error message can be more helpful

@Tazminia
Copy link

@tejal29 should I take a look at this ?

@runzexia
Copy link

I also encountered the same problem.
my dockerfile is

FROM debian as debian
RUN \
  export DEBIAN_FRONTEND=noninteractive &&\
  apt-get update &&\
  apt-get install -qq bash-static

FROM golang:1.13-alpine as builder
WORKDIR /workspace
COPY / /workspace/
RUN CGO_ENABLED=0 go install .

FROM alpine
ENTRYPOINT ["/khronos/khronos"]
EXPOSE 8080
COPY --from=debian /bin/bash-static /khronos/bash
COPY --from=builder /go/bin/khronos /khronos/

@tejal29
Copy link
Member

tejal29 commented Jun 22, 2020

@tejal29 should I take a look at this ?

Please do @Tazminia . Would appreciate any help here.

@tejal29 tejal29 added the help wanted Looking for a volunteer! label Jun 22, 2020
@tejal29 tejal29 added priority/p3 agreed that this would be good to have, but no one is available at the moment. area/behavior all bugs related to kaniko behavior like running in as root labels Aug 12, 2020
@iclass-brian
Copy link

I also encountered the same problem.
my dockerfile is

FROM debian as debian
RUN \
  export DEBIAN_FRONTEND=noninteractive &&\
  apt-get update &&\
  apt-get install -qq bash-static

FROM golang:1.13-alpine as builder
WORKDIR /workspace
COPY / /workspace/
RUN CGO_ENABLED=0 go install .

FROM alpine
ENTRYPOINT ["/khronos/khronos"]
EXPOSE 8080
COPY --from=debian /bin/bash-static /khronos/bash
COPY --from=builder /go/bin/khronos /khronos/

maybe the following line is the reason?

FROM debian as debian

In my case,
it works after I change FROM composer as composer to FROM composer to composerStage

@gstolz
Copy link

gstolz commented Nov 13, 2020

I'm having the same problem. Using ARG reference in multi-stage seems to be the problem:

  • ARG in single-FROM Dockerfile -> OK
  • ARG in multi-stage Dockerfile (NodeJS) -> Not OK
  • ARG in multi-stage Dockerfile (Go) -> Not OK

Dockerfile example:

FROM golang:1.15 as build
...
ARG BASE_IMAGE=ghcr.io/ironpeakservices/iron-scratch/iron-scratch:1.0.1
FROM ${BASE_IMAGE}
...

Log:
INFO[0001] Retrieving image golang:1.15 panic: runtime error: index out of range [1] with length 1 goroutine 1 [running]: github.com/GoogleContainerTools/kaniko/pkg/executor.CalculateDependencies(0xc000690900, 0x2, 0x2, 0x334ef00, 0xc0007dec60, 0x0, 0x0, 0x0) /go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:506 +0xfd4 github.com/GoogleContainerTools/kaniko/pkg/executor.DoBuild(0x334ef00, 0x1, 0x0, 0x0, 0xc00059a280) /go/src/github.com/GoogleContainerTools/kaniko/pkg/executor/build.go:584 +0x268 github.com/GoogleContainerTools/kaniko/cmd/executor/cmd.glob..func2(0x3336bc0, 0xc000156000, 0x1, 0xe) /go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/cmd/root.go:109 +0x11c github.com/spf13/cobra.(*Command).execute(0x3336bc0, 0xc00004c100, 0xe, 0xe, 0x3336bc0, 0xc00004c100) /go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:846 +0x29d github.com/spf13/cobra.(*Command).ExecuteC(0x3336bc0, 0x0, 0x1b78c20, 0xc00005a2f8) /go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:950 +0x349 github.com/spf13/cobra.(*Command).Execute(...) /go/src/github.com/GoogleContainerTools/kaniko/vendor/github.com/spf13/cobra/command.go:887 main.main() /go/src/github.com/GoogleContainerTools/kaniko/cmd/executor/main.go:26 +0x2d

It would be very helpful if this could be fixed, since this seems to be the easiest solution to setup hardened production images as well as comprehensive debugging images with just one Dockerfile!

@gstolz
Copy link

gstolz commented Nov 19, 2020

Sorry to say this, but in my case it was not a problem of Kaniko! I just did not properly specify the ARG in Dockerfile!
In multi-layer Dockerfile the scope needs to be taken care of as described in the docs and a Stackoverflow article:
https://stackoverflow.com/questions/53681522/multi-stage-dockerfile-arg-before-from-not-substituted
https://docs.docker.com/engine/reference/builder/#arg
https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact

@dankeder
Copy link

I encountered the same problem as well. In my case the problem was the FROM statement:

FROM nginx as nginx

A workaround that helped in my case was to use a tagged image:

FROM nginx:latest as nginx

@neumantm
Copy link

I have the same problem.
I'm using FROM composer as composer
The workaround mentioned by @dankeder worked, but I think this should be fixed.

@vijal-patel
Copy link

is this still an issue? I'm happy to work on it

@dimaulupov
Copy link

It is still happening.
If you have multi-stage build and have this:

FROM golang as golang

kaniko fails with this error.

But this line:

FROM golang as builder

works fine

@ashish1099
Copy link

I'm still seeing this issue, even without multistage build.
This is my Dockerfile, and I have tried the latest 1.18.0 and 1.9.1 (debug) images

FROM example.com/jammy-generic-build:1.0.0
MAINTAINER Ashish Jaiswal <[email protected]>

WORKDIR /tmp

RUN apt-get update \
    && \
    DEBIAN_FRONTEND=noninteractive \
    apt-get install -y \
    pandoc \
    texlive-xetex \
    && \
    apt-get autoremove -y \
    && \
    apt-get autoclean -y \

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN rm -fr /var/lib/apt/lists/*

@bouaouda-achraf
Copy link

Reproductible with :
--build-arg "XX=YY"
instead of :
--build-arg XX=YY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/behavior all bugs related to kaniko behavior like running in as root good first issue Good for newcomers help wanted Looking for a volunteer! 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

No branches or pull requests