def gcp_setproject(): list_cmd = "gcloud projects list" output, error = run_bash_cmd(list_cmd) output = output.decode("utf-8") if output else output error = error.decode("utf-8") if error else error project_id = os.environ[PROJECT_ID] if output.find(project_id) == -1 or error: config_cmd = "gcloud config set project {}".format(project_id) run_bash_cmd(config_cmd)
def deploy_container(model_id, region, auth): try: deploy_cmd = "gcloud run deploy {} --image gcr.io/{}/{} --platform managed --region {} {}".format( model_id, os.environ[PROJECT_ID], model_id, region, auth) run_bash_cmd(deploy_cmd) print("Make predictions by appending /{} to the deployment url above.". format(os.getenv(MODEL_ROUTE, ""))) except: raise Exception(CONTAINER_ERROR)
def gcp_auth(): try: auth_list_cmd = "gcloud auth list" auth_output = run_bash_cmd(auth_list_cmd) if (auth_output and int(auth_output.find("No credentialed accounts.")) != -1): login_cmd = "gcloud auth login" run_bash_cmd(login_cmd) except: raise AUTH_ERROR
def gcp_setproject(): try: list_cmd = "gcloud projects list" output = run_bash_cmd(list_cmd) project_id = os.environ[PROJECT_ID] if output and int(output.find(project_id)) == -1: config_cmd = "gcloud config set project {}".format(project_id) run_bash_cmd(config_cmd) except: raise AUTH_ERROR
def build_container(model_id, yaml=False): # https://stackoverflow.com/questions/48066114/execute-bash-commands-python-way # https://stackoverflow.com/questions/52415779/python-run-bash-commands-sequentially # https://cloud.google.com/run/docs/quickstarts/build-and-deploy # running bash cmd in python here, need to do this b/c there isn't a python sdk for this yet try: imagebuild_cmd = "gcloud builds submit --tag gcr.io/{}/{}".format( os.environ[PROJECT_ID], model_id) run_bash_cmd(imagebuild_cmd) except: raise Exception(CONTAINER_ERROR)
def gcp_auth(): try: auth_list_cmd = "gcloud auth list" auth_output, auth_error = run_bash_cmd(auth_list_cmd) auth_output = auth_output.decode( "utf-8") if auth_output else auth_output auth_error = auth_error.decode("utf-8") if auth_error else auth_error if (auth_output and auth_output.find("No credentialed accounts.") != -1 ) or auth_error: login_cmd = "gcloud auth login" login_output, login_error = run_bash_cmd(login_cmd) except: raise