GCP Cloud Run Deployment Example
This guide demonstrates how to deploy a simple reward function to Google Cloud Run using thereward-kit
CLI. The example uses a basic hello_world_reward
function found in examples/gcp_cloud_run_deployment_example/dummy_rewards.py
.
Overview
Deploying a reward function to GCP Cloud Run allows you to host it as a scalable, serverless HTTP endpoint. Thereward-kit deploy
command automates much of this process, including containerization and service configuration.
Files in the Example Directory
Located inexamples/gcp_cloud_run_deployment_example/
:
dummy_rewards.py
: Contains a basichello_world_reward
function used for this deployment example.rewardkit.example.yaml
: An example configuration file forreward-kit
. This shows the structure forrewardkit.yaml
if you choose to use one for GCP settings.
Prerequisites
- Google Cloud Platform (GCP) Account: Active GCP account with billing enabled.
gcloud
CLI: Google Cloud CLI installed and authenticated (gcloud auth login
,gcloud auth application-default login
).- APIs Enabled: Ensure the following APIs are enabled in your GCP project:
- Cloud Build API
- Artifact Registry API
- Cloud Run Admin API
- Secret Manager API
- Permissions: The authenticated user/service account for
gcloud
needs sufficient permissions (e.g., roles like “Cloud Build Editor”, “Artifact Registry Administrator”, “Cloud Run Admin”, “Secret Manager Admin”). reward-kit
installed: Ensurereward-kit
is installed in your Python environment (e.g.,pip install reward-kit
).
Setup
rewardkit.yaml
Configuration (Optional but Recommended)
The reward-kit
CLI can pick up GCP settings from a rewardkit.yaml
file located in the directory from which you run the reward-kit deploy
command.
-
Create
rewardkit.yaml
: You can copy theexamples/gcp_cloud_run_deployment_example/rewardkit.example.yaml
to the directory where you intend to runreward-kit deploy
(this could be the example directory itself, or your project root). Rename it torewardkit.yaml
. -
Customize
rewardkit.yaml
: Openrewardkit.yaml
and replace placeholders with your actual GCP Project ID and desired region. Examplerewardkit.yaml
:
rewardkit.yaml
file, you must provide all necessary GCP parameters (like --gcp-project YOUR_PROJECT_ID
, --gcp-region YOUR_REGION
) directly in the reward-kit deploy
command.
Deployment Command
It’s recommended to run the deployment command from the directory containing the reward function script (dummy_rewards.py
) and your rewardkit.yaml
(if used), for example, from examples/gcp_cloud_run_deployment_example/
.
- Ensure your virtual environment is active:
- Run the deployment command:
--id my-dummy-gcp-evaluator
: A unique ID for your evaluator on the Fireworks AI platform.--target gcp-cloud-run
: Specifies deployment to GCP Cloud Run.--function-ref dummy_rewards.hello_world_reward
: The Python import path to your reward function. Ifdummy_rewards.py
is in the current directory, this reference works.--gcp-auth-mode api-key
: Configures the Cloud Run service with API key authentication.reward-kit
will generate a key, store it in GCP Secret Manager, and configure the service. The key is also saved to your localrewardkit.yaml
underevaluator_endpoint_keys
. This is the default if not specified.--verbose
: Shows detailed output, includinggcloud
commands being executed.--force
: (Optional) If an evaluator with the same--id
already exists, this flag will delete the existing one before creating the new one.
Expected Outcome
If successful,reward-kit
will:
- Create an Artifact Registry repository (default:
reward-kit-evaluators
, or as specified inrewardkit.yaml
). - Build a Docker container with your reward function and push it to Artifact Registry.
- If
api-key
auth is used, create a GCP Secret to store the generated API key. - Deploy the container to Cloud Run, configured for the chosen authentication mode.
- Register the deployed Cloud Run service URL as a remote evaluator with the Fireworks AI platform.
Testing the Deployed Endpoint
You can test the deployed endpoint usingcurl
or reward-kit preview --remote-url <your-cloud-run-url>
.
If using curl
with API key authentication:
- Retrieve the API key. It’s printed during deployment and saved in
rewardkit.yaml
(if one is used in the command’s directory) underevaluator_endpoint_keys: { "my-dummy-gcp-evaluator": "YOUR_KEY" }
. - Get your Cloud Run service URL from the deployment output.
hello_world_reward
function.