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

Fixes DockerfileTemplate resource resolution. #171

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import com.google.cloud.tools.jib.filesystem.DirectoryWalker;
import com.google.cloud.tools.jib.filesystem.PathConsumer;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.io.InsecureRecursiveDeleteException;
import com.google.common.io.MoreFiles;
import com.google.common.io.Resources;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -130,22 +130,17 @@ DockerContextMojo setFrom(String baseImage) {

@VisibleForTesting
/** Makes a {@code Dockerfile} from the {@code DockerfileTemplate}. */
String makeDockerfile(SourceFilesConfiguration sourceFilesConfiguration)
throws IOException, URISyntaxException {
Path dockerfileTemplate = Paths.get(Resources.getResource("DockerfileTemplate").toURI());

String dockerfile = new String(Files.readAllBytes(dockerfileTemplate), StandardCharsets.UTF_8);
dockerfile =
dockerfile
.replace("@@BASE_IMAGE@@", from)
.replace(
"@@DEPENDENCIES_PATH_ON_IMAGE@@",
sourceFilesConfiguration.getDependenciesPathOnImage())
.replace(
"@@RESOURCES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getResourcesPathOnImage())
.replace("@@CLASSES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getClassesPathOnImage())
.replace("@@ENTRYPOINT@@", getEntrypoint(sourceFilesConfiguration));
return dockerfile;
String makeDockerfile(SourceFilesConfiguration sourceFilesConfiguration) throws IOException {
String dockerfileTemplate =
Resources.toString(Resources.getResource("DockerfileTemplate"), StandardCharsets.UTF_8);

return dockerfileTemplate
.replace("@@BASE_IMAGE@@", from)
.replace(
"@@DEPENDENCIES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getDependenciesPathOnImage())
.replace("@@RESOURCES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getResourcesPathOnImage())
.replace("@@CLASSES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getClassesPathOnImage())
.replace("@@ENTRYPOINT@@", getEntrypoint(sourceFilesConfiguration));
}

/**
Expand Down Expand Up @@ -214,11 +209,15 @@ private void createDockerContext(ProjectProperties projectProperties)

projectProperties.getLog().info("Created Docker context at " + targetDir);

} catch (InsecureRecursiveDeleteException ex) {
throwMojoExecutionExceptionWithHelpMessage(
ex,
"cannot clear directory '"
+ targetDir
+ "' safely - clear it manually before creating the Docker context");

} catch (IOException ex) {
throwMojoExecutionExceptionWithHelpMessage(ex, "check if `targetDir` is set correctly");

} catch (URISyntaxException ex) {
throw new MojoFailureException("Unexpected URISyntaxException", ex);
}
}

Expand Down