Skip to content

Commit

Permalink
Add binary path to staging (#842)
Browse files Browse the repository at this point in the history
* Allow binaries in java11 standard buildpath
  • Loading branch information
loosebazooka committed Jun 18, 2020
1 parent df426fd commit 55b0ced
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 54 deletions.
Expand Up @@ -85,7 +85,7 @@ public static Builder builder() {
/**
* Create a new builder for AppYamlProjectStageConfiguration.
*
* @deprecated Use newBuilder().appEngineDirectory(appEngineDirectory).artifact(artifact)
* @deprecated Use builder().appEngineDirectory(appEngineDirectory).artifact(artifact)
* .stagingDirectory(stagingDirectory) instead.
*/
@Deprecated
Expand Down
Expand Up @@ -74,15 +74,29 @@ public void stageArchive(AppYamlProjectStageConfiguration config) throws AppEngi
String runtime = findRuntime(config);
if ("flex".equals(env)) {
stageFlexibleArchive(config, runtime);
} else if ("java11".equals(runtime)) {
stageStandardArchive(config);
} else {
// I don't know how to deploy this
return;
}
if ("java11".equals(runtime)) {
boolean isJar = config.getArtifact().getFileName().toString().endsWith(".jar");
if (isJar) {
stageStandardArchive(config);
return;
}
if (hasCustomEntrypoint(config)) {
stageStandardBinary(config);
return;
}
// I cannot deploy non-jars without custom entrypoints
throw new AppEngineException(
"Cannot process application with runtime: "
+ runtime
+ (Strings.isNullOrEmpty(env) ? "" : " and env: " + env));
"Cannot process application with runtime: java11."
+ " A custom entrypoint must be defined in your app.yaml for non-jar artifact: "
+ config.getArtifact().toString());
}
// I don't know how to deploy this
throw new AppEngineException(
"Cannot process application with runtime: "
+ runtime
+ (Strings.isNullOrEmpty(env) ? "" : " and env: " + env));
} catch (IOException ex) {
throw new AppEngineException(ex);
}
Expand All @@ -108,6 +122,15 @@ void stageStandardArchive(AppYamlProjectStageConfiguration config)
copyArtifactJarClasspath(config, copyService);
}

@VisibleForTesting
void stageStandardBinary(AppYamlProjectStageConfiguration config)
throws IOException, AppEngineException {
CopyService copyService = new CopyService();
copyExtraFiles(config, copyService);
copyAppEngineContext(config, copyService);
copyArtifact(config, copyService);
}

@VisibleForTesting
@Nullable
static String findEnv(AppYamlProjectStageConfiguration config)
Expand Down Expand Up @@ -198,7 +221,6 @@ static void copyExtraFiles(AppYamlProjectStageConfiguration config, CopyService

private static void copyArtifact(AppYamlProjectStageConfiguration config, CopyService copyService)
throws IOException, AppEngineException {
// Copy the JAR/WAR file to staging.
Path artifact = config.getArtifact();
if (Files.exists(artifact)) {
Path stagingDirectory = config.getStagingDirectory();
Expand Down Expand Up @@ -248,6 +270,20 @@ static void copyArtifactJarClasspath(
}
}

@VisibleForTesting
// for non jar artifacts we want to ensure the entrypoint is custom
static boolean hasCustomEntrypoint(AppYamlProjectStageConfiguration config)
throws IOException, AppEngineException {
// verify that app.yaml that contains entrypoint:
if (config.getAppEngineDirectory() == null) {
throw new AppEngineException("Invalid Staging Configuration: missing App Engine directory");
}
Path appYamlFile = config.getAppEngineDirectory().resolve(APP_YAML);
try (InputStream input = Files.newInputStream(appYamlFile)) {
return AppYaml.parse(input).getEntrypoint() != null;
}
}

@VisibleForTesting
static class CopyService {
void copyDirectory(Path src, Path dest, List<Path> excludes) throws IOException {
Expand Down

0 comments on commit 55b0ced

Please sign in to comment.