4
4
import time
5
5
6
6
from google .cloud .devtools import cloudbuild_v1
7
- from google .cloud .devtools .cloudbuild_v1 .types import Build , BuildStep , BuildOptions , Source , StorageSource
7
+ from google .cloud .devtools .cloudbuild_v1 .types import Build , BuildStep , Source , StorageSource
8
8
from google .cloud import storage
9
9
10
- # from google.api_core.exceptions import NotFound
11
-
12
10
from deploy import deploy_cloud_run_service
13
11
14
12
PROJECT_ID = os .environ ["GOOGLE_CLOUD_PROJECT" ]
@@ -76,9 +74,6 @@ def build_image_from_source(
76
74
)
77
75
],
78
76
timeout = {"seconds" : 1200 },
79
- options = BuildOptions (
80
- # Example: machine_type=BuildOptions.MachineType.E2_MEDIUM
81
- )
82
77
)
83
78
84
79
print (f"Starting Cloud Build for image { full_image_uri } ..." )
@@ -123,13 +118,11 @@ def build_image_from_source(
123
118
SOURCE_DIRECTORY = "./source/"
124
119
GCS_BUILD_BUCKET = f"{ PROJECT_ID } _cloudbuild_sources"
125
120
126
- ENVIRONMENT_VARIABLES = {
127
- # "APP_MESSAGE": "Deployed from source via Python!",
128
- }
121
+ ENVIRONMENT_VARIABLES = {}
129
122
130
123
built_image_uri = None
131
124
try :
132
- print (f"--- Step 1: Building image for { SERVICE_NAME } from source { SOURCE_DIRECTORY } --- " )
125
+ print (f"Step 1: Building image for { SERVICE_NAME } from source { SOURCE_DIRECTORY } . " )
133
126
built_image_uri = build_image_from_source (
134
127
project_id = PROJECT_ID ,
135
128
region = REGION ,
@@ -139,7 +132,7 @@ def build_image_from_source(
139
132
)
140
133
141
134
if built_image_uri :
142
- print (f"\n --- Step 2: Deploying image { built_image_uri } to Cloud Run service { SERVICE_NAME } --- " )
135
+ print (f"\n Step 2: Deploying image { built_image_uri } to Cloud Run service { SERVICE_NAME } . " )
143
136
deploy_cloud_run_service (
144
137
project_id = PROJECT_ID ,
145
138
region = REGION ,
@@ -148,11 +141,11 @@ def build_image_from_source(
148
141
env_vars = ENVIRONMENT_VARIABLES ,
149
142
allow_unauthenticated = True ,
150
143
)
151
- print (f"\n --- Deployment process for { SERVICE_NAME } finished --- " )
144
+ print (f"\n Deployment process for { SERVICE_NAME } finished. " )
152
145
else :
153
146
print (f"Image build failed for { SERVICE_NAME } . Deployment aborted." )
154
147
155
148
except Exception as e :
156
149
print (f"An error occurred during the build or deployment process: { e } " )
157
150
import traceback
158
- traceback .print_exc ()
151
+ traceback .print_exc ()
0 commit comments