You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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"]
@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!
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.
FixesGoogleContainerTools#741
Signed-off-by: David Gageot <david@gageot.net>
@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 ;)
Just found another minor regression when trying to move Jenkins X to
0.8.0
of skaffold.The current
Dockerfile
syntax fails if aCOPY
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:
So that if there are no files matching
target/lib*
then at leastpom.xml
will match so that theCOPY
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 skaffoldActual behavior
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
Dockerfile:
Full project here: https://github.com/jstrachan/demo102/blob/master/skaffold.yaml
Steps to reproduce the behavior
The text was updated successfully, but these errors were encountered: