kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

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

Open slayer opened this issue 5 years ago • 14 comments

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

slayer avatar May 19 '20 10:05 slayer

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

tejal29 avatar May 20 '20 16:05 tejal29

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

slayer avatar May 21 '20 10:05 slayer

@tejal29 should I take a look at this ?

Tazminia avatar May 25 '20 13:05 Tazminia

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/

runzexia avatar Jun 22 '20 12:06 runzexia

@tejal29 should I take a look at this ?

Please do @Tazminia . Would appreciate any help here.

tejal29 avatar Jun 22 '20 21:06 tejal29

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

iclass-brian avatar Oct 14 '20 09:10 iclass-brian

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 avatar Nov 13 '20 12:11 gstolz

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

gstolz avatar Nov 19 '20 20:11 gstolz

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

dankeder avatar Sep 21 '21 10:09 dankeder

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.

neumantm avatar Sep 29 '21 13:09 neumantm

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

vijal-patel avatar Oct 13 '22 08:10 vijal-patel

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

dimaulupov avatar Nov 07 '23 13:11 dimaulupov

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/*

ashish1099 avatar Nov 13 '23 06:11 ashish1099

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

bouaouda-achraf avatar Oct 01 '24 10:10 bouaouda-achraf