-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7452a0
commit 66a349a
Showing
3 changed files
with
53 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...main/java/io/quarkus/gcp/functions/http/deployment/CloudFunctionsDeploymentBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.quarkus.gcp.functions.http.deployment; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
|
||
import io.quarkus.builder.BuildException; | ||
import io.quarkus.deployment.IsNormal; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.JarBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem; | ||
import io.quarkus.deployment.pkg.builditem.UberJarRequiredBuildItem; | ||
import io.quarkus.deployment.pkg.steps.NativeBuild; | ||
|
||
public class CloudFunctionsDeploymentBuildStep { | ||
@BuildStep | ||
public UberJarRequiredBuildItem forceUberJar() { | ||
// Google Cloud Function needs a single JAR inside a dedicated directory | ||
return new UberJarRequiredBuildItem(); | ||
} | ||
|
||
/** | ||
* Creates a target/deployment dir and copy the uber jar in it. | ||
* This facilitates the usage of the 'glcoud' command. | ||
*/ | ||
@BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class) | ||
public ArtifactResultBuildItem functionDeployment(OutputTargetBuildItem target, JarBuildItem jar) | ||
throws BuildException, IOException { | ||
if (!jar.isUberJar()) { | ||
throw new BuildException("Google Cloud Function deployment need to use a uberjar, " + | ||
"please set 'quarkus.package.uber-jar=true' inside your application.properties", | ||
Collections.EMPTY_LIST); | ||
} | ||
|
||
Path deployment = target.getOutputDirectory().resolve("deployment"); | ||
if (Files.notExists(deployment)) { | ||
Files.createDirectory(deployment); | ||
} | ||
|
||
Path jarPath = jar.getPath(); | ||
Path targetJarPath = deployment.resolve(jarPath.getFileName()); | ||
Files.deleteIfExists(targetJarPath); | ||
Files.copy(jarPath, targetJarPath); | ||
|
||
return new ArtifactResultBuildItem(targetJarPath, "function", Collections.EMPTY_MAP); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
quarkus.package.uber-jar=true | ||