Skip to content

Latest commit

 

History

History

run

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Google Cloud Platform logo

Google Cloud Run Ruby Samples

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

For more Cloud Run samples beyond Ruby, 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/ruby-docs-samples.git
  3. Create an Artifact Registry:

    gcloud artifacts repositories create containers --repository-format docker --location ${GOOGLE_CLOUD_REGION}

How to run a sample locally

  1. Install docker locally

  2. Build the sample container:

    # Replace <sample> with the sample name, ie 'helloworld'
    export SAMPLE=<sample>
    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:/usr/src/app $SAMPLE

    Injecting your service account key:

    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:/usr/src/app $SAMPLE
  4. Visit the application at http://localhost:8080.

Deploying

  1. Set your GCP project Id:

    export GOOGLE_CLOUD_PROJECT=$(gcloud config get-value project)
  2. Build your container image using Cloud Build, by running the following command from the directory containing the Dockerfile:

    gcloud builds submit --tag ${GOOGLE_CLOUD_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/containers/${SAMPLE}
  3. Deploy the container image using the following command:

    gcloud run deploy ${SAMPLE} \
      --image ${GOOGLE_CLOUD_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/containers/${SAMPLE}

See Building containers and Deploying container images for more information.