Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hands-On Lab: Modernizing Monolith to Microserv...

Hands-On Lab: Modernizing Monolith to Microservices Applications on Google Cloud with Cloud Run

Ananda Dwi Ae

November 16, 2024
Tweet

More Decks by Ananda Dwi Ae

Other Decks in Technology

Transcript

  1. Ananda Dwi Rahmawati - Cloud and DevOps Engineer @ Singapore

    - Google Developer Expert Cloud - Modern Architecture - https://linktr.ee/misskecupbung Surabaya
  2. Containerize Application Google’s Jib Tool: • A powerful image build

    tool. • Easily builds and publishes optimized Docker images for Java apps. • No need for Docker or a Dockerfile. • Link: https://github.com/GoogleContainerTools/jib
  3. Cloud Run • Serverless container platform by Google Cloud. •

    Automatically scales stateless containers. • Supports a fully managed, containerized infrastructure. • Link: https://cloud.google.com/run/
  4. Prerequisites Familiarity with Java programming language and tools Knowledge of

    standard Linux text editors, such as Vim, Emacs, and nano
  5. Set up a Spring Boot Kotlin app. Build an optimized

    Docker image. Publish the image to Container Registry. Run the containerized app on Cloud Run. What you will do
  6. In this approach we create an anthemic opener showing real

    people using A.I. to do amazing things. This can be everyday people You will need to be signed in Click on “Sign in with Google” button
  7. In this approach we create an anthemic opener showing real

    people using A.I. to do amazing things. This can be everyday people You will need to be signed in You should see a similar page. Click on this button
  8. In this approach we create an anthemic opener showing real

    people using A.I. to do amazing things. This can be everyday people [email protected] Click on “Accept and Continue” to proceed Make sure that you are applying for the correct account
  9. In this approach we create an anthemic opener showing real

    people using A.I. to do amazing things. This can be everyday people Click on “New Project” Creating a new project
  10. In this approach we create an anthemic opener showing real

    people using A.I. to do amazing things. This can be everyday people Name your project Creating a new project IF you see a billing account, make sure to select the “Trial Billing Account”. If NOT, still create the project and go to next slide Click “CREATE”
  11. If you don’t see a billing account in the previous

    step: 1) Go to Billing from Google Cloud Console and 2) Set your project’s billing account to Google Cloud Platform Trial Billing Account
  12. Generate a new Spring Boot app with Spring Initializr. Step

    1 Initialize a Spring Boot App curl https://start.spring.io/starter.tgz \ -d type=maven-project \ -d language=java \ -d dependencies=web \ -d baseDir=maven-cloud-run | tar -xzvf - cd maven-cloud-run/
  13. Change to the directory of the template app and build

    and run the app using Maven. Step 1 Initialize a Spring Boot App cd maven-jib-cloud-run ./mvnw -DskipTests spring-boot:run
  14. nano src/main/java/com/example/demo/DemoApplication.java Step 2 Add a web controller package com.example.demo;

    import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @GetMapping("/") public String saySomething() { return "Java app on Cloud Run, containerized by Jib!"; } }
  15. Activate the Container Registry API. Step 4 Containerize your app

    and publish to Container Registry gcloud services enable containerregistry.googleapis.com
  16. Run Jib to build a Docker image and publish to

    Container Registry. Step 5 Containerize your app and publish to Container Registry ./mvnw com.google.cloud.tools:jib-maven-plugin:3.3.1:build \ -Dimage=gcr.io/$GOOGLE_CLOUD_PROJECT/kotlin-jib-cloud-run \ -Djib.from.image=eclipse-temurin:17-jre