Skip to content

Commit

Permalink
Add support for gcp secrets and labels (#11)
Browse files Browse the repository at this point in the history
* Add support for gcp secrets and labels
  • Loading branch information
kongzii authored Feb 15, 2024
1 parent 9234c2b commit 878ffea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
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`.
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

0 comments on commit 878ffea

Please sign in to comment.