Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gcp secrets and labels #11

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions examples/cloud_deployment/gcp/deploy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getpass
import os

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.deploy.gcp.deploy import (
deploy_to_gcp,
remove_deployed_gcp_function,
Expand All @@ -13,13 +13,20 @@
if __name__ == "__main__":
current_dir = os.path.dirname(os.path.realpath(__file__))
fname = deploy_to_gcp(
requirements_file=f"{current_dir}/../../../pyproject.toml",
requirements_file=None,
extra_deps=[
"git+https://github.com/gnosis/prediction-market-agent-tooling.git"
"git+https://github.com/gnosis/prediction-market-agent-tooling.git@main"
],
function_file=f"{current_dir}/agent.py",
market_type=MarketType.MANIFOLD,
api_keys={"MANIFOLD_API_KEY": APIKeys().manifold_api_key},
labels={
"owner": getpass.getuser()
}, # Only lowercase letters, numbers, hyphens and underscores are allowed.
env_vars={"EXAMPLE_ENV_VAR": "Gnosis"},
# You can allow the cloud function to access secrets by adding the role: `gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} --member=serviceAccount:${GCP_SVC_ACC} --role=roles/container.admin`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! How do you know what to set GCP_SVC_ACC to here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find it in the console of your cloud function, or you can deploy the function with a specified service account:

Screenshot by Dropbox Capture

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

secrets={
"MANIFOLD_API_KEY": f"JUNG_PERSONAL_GMAIL_MANIFOLD_API_KEY:latest"
}, # Must be in the format "env_var_in_container => secret_name:version", you can create secrets using `gcloud secrets create --labels owner=<your-name> <secret-name>` command.
memory=512,
)

Expand Down
8 changes: 6 additions & 2 deletions prediction_market_agent_tooling/deploy/gcp/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def deploy_to_gcp(
function_file: str,
requirements_file: t.Optional[str],
extra_deps: list[str],
api_keys: dict[str, str],
labels: dict[str, str],
env_vars: dict[str, str],
secrets: dict[str, str],
market_type: MarketType,
memory: int, # in MB
) -> str:
Expand Down Expand Up @@ -66,7 +68,9 @@ def deploy_to_gcp(
gcp_function_name=gcp_fname,
source=tempdir,
entry_point="main", # TODO check this function exists in main.py
api_keys=api_keys,
labels=labels,
env_vars=env_vars,
secrets=secrets,
memory=memory,
)
subprocess.run(cmd, shell=True)
Expand Down
10 changes: 8 additions & 2 deletions prediction_market_agent_tooling/deploy/gcp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def gcloud_deploy_cmd(
gcp_function_name: str,
source: str,
entry_point: str,
api_keys: dict[str, str],
labels: dict[str, str],
env_vars: dict[str, str],
secrets: dict[str, str],
memory: int, # in MB
) -> str:
cmd = (
Expand All @@ -25,8 +27,12 @@ def gcloud_deploy_cmd(
f"--memory {memory}MB "
f"--no-allow-unauthenticated "
)
for k, v in api_keys.items():
for k, v in labels.items():
cmd += f"--update-labels {k}={v} "
for k, v in env_vars.items():
cmd += f"--set-env-vars {k}={v} "
for k, v in secrets.items():
cmd += f"--set-secrets {k}={v} "

return cmd

Expand Down
Loading