From 025f972371047e3abfff7f5a556838ef5047efb2 Mon Sep 17 00:00:00 2001 From: Ryan Gardner Date: Tue, 3 Oct 2017 13:00:58 -0400 Subject: [PATCH 1/3] create a test that fails to demonstrate issue #75 --- .../basic-using-docker-directory/Dockerfile | 4 + .../it/basic-using-docker-directory/pom.xml | 82 +++++++++++++++++++ .../src/main/java/com/foo/Foo.java | 8 ++ .../verify.groovy | 21 +++++ 4 files changed, 115 insertions(+) create mode 100644 plugin/src/it/basic-using-docker-directory/Dockerfile create mode 100644 plugin/src/it/basic-using-docker-directory/pom.xml create mode 100644 plugin/src/it/basic-using-docker-directory/src/main/java/com/foo/Foo.java create mode 100644 plugin/src/it/basic-using-docker-directory/verify.groovy diff --git a/plugin/src/it/basic-using-docker-directory/Dockerfile b/plugin/src/it/basic-using-docker-directory/Dockerfile new file mode 100644 index 00000000..34a955fa --- /dev/null +++ b/plugin/src/it/basic-using-docker-directory/Dockerfile @@ -0,0 +1,4 @@ +FROM scratch +MAINTAINER David Flemström + +COPY target/docker/lib \ No newline at end of file diff --git a/plugin/src/it/basic-using-docker-directory/pom.xml b/plugin/src/it/basic-using-docker-directory/pom.xml new file mode 100644 index 00000000..4eca588d --- /dev/null +++ b/plugin/src/it/basic-using-docker-directory/pom.xml @@ -0,0 +1,82 @@ + + + + + 4.0.0 + + com.spotify.it + basic + 1.0-SNAPSHOT + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + + commons-lang + commons-lang + 2.4 + + + + + + + + + + maven-dependency-plugin + + + initialize + + copy-dependencies + + + false + runtime + ${project.build.directory}/docker/lib + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + default + + build + + + + + + + diff --git a/plugin/src/it/basic-using-docker-directory/src/main/java/com/foo/Foo.java b/plugin/src/it/basic-using-docker-directory/src/main/java/com/foo/Foo.java new file mode 100644 index 00000000..43d072b8 --- /dev/null +++ b/plugin/src/it/basic-using-docker-directory/src/main/java/com/foo/Foo.java @@ -0,0 +1,8 @@ +package com.foo; + + +public class Foo { + public static void main(String[] args) { + // don't do anything. + } +} diff --git a/plugin/src/it/basic-using-docker-directory/verify.groovy b/plugin/src/it/basic-using-docker-directory/verify.groovy new file mode 100644 index 00000000..0395ec6e --- /dev/null +++ b/plugin/src/it/basic-using-docker-directory/verify.groovy @@ -0,0 +1,21 @@ +/* + * -/-/- + * Dockerfile Maven Plugin + * %% + * Copyright (C) 2015 - 2016 Spotify AB + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * -\-\- + */ +File imageIdFile = new File(basedir, "target/docker/image-id") +assert imageIdFile.isFile() From f89973de5cdc2846dbb229fa3c2ef4f03753dea8 Mon Sep 17 00:00:00 2001 From: Ryan Gardner Date: Tue, 3 Oct 2017 13:39:49 -0400 Subject: [PATCH 2/3] update test case to demonstrate issue --- plugin/src/it/basic-using-docker-directory/Dockerfile | 6 +++++- .../it/basic-using-docker-directory/src/main/docker/foo.txt | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 plugin/src/it/basic-using-docker-directory/src/main/docker/foo.txt diff --git a/plugin/src/it/basic-using-docker-directory/Dockerfile b/plugin/src/it/basic-using-docker-directory/Dockerfile index 34a955fa..28a18141 100644 --- a/plugin/src/it/basic-using-docker-directory/Dockerfile +++ b/plugin/src/it/basic-using-docker-directory/Dockerfile @@ -1,4 +1,8 @@ FROM scratch MAINTAINER David Flemström -COPY target/docker/lib \ No newline at end of file +ENV BASE /opt/base + +COPY target/docker/lib $BASE/lib + +ADD src/main/docker/foo.txt $BASE/ \ No newline at end of file diff --git a/plugin/src/it/basic-using-docker-directory/src/main/docker/foo.txt b/plugin/src/it/basic-using-docker-directory/src/main/docker/foo.txt new file mode 100644 index 00000000..a3f81e37 --- /dev/null +++ b/plugin/src/it/basic-using-docker-directory/src/main/docker/foo.txt @@ -0,0 +1 @@ +# a text file to copy over \ No newline at end of file From e86347a8aa356c7dcd63baac7ed6734ef349dd68 Mon Sep 17 00:00:00 2001 From: Ryan Gardner Date: Tue, 3 Oct 2017 13:40:13 -0400 Subject: [PATCH 3/3] check that the source is a directory before trying to copy it --- .../plugin/dockerfile/AbstractDockerMojo.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java b/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java index fe895b7f..c73b9571 100644 --- a/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java +++ b/plugin/src/main/java/com/spotify/plugin/dockerfile/AbstractDockerMojo.java @@ -293,10 +293,19 @@ private void writeTestMetadata() throws MojoExecutionException { for (String name : dockerInfoDirectory.list()) { final File sourceFile = new File(dockerInfoDirectory, name); final File targetFile = new File(testMetadataDir, name); - try { - Files.copy(sourceFile, targetFile); - } catch (IOException e) { - throw new MojoExecutionException("Could not copy files", e); + if (sourceFile.isDirectory()) { + getLog().warn("A directory was found inside the docker info directory at " + + dockerInfoDirectory.getAbsolutePath() + + " - this usually indicates that you have used this directory for something other" + + " than this plugin. " + + "For proper functionality, please configure the `dockerfile.dockerInfoDirectory`" + + " property to something that is only used by this plugin."); + } else { + try { + Files.copy(sourceFile, targetFile); + } catch (IOException e) { + throw new MojoExecutionException("Could not copy files", e); + } } } }