-
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.
Merge pull request #10293 from loicmathieu/gcp/http-functions-improve…
…ments Gcp HTTP functions improvements
- Loading branch information
Showing
6 changed files
with
82 additions
and
22 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
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
1 change: 0 additions & 1 deletion
1
integration-tests/google-cloud-functions-http/src/main/resources/application.properties
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 | ||
20 changes: 20 additions & 0 deletions
20
...gle-cloud-functions-http/src/test/java/io/quarkus/it/gcp/functions/http/GreetingTest.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,20 @@ | ||
package io.quarkus.it.gcp.functions.http; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class GreetingTest { | ||
|
||
@Test | ||
public void testGreeting() { | ||
when().get("/hello").then().statusCode(200); | ||
|
||
when().get("/servlet/hello").then().statusCode(200); | ||
|
||
when().get("/vertx/hello").then().statusCode(200); | ||
} | ||
} |