Git Product home page Git Product logo

cloud-debugger-gce-java-sample's Introduction

status: inactive

This project is no longer actively developed or maintained.

Cloud Debug for Compute Engine sample

cloud-debugger-gce-java-sample

This sample shows how to add the ability to debug your Java application running on Google Compute Engine. It is based on the Spark Java - a tiny Sinatra inspired framework for creating web applications in Java 8.

This application just listens on port 8080 for requests and says "hello world" with a counter. You can ask that a Cloud Debugger snapshot be generated on any line.

Preperation

  1. Download & install the Cloud SDK

  2. Create a project (if you don't have one already) using the Developers Console.

  3. If you haven't already, use:

    $ gcloud init

  4. Create a bucket (Storage > Cloud Storage > Browser > Create bucket) or using the command line:

    $ gsutil mb <bucketName>

  5. Connect with your Cloud Source Repository using:

    $ gcloud beta source repos clone default <directoryName>

  6. Copy this project, skiping any .git files by using:

    rsync -av --exclude=".*" <src> <directoryName>

  7. go into your directory:

    $ cd <directoryName>

Deploying

  1. Commit and push the project to the Source Repository:

    $ git add *
    $ git commit -m 'Initial Commit'
    $ git push origin master

  2. Build the project

    $ mvn package -Dbucket=<bucketName>

In addition to the normal compiling of classes and building of jars, we add to the process-resources phase the following:

gcloud app gen-repo-info-file -\-output-file=target/project-1.0-SNAPSHOT/WEB-INF/classes/source-context.json

Which helps tell the Cloud Debugger which version of your source code to associate with this execution as you can have many.

  1. Deploy your application using:

    $ mvn deploy -Dbucket=<bucketName>

Deploy will first copy the startup script and the jar to the bucket using gsutil. Then it will create a new instance using:

gcloud compute instances create cdb --image debian-8 --metadata startup-script-url=gs://bucket/start.sh,my-bucket=gs://bucket --scopes cloud-platform

For this application, it is important that we use debian-8 (Jessie) as it will allow us to use Java 8 easily.

The startup script installs the Java 8 open jdk, uses update-alternatives to tell the system to default to Java 8 and gets a copy of the jar from the bucket.

The next steps are to setup the Cloud Debugger. The first two lines get the latest version of the debugger bootstrap script and make it executable.

wget -q https://storage.googleapis.com/cloud-debugger/compute-java/format_env_gce.sh chmod +x format_env_gce.sh

This next line executes that script passing a copy of the jar, and the return Java command line arguments

CDBG_ARGS="$( sudo ./format_env_gce.sh --app_class_path=hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar )"

Finally we startup the code using, it will listen on port 8080:

java ${CDBG_ARGS} -cp sparky/hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.hellosparky.App

Run Locally

java -cp target/hellosparky-1.0-SNAPSHOT-jar-with-dependencies.jar com.example.hellosparky.App
  1. Visit the application at http://localhost:8080.

Contributing changes

Licensing

cloud-debugger-gce-java-sample's People

Contributors

elharo avatar lesv avatar tswast avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.