2

Building the following Dockerfile on GitLab CI using Kaniko, result in the error error pushing image: failed to push to destination eu.gcr.io/stritzke-enterprises/eliah-speech-server:latest: Get https://eu.gcr.io/...: exit status 1

If I remove the first FROM, RUN and COPY --from statements from the Dockerfile, the Docker Image is built and pushed as expected. If I execute the Kaniko build using Docker on my local machine everything works as expected. I execute other Kaniko builds and pushed on the same GitLab CI runner with the same GCE Service Account credentials.

What is going wrong with the GitLab CI based Kaniko build?

Dockerfile

FROM alpine:latest as alpine

RUN apk add -U --no-cache ca-certificates

FROM scratch

COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

COPY binaries/speech-server /speech-server

EXPOSE 8080
ENTRYPOINT ["/speech-server"]
CMD ["serve", "-t", "$GOOGLE_ACCESS_TOKEN"]

GitLab CI build stage

buildDockerImage:
  stage: buildImage
  dependencies:
    - build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  variables:
    GOOGLE_APPLICATION_CREDENTIALS: /secret.json
  script:
    - echo "$GCR_SERVICE_ACCOUNT_KEY" > /secret.json
    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $DOCKER_IMAGE:latest -v debug
  only:
    - branches
  except:
    - master
Dennis Stritzke
  • 5,198
  • 1
  • 19
  • 28
  • Is this still a problem for you? I can build multi-stage images without problems, so I assume the issue for you was credentials. – tdensmore Jul 29 '19 at 16:19
  • 1
    Eight months after asking, I definitely agree with your assumption. Posted an answer to maybe help diagnosing issues of other people who come here. – Dennis Stritzke Aug 05 '19 at 18:22

1 Answers1

2

As tdensmore pointed out this was most likely an authentication issue.

So for everyone who has come here, the following Dockerfile and Kaniko call work just fine.

FROM ubuntu:latest as ubuntu

RUN echo "Foo" > /foo.txt

FROM ubuntu:latest

COPY --from=ubuntu /foo.txt /

CMD ["/bin/cat", "/foo.txt"]

The Dockerfile can be built by running

docker run -v $(pwd):/workspace gcr.io/kaniko-project/executor:latest --context /workspace --no-push
Dennis Stritzke
  • 5,198
  • 1
  • 19
  • 28