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

Add binary path to staging #842

Merged
merged 5 commits into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
* .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);
loosebazooka marked this conversation as resolved.
Show resolved Hide resolved
}

@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