GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — java-docs-samples/run at main · GoogleCloudPlatform/java-docs-samples

Expand file tree

/

run

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

run

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
authentication
authentication
 
 
endpoints-v2-backend
endpoints-v2-backend
 
 
hello-broken
hello-broken
 
 
helloworld
helloworld
 
 
idp-sql
idp-sql
 
 
image-processing
image-processing
 
 
jobs
jobs
 
 
logging-manual
logging-manual
 
 
markdown-preview
markdown-preview
 
 
pubsub
pubsub
 
 
service-auth
service-auth
 
 
system-package
system-package
 
 
README.md
README.md
 
 

README.md

Outline

Google Cloud Run Java Samples

Open in Cloud Shell

This directory contains samples for Google Cloud Run. Cloud Run runs stateless containers on a fully managed environment or in your own GKE cluster.

Samples

Sample Description Deploy
Hello World Quickstart Run on Google Cloud
Cloud Pub/Sub Handling Pub/Sub push messages Run on Google Cloud
System Packages Using system packages with containers Run on Google Cloud
Image Magick Event-driven image analysis & transformation Run on Google Cloud
Manual Logging Structured logging for Stackdriver Run on Google Cloud
Local Troubleshooting Broken services for local troubleshooting tutorial Run on Google Cloud
Cloud SQL (MySQL) Use MySQL with Cloud Run Run on Google Cloud
Events - Pub/Sub Events for Cloud Run with Pub/Sub Run on Google Cloud
Anthos Events - Pub/Sub Events for Cloud Run on Anthos with Pub/Sub -
Events - GCS Events for Cloud Run with GCS Run on Google Cloud
Anthos Events - GCS Events for Cloud Run on Anthos with GCS -
Authentication Make an authenticated request by retrieving a JSON Web Tokens (JWT) Run on Google Cloud

For more Cloud Run samples beyond Java, see the main list in the Cloud Run Samples repository.

Jib

These samples use Jib to build Docker images using common Java tools. Jib optimizes container builds without the need for a Dockerfile or having Docker installed. Learn more about how Jib works.

Setup

  1. Set up for Cloud Run development

  2. Clone this repository:

    git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
    
  3. In the samples's pom.xml, update the image field for the jib-maven-plugin with your Google Cloud Project Id:

    <plugin>
      <groupId>com.google.cloud.tools</groupId>
      <artifactId>jib-maven-plugin</artifactId>
      <version>2.0.0</version>
      <configuration>
        <to>
          <image>gcr.io/PROJECT_ID/SAMPLE_NAME</image>
        </to>
      </configuration>
    </plugin>

How to run a sample locally

  1. Build the sample container using Jib:

    mvn compile jib:dockerBuild
  2. Run containers locally by replacing PROJECT_ID and SAMPLE_NAME with your values.

    With the built container:

    PORT=8080 && docker run --rm -p 9090:${PORT} -e PORT=${PORT} gcr.io/PROJECT_ID/SAMPLE_NAME

    Injecting your service account key for access to GCP services:

    PORT=8080 && docker run \
       -p 9090:${PORT} \
       -e PORT=${PORT} \
       -e K_SERVICE=dev \
       -e K_CONFIGURATION=dev \
       -e K_REVISION=dev-00001 \
       -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/[FILE_NAME].json \
       -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/[FILE_NAME].json:ro \
        gcr.io/PROJECT_ID/SAMPLE_NAME
    • Use the --volume (-v) flag to inject the credential file into the container (assumes you have already set your GOOGLE_APPLICATION_CREDENTIALS environment variable on your machine)

    • Use the --environment (-e) flag to set the GOOGLE_APPLICATION_CREDENTIALS variable inside the container

  3. Open http://localhost:9090 in your browser.

Learn more about testing your container image locally.

Deploying

  1. Build the sample container using Jib:

    mvn compile jib:build
    

    Note: Using the image tag gcr.io/PROJECT_ID/SAMPLE_NAME automatically pushes the image to Google Container Registry.

  2. Deploy to Cloud Run by replacing PROJECT_ID and SAMPLE_NAME with your values:

    gcloud run deploy --image gcr.io/PROJECT_ID/SAMPLE_NAME

Next Steps

  • See building containers and deploying container images for more information.

  • Dockerize a Spring Boot app without a Dockerfile using Jib.

  • To improve Tomcat startup time, add -Djava.security.egd=file:/dev/./urandom to the Dockerfile's CMD instructions. This is acceptable for many applications. However, if your application does it's own key generation, such as for SSL, and you require greater security, you may prefer to not set java.security.egd.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.