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

skaffold doesn't support COPY with wildcard that does not match anything #741

Closed
jstrachan opened this issue Jun 25, 2018 · 2 comments
Closed
Assignees
Labels
build/docker kind/bug Something isn't working

Comments

@jstrachan
Copy link
Contributor

Just found another minor regression when trying to move Jenkins X to 0.8.0 of skaffold.

The current Dockerfile syntax fails if a COPY statement containing a wildcard does not match anything.
When building Java docker images we often want to copy shared dependency jars if they exist; but don't fail if they don't.

So we use a trick like this:

# copy pom.xml and wildcards to avoid this command failing if there's no `target/lib*` files
COPY pom.xml target/lib* /opt/lib/

So that if there are no files matching target/lib* then at least pom.xml will match so that the COPY command will not fail. Docker does not seem to mind if a wildcard matches no files so long as there is at least one file found on the statement to copy.

However trying to use this Dockerfile with 0.8.0 of skaffold fails.

Expected behavior

Should be able to build a docker image using this Dockerfile that works fine outside of skaffold

Actual behavior

$ skaffold run -f skaffold.yaml
Starting build...
Sending build context to Docker daemon 

time="2018-06-25T08:54:13Z" level=fatal msg="build step: running build for artifact: running build: docker build: error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.27/build?buildargs=null&cachefrom=null&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=null&memory=0&memswap=0&networkmode=&rm=0&shmsize=0&t=0beb63c16455e3481c2c1f2c45960a96&target=&ulimits=null: creating docker context: getting relative tar paths: file pattern must match at least one file target/lib*"

So it looks like skaffold is validating the wildcard and failing the build if a wildcard does not match anything, even if there's already been pom.xml specified.

Information

  • Skaffold version: 0.8.0
  • Operating system: ...
  • Contents of skaffold.yaml:
apiVersion: skaffold/v1alpha2
kind: Config
build:
  tagPolicy:
    envTemplate:
      template: "{{.DOCKER_REGISTRY}}/jstrachan/demo102:{{.VERSION}}"
  artifacts:
  - imageName: changeme
    workspace: .
    docker: {}
  local: {}
deploy:
  kubectl:
    manifests:
profiles:
- name: dev
  build:
    tagPolicy:
      envTemplate:
        template: "{{.DOCKER_REGISTRY}}/jstrachan/demo102:{{.DIGEST_HEX}}"
    artifacts:
    - docker: {}
    local: {}
  deploy:
    helm:
      releases:
      - name: demo102
        chartPath: charts/demo102
        setValueTemplates:
          image.repository: "{{.DOCKER_REGISTRY}}/jstrachan/demo102"
          image.tag: "{{.TAG}}"

Dockerfile:

FROM openjdk:8-jdk-slim
ENV PORT 8080
ENV CLASSPATH /opt/lib
EXPOSE 8080

# copy pom.xml and wildcards to avoid this command failing if there's no target/lib directory
COPY pom.xml target/lib* /opt/lib/

# NOTE we assume there's only 1 jar in the target dir
# but at least this means we don't have to guess the name
# we could do with a better way to know the name - or to always create an app.jar or something
COPY target/*.jar /opt/app.jar
WORKDIR /opt
CMD ["java", "-jar", "app.jar"]

Full project here: https://github.com/jstrachan/demo102/blob/master/skaffold.yaml

Steps to reproduce the behavior

git clone https://github.com/jstrachan/demo102.git
cd demo102
export VERSION="1.2.3"
skaffold run -f skaffold.yaml
@dgageot
Copy link
Contributor

dgageot commented Jun 25, 2018

@jstrachan
I thought I made it work like docker build. I'm going to fix it tomorrow and make sure we have some tests. In fact we have some tests, it's just that they test the wrong thing!

@dgageot dgageot added kind/bug Something isn't working build/docker labels Jun 25, 2018
dgageot added a commit to dgageot/skaffold that referenced this issue Jun 25, 2018
Docker does not seem to mind if a wildcard matches no files so long as there is at least one file found on the statement to copy.

Fixes GoogleContainerTools#741

Signed-off-by: David Gageot <david@gageot.net>
@jstrachan
Copy link
Contributor Author

@dgageot awesome work many thanks! I'm sorry we rely on such obscure odd behaviour of COPY in Dockerfiles - there doesn't seem to be another way to handle optional file copying in docker ;)

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/docker kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants