fix(CI4): bruk regional cloudbuild endpoint via client_options
This commit is contained in:
parent
3c69490a68
commit
3fd3d30ac3
|
|
@ -25,6 +25,16 @@ def verify_token(x_mcp_key: str = Header(default="")):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _cloudbuild_client():
|
||||||
|
"""Returnerer CloudBuildClient koblet til regional endpoint."""
|
||||||
|
from google.cloud.devtools import cloudbuild_v1
|
||||||
|
from google.api_core.client_options import ClientOptions
|
||||||
|
endpoint = f"{REGION}-cloudbuild.googleapis.com"
|
||||||
|
return cloudbuild_v1.CloudBuildClient(
|
||||||
|
client_options=ClientOptions(api_endpoint=endpoint)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PushStaticRequest(BaseModel):
|
class PushStaticRequest(BaseModel):
|
||||||
file_path: str
|
file_path: str
|
||||||
content: str
|
content: str
|
||||||
|
|
@ -84,13 +94,13 @@ async def push_static(req: PushStaticRequest, _: bool = Depends(verify_token)):
|
||||||
@app.get("/tools/get_build_status")
|
@app.get("/tools/get_build_status")
|
||||||
async def get_build_status(_: bool = Depends(verify_token)):
|
async def get_build_status(_: bool = Depends(verify_token)):
|
||||||
"""
|
"""
|
||||||
Henter siste build fra osvauco-agent-main-trigger (us-central1).
|
Henter siste build fra osvauco-agent-main-trigger.
|
||||||
Bruker regional parent-format: projects/{project}/locations/{region}
|
Bruker regional endpoint: {region}-cloudbuild.googleapis.com
|
||||||
|
og parent: projects/{project}/locations/{region}
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from google.cloud.devtools import cloudbuild_v1
|
from google.cloud.devtools import cloudbuild_v1
|
||||||
client = cloudbuild_v1.CloudBuildClient()
|
client = _cloudbuild_client()
|
||||||
# Regional builds krever parent i stedet for project_id
|
|
||||||
parent = f"projects/{PROJECT_ID}/locations/{REGION}"
|
parent = f"projects/{PROJECT_ID}/locations/{REGION}"
|
||||||
request = cloudbuild_v1.ListBuildsRequest(
|
request = cloudbuild_v1.ListBuildsRequest(
|
||||||
parent=parent,
|
parent=parent,
|
||||||
|
|
@ -129,7 +139,7 @@ async def get_build_status(_: bool = Depends(verify_token)):
|
||||||
async def deploy_service(req: DeployServiceRequest, _: bool = Depends(verify_token)):
|
async def deploy_service(req: DeployServiceRequest, _: bool = Depends(verify_token)):
|
||||||
try:
|
try:
|
||||||
from google.cloud.devtools import cloudbuild_v1
|
from google.cloud.devtools import cloudbuild_v1
|
||||||
client = cloudbuild_v1.CloudBuildClient()
|
client = _cloudbuild_client()
|
||||||
trigger_id = req.trigger_id or BUILD_TRIGGER_ID
|
trigger_id = req.trigger_id or BUILD_TRIGGER_ID
|
||||||
subs = {"BRANCH_NAME": req.branch, **req.substitutions}
|
subs = {"BRANCH_NAME": req.branch, **req.substitutions}
|
||||||
response = client.run_build_trigger(
|
response = client.run_build_trigger(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user