Skip to content

Commit

Permalink
Merge pull request #254 from cloud-quickstart/canary
Browse files Browse the repository at this point in the history
#220 - cloud run master automation
  • Loading branch information
fmichaelobrien authored Jan 10, 2023
2 parents 81298fc + b767fa7 commit 91785a1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
2 changes: 1 addition & 1 deletion solutions/document-processing/apps/master/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ RUN pip install --no-cache-dir -r requirements.txt
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 solutions/document-processing/apps/master/main:app

14 changes: 9 additions & 5 deletions solutions/document-processing/apps/master/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ steps:

# [START cloudbuild_python_deploy_yaml]
# Deploy to Cloud Run
# - name: google/cloud-sdk
# args: ['gcloud', 'run', 'deploy', 'helloworld-${SHORT_SHA}',
# '--image=us-central1-docker.pkg.dev/${PROJECT_ID}/docproc3/dp-master:${SHORT_SHA}',
# '--region', 'us-central1', '--platform', 'managed',
# '--allow-unauthenticated']
# AR_NAME
# DOCKER_MASTER_IMAGE_NAME
#- name: google/cloud-sdk
# args: ['gcloud', 'run', 'deploy', 'helloworld-${SHORT_SHA}',
# '--image=us-central1-docker.pkg.dev/${PROJECT_ID}/docproc3/dp-master:${SHORT_SHA}',
# '--region', 'us-central1', '--platform', 'managed',
# '--allow-unauthenticated']
# [END cloudbuild_python_deploy_yaml]

# [START cloudbuild_python_logs_yaml]
Expand All @@ -61,5 +63,7 @@ steps:
# Store images in Google Artifact Registry
images:
- us-central1-docker.pkg.dev/${PROJECT_ID}/docproc3/dp-master:${SHORT_SHA}
# ["gcr.io/$PROJECT_ID/magellan-nbi:latest"]
# - us-central1-docker.pkg.dev/${PROJECT_ID}/docproc3/dp-master:latest
# [END cloudbuild_python_yaml]
#
40 changes: 37 additions & 3 deletions solutions/document-processing/gcloud/deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,42 @@ create_ar() {
echo "create ar"
# enable csr role
#gcloud source repos set-iam-policy REPOSITORY_NAME POLICY_FILE
# ar
gcloud artifacts repositories create $AR_NAME --location=$REGION --repository-format=docker
}

delete_ar() {
echo "delete ar"
# test
gcloud artifacts repositories delete $AR_NAME --location=$REGION
}

create_cloudrun() {
echo "create cloud run"
# Get service account via project mumber env
gcloud run deploy ${CLOUD_RUN_MASTER_NAME} \
--image=${REGION}-docker.pkg.dev/${CC_PROJECT_ID}/${AR_NAME}/${CLOUD_RUN_MASTER_NAME}@sha256:19c7e0c35c47a2a408bde8d9a54402cbad94c46b5421f1b17bdf4f4b27010e60 \
--allow-unauthenticated \
--service-account=${PROJECT_NUMBER}-compute@developer.gserviceaccount.com \
--min-instances=1 \
--max-instances=10 \
--set-env-vars=GCS_BUCKET=${GCSBUCKET}=bucket,HOSTPATH=${HOSTPATH_MASTER} \
--no-cpu-throttling \
--execution-environment=gen2 \
--region=${REGION} \
--project=${CC_PROJECT_ID}

# get master cloud run url
export CLOUD_RUN_MASTER_URL=$(gcloud run services describe $CLOUD_RUN_MASTER_NAME --platform managed --region $REGION --format 'value(status.url)')
echo "Cloud Run URL for $CLOUD_RUN_MASTER_NAME: ${CLOUD_RUN_MASTER_URL}"
}

delete_cloudrun() {
echo "delete cloud run"
gcloud run services delete $CLOUD_RUN_MASTER_NAME --region=$REGION --quiet
}



