Skip to content

Timtech4u/cloudrun_warmer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cloud Run Warmer

A warmer service that periodically makes requests to Cloud Run services.

Cloud Run services often requires downloading the container image and starting the container before it is accessible. This is called a cold start and it occurs due to Cloud Run's scale to zero ability.

This tool prevents cold start by making scheduled requests that warms up Cloud Run services. You can read more about how to minimize Cloud Run Cold Starts John's article here

Note that this tool best fits when you have multiple Cloud Run services on a project and you do not want to setup individual Cloud Scheduler Jobs to warm each service.

How to use

  • Set up a Google Cloud account and project and start Cloud Shell.

  • Clone the source codes in the Cloud Shell Terminal: git clone https://github.com/Timtech4u/cloudrun_warmer

  • Generate Service Account JSON Key and update code OR get values for enviroment variables labels:

    gcloud auth application-default print-access-token

    • ACCESS_TOKEN here (Required)

    • PROJECT_ID here (Required)

    • REGION (Optional/Default: "us-central1") here

    • DISALLOWED_IMAGES (Optional) here

    • DISALLOWED_SERVICES (Optional) here env vars.

  • Deploy this repo to Cloud Functions

    gcloud functions deploy cloudrun_warmer --set-env-vars PROJECT_ID=foo, ACCESS_TOKEN=bar, --runtime python37 --trigger-http

  • Set up Cloud Scheduler Job with Function's URL

    gcloud scheduler jobs create http cloudrun_warmer_job --schedule "0 * * * *" --uri "https://us-central1-myproject.cloudfunctions.net/cloudrun_warmer" --http-method GET
    

How it works

  • Attempts to retrieve access token, project ID, services to skip.

  • Fetches the list of all Cloud Run services based on configured project and region.

  • Makes peroidic requests to each service (while skipping disallowed services) with 5secs timeout.

Tools Used

If you want to complete this steps using a GUI or Cloud Console, check out my article on Scheduling periodic jobs with Cloud Scheduler ⏰

About

A warmer service that periodically makes requests to Cloud Run services.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages