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 master · snehilrx/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

..
pubsub
pubsub
 
 
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

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

Setup

  1. Set up for Cloud Run development

  2. Clone this repository:

    git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
    

    Note: Some samples in the list above are hosted in other repositories. They are noted with the symbol "➥".

How to run a sample locally

  1. Install docker locally

  2. Build the sample container:

    export SAMPLE=<SAMPLE_NAME>
    cd $SAMPLE
    docker build --tag $SAMPLE .
    
  3. Run containers locally

    With the built container:

    PORT=8080 && docker run --rm -p 8080:${PORT} -e PORT=${PORT} $SAMPLE
    

    Overriding the built container with local code:

    PORT=8080 && docker run --rm \
        -p 8080:${PORT} -e PORT=${PORT} \
        -v $PWD:/app $SAMPLE
    

    Injecting your service account key for access to GCP services:

    # Set the name of the service account key within the container
    export SA_KEY_NAME=my-key-name-123
    
    PORT=8080 && docker run --rm \
        -p 8080:${PORT} \
        -e PORT=${PORT} \
        -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/${SA_KEY_NAME}.json \
        -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/${SA_KEY_NAME}.json:ro \
        -v $PWD:/app $SAMPLE
    
    • 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

Learn more about testing your container image locally.

Deploying

  1. Set your GCP Project ID as an environment variable:
export GOOGLE_CLOUD_PROJECT=<PROJECT_ID>
  1. Choose to push your image to Google Container Registry or submit a build to Cloud Build:
  • Push the docker build to Google Container Registry:
docker tag $SAMPLE gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
docker push gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}

Learn more about pushing and pulling images.

  • Submit a build using Google Cloud Build:
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
  1. Deploy to Cloud Run:
gcloud beta run deploy $SAMPLE \
  --set-env-vars GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}  \
  --image gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}

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 01402775 — 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.