delete_all() {
# delete service accounts
#gcloud iam service-accounts delete $SERVICE_ACCOUNT_M4A_CE_SRC@$PROJECT_ID.iam.gserviceaccount.com --project=$PROJECT_ID --quiet
Expand Down Expand Up @@ -563,10 +591,13 @@ if [[ "$CREATE_KCC" != false ]]; then
# check expiry https://cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding

# get GKE/ASM ids
export PROJECT_NUMBER=$(gcloud projects describe ${CC_PROJECT_ID} --format="value(projectNumber)")
# get project number
export PROJECT_NUMBER=$(gcloud projects list --filter="${CC_PROJECT_ID}" '--format=value(PROJECT_NUMBER)')
#export PROJECT_NUMBER=$(gcloud projects describe ${CC_PROJECT_ID} --format="value(projectNumber)")
export WORKLOAD_POOL=${CC_PROJECT_ID}.svc.id.goog
export MESH_ID="proj-${CC_PROJECT_NUMBER}"


create_roles_services
create_vpc
create_once_only
Expand All @@ -580,6 +611,8 @@ if [[ "$CREATE_KCC" != false ]]; then
# istio_injection_prod
# install_gateway_prod
# trigger_prod_main_build
create_cloudrun


else
echo "Switching to KCC project ${KCC_PROJECT_ID}"
Expand Down Expand Up @@ -628,11 +661,12 @@ fi
#create_cloudbuild_prod
#delete_cloudbuild_prod
#trigger_prod_main_build

#create_cloudrun

# delete
if [[ "$DELETE_KCC" != false ]]; then
echo "Deleting ${CC_PROJECT_ID}"
delete_cloudrun
# delete_clusters
# delete_istio_registration
delete_cloudbuild_prod
Expand Down
19 changes: 11 additions & 8 deletions solutions/document-processing/gcloud/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

###
# UPDATE
export REGION=us-central1
# root of current project dir
export ROOT_DIR=~/docproc-old
# generated project prefix
Expand All @@ -26,15 +27,20 @@ export PREFIX=pdt
# increment/verify
export CSR_NAME=docproc3
export AR_NAME=$CSR_NAME
# directory inside this current repo from where we run scripts
export GITHUB_GCLOUD_REPO_DIR=pubsec-declarative-toolkit/solutions/document-processing/gcloud
export CLOUD_RUN_MASTER_NAME=dp-master
export DOCKER_MASTER_IMAGE_NAME=dp-master
# no underscores
export SERVICE_ACCOUNT_MAIN=service-account-main
# current project - not the target project
#export BOOT_PROJECT_ID=$PROJECT_ID
export BOOT_PROJECT_ID=docproc-old
###

### APP SPECIFIC
export GCS_BUCKET=${CSR_NAME}-bucket
export HOSTPATH_MASTER=0.0.0.0
###

###
# DERIVED - do not edit
# current project - not the target project
Expand All @@ -45,19 +51,16 @@ export PROJECT_ID=$DEVSHELL_PROJECT_ID
# dir/name of internal source repo
#export SRC_REPO=docproc
export SRC_REPO=pubsec-declarative-toolkit
# directory inside this current repo from where we run scripts
export GITHUB_GCLOUD_REPO_DIR=${SRC_REPO}/solutions/document-processing/gcloud

# branch under use
export CSR_BRANCH_OTHER_THAN_MAIN=canary
# subfolder off root to hold CSR from github
export CSR_ROOT=csr
export REPO_TREE_DEPTH_FOR_CD_UP=../../../../
# after the fact - post service enablement - 2nd one
# not required
export CLOUD_BUILD_SA=880919021125@cloudbuild.gserviceaccount.com


export TEMP_REPO_DIR=temp0

export REGION=us-central1
export NETWORK=$REGION
export SUBNET=$NETWORK-sn
#export NETWORK=default
Expand Down

0 comments on commit 91785a1

Please sign in to comment.