{{announcement.body}}
{{announcement.title}}

Deploy Quarkus Faster in The Cloud with Platform.sh. Part 1: Hello World

DZone 's Guide to

Deploy Quarkus Faster in The Cloud with Platform.sh. Part 1: Hello World

How to deploy a plain Quarkus application in the cloud with Platform.sh

· Java Zone ·
Free Resource

Quarkus is, in its own words, a cloud-native, (Linux) container-first framework for writing Java applications. It has become popular lately because of the amazingly fast boot time, incredibly low RSS memory. In this series of articles about Quarkus, we'll discuss how to deploy a Quarkus application even faster to the cloud with Platform.sh.

The first step is to create the application itself, and Quarkus has proper documentation. You have either a Maven Archetype or the start code link where you can define the dependencies that you need to write your application.

As soon as you generate the application it will create an  ExemploResource  with the Hello world message.

Java
 




x
14


 
1
import javax.ws.rs.GET;
2
import javax.ws.rs.Path;
3
import javax.ws.rs.Produces;
4
import javax.ws.rs.core.MediaType;
5
 
          
6
@Path("/hello")
7
public class ExampleResource {
8
 
          
9
    @GET
10
    @Produces(MediaType.TEXT_PLAIN)
11
    public String hello() {
12
        return "Hello World From Platform.sh";
13
    }
14
}



If you want to change the hello world message, please, don't forget to update the test as well.

Java
 




xxxxxxxxxx
1
19


1
import io.quarkus.test.junit.QuarkusTest;
2
import org.junit.jupiter.api.Test;
3
 
          
4
import static io.restassured.RestAssured.given;
5
import static org.hamcrest.CoreMatchers.is;
6
 
          
7
@QuarkusTest
8
public class ExampleResourceTest {
9
 
          
10
    @Test
11
    public void testHelloEndpoint() {
12
        given()
13
          .when().get("/hello")
14
          .then()
15
             .statusCode(200)
16
             .body(is("Hello World From Platform.sh"));
17
    }
18
 
          
19
}



Quarkus requires Apache Maven 3.6.2 or higher to run the application, but even if your machine does not have the generated project brings a Maven Wrapper with the Maven version that it needs to run. So you can package and run this application from this Maven Wrapper.

Shell
 




xxxxxxxxxx
1


 
1
 ./mvnw package



We've finished the application, and it is ready to run. Be prepared to see how fast this application starts.

Shell
 




xxxxxxxxxx
1


1
java -jar target/quarkus-1.0.0-SNAPSHOT-runner.jar



Amazing, isn't? But how about moving this application to the cloud? Let me introduce to you Platform.sh, it is a second-generation Platform-as-a-Service built especially for continuous deployment. It allows you to host web applications on the cloud while making your development and testing workflows more productive.

As a Platform as a Service, or PaaS, Platform.sh automatically manages everything your application needs in order to run. That means you can, and should, view your infrastructure needs as part of your application, and version-control it as part of your application.

To move your application to the cloud, briefly, you need two files: 

  • One Router (.platform/routes.yaml). Platform.sh allows you to define the routes.
YAML
 




xxxxxxxxxx
1


 
1
"https://{default}/":
2
  type: upstream
3
  upstream: "app:http"
4
 
          
5
"https://www.{default}/":
6
  type: redirect
7
  to: "https://{default}/"


  • One or more application containers (.platform.app.yaml). You control your application and the way it will be built and deployed on Platform.sh via a single configuration file.
YAML
 




xxxxxxxxxx
1


 
1
name: app
2
type: "java:11"
3
disk: 1024
4
hooks:
5
    build: ./mvnw package -DskipTests
6
web:
7
    commands:
8
        start: java -jar -Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError -Dquarkus.http.port=$PORT target/quarkus-1.0.0-SNAPSHOT-runner.jar



The application is now ready, so it’s time to move it to the cloud with Platform.sh using the following steps:

  • Create a new free trial account.
  • Sign up with a new user and password, or login using a current GitHub, Bitbucket, or Google account. If you use a third-party login, you’ll be able to set a password for your Platform.sh account later.
  • Select the region of the world where your site should live.
  • Select the blank template.

You have the option to either integrate to GitHub, GitLab, or Platform.sh will provide to you. Finally, push to the remote repository:

PowerShell
 




x


 
1
git remote add platform <platform.sh@gitrepository>
2
git commit -m "Initial project"
3
git push -u platform master



Done! We have a simple and nice Quarkus application ready to go to the cloud.

Topics:
cloud ,container ,framework ,java ,linux ,platform.sh ,quarkus

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}