GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
14.93k stars 1.62k forks source link

Kaniko builder TarGz fails when Dockerfile is in sub-directory #1611

Closed fpighi closed 5 years ago

fpighi commented 5 years ago

I've started using Skaffold very recently, so it might be something I'm doing wrong. Please correct me if so.

Expected behavior

Kaniko build works with examples/microservices/skaffold.yaml.

Actual behavior

Kaniko builder tar.gz path handling seems to be wrong when the context is not the same directory as the workspace.

The failure is as follows on my machine:

~/go/src/github.com/GoogleContainerTools/skaffold/examples/microservices $ skaffold build -v debug                                                                                       
INFO[0000] Skaffold &{Version:v0.22.0 ConfigVersion:skaffold/v1beta4 GitVersion: GitCommit:2187105aae414f500789ca6873898efeb104d7a7 GitTreeState:clean BuildDate:2019-01-31T22:53:12Z GoVersion:go1.10.8 Compiler:g
c Platform:linux/amd64}
INFO[0000] no config entry found for kube-context minikube                                                                                                                                                        
INFO[0000] Using kubectl context: minikube
INFO[0000] no config entry found for kube-context minikube                                                                                                                                                        
DEBU[0000] Using builder: kaniko                                                        
Starting build...
Creating kaniko secret [aws-secret]...
DEBU[0000] No pull secret specified. Checking for one in the cluster.
Building [gcr.io/k8s-skaffold/leeroy-web]...
Storing build context at /tmp/context-dd8cce3a8e0f4b1897348447d9f4cd6a.tar.gz
DEBU[0000] Checking base image golang:1.10.1-alpine3.7 for ONBUILD triggers.
DEBU[0000] Checking base image golang:1.10.1-alpine3.7 for ONBUILD triggers.
DEBU[0000] Running command: [minikube docker-env --shell none]
DEBU[0000] Command output: [DOCKER_TLS_VERIFY=1
DOCKER_HOST=tcp://192.168.99.100:2376
DOCKER_CERT_PATH=/home/fpighi/.minikube/certs
DOCKER_API_VERSION=1.35
]
DEBU[0000] setting Docker user agent to skaffold-v0.22.0
DEBU[0000] Checking base image alpine:3.7 for ONBUILD triggers.
DEBU[0000] Checking base image alpine:3.7 for ONBUILD triggers.
DEBU[0000] Found dependencies for dockerfile: [app.go]
DEBU[0000] Found dependencies for dockerfile: [web.go]
FATA[0000] build failed: building [gcr.io/k8s-skaffold/leeroy-web]: kaniko build for [gcr.io/k8s-skaffold/leeroy-web]: setting up build context: creating tar gz: lstat /home/fpighi/go/src/github.com/GoogleContai
nerTools/skaffold/examples/microservices/leeroy-web/leeroy-web/Dockerfile: no such file or directory

Note the path on last line of the log is /home/fpighi/go/src/github.com/GoogleContai nerTools/skaffold/examples/microservices/leeroy-web/leeroy-web/Dockerfile

Information

apiVersion: skaffold/v1beta4
kind: Config
build:
  artifacts:
  - image: gcr.io/k8s-skaffold/leeroy-web
    context: ./leeroy-web/
  - image: gcr.io/k8s-skaffold/leeroy-app
    context: ./leeroy-app/
  kaniko:
    buildContext:
      localDir: {}
    pullSecretName: aws-secret
    namespace: default
deploy:
  kubectl:
    manifests:
    - ./leeroy-web/kubernetes/*
    - ./leeroy-app/kubernetes/*

Steps to reproduce the behavior

  1. Clone the repo
  2. cd into examples/microservices
  3. edit skaffold.yaml with the content pasted above (probably replacing the pullSecretName)
  4. run skaffold build -v debug
fpighi commented 5 years ago

Additional note: I reverted to v0.20.0 and that version seems to be working fine.

wstrange commented 5 years ago

I am seeing a similar issue with googleCloudBuild.

It only works if the Dockerfile is in the same directory as skaffold.yaml. If I specify a context: docker/ it looks like the path calculations append the context: directory twice. The tar command fails with:

/Users/redacted/tmp/forgeops-init/cicd/ig/docker/docker/Dockerfile . no such file or directory

FWIW, I am using a profile. I have tried various combinations of setting the context: (./docker, ../docker, omitting it, etc.) - and they all seem to fail

dgageot commented 5 years ago

Yes, I'm sure I broke something. Let me take a look.

dgageot commented 5 years ago

Sorry. A fix is coming soon. Until then, you can rollback to using Skaffold v0.20.0.