Skip to content

Deploy TransformationSvc to PathCloud Google Cloud Run Jobs

Pre-requisites

  • Google Cloud SDK https://cloud.google.com/sdk/docs/install

ImageTransformation FastAPI Service

Build the container image

docker build --pull --rm -f "container/Dockerfile" -t imagetransformsvc_worker:1.4.1 .

Run the container image locally and mount the local directory

docker run --rm -p 8080:8080 -v /mnt/g/Datasets/LoadTest-Multi/:/temp_files/Input -e ITS_SFTPFileInputPath=/temp_files/Input imagetransformsvc_worker:1.4.1 python3 cli.py path2dcmweb --dcm_input TransformSvcGCPDICOM/SVS/JP2K-33003-1.svs --metadata_input TransformSvcGCPDICOM/SVS/613392.json --url https://dicom.poc1.gestaltcloud.com/proxy01/projects/gcp-pathology-poc1/locations/us-west2/datasets/dicom-pathology/dicomStores/slide-dicom-store-public/dicomWeb

Upload to DICOMWeb should fail because no service account is configured.

Tag the container image

docker tag imagetransformsvc_worker:1.4.1 us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1

Push the container image to Google Container Registry

gcloud auth login
docker push us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1

Deploy to GCP Cloud Run JOB

gcloud config set project gcp-pathology-poc1 && \
gcloud beta run jobs create imagetransformsvc-worker \
  --image us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1 \
  --region=us-west2 \
  --command="python3,cli.py" \
  --memory=16Gi --cpu=8 \
  --parallelism=10 \
  --task-timeout=3h \
  --max-retries=1 \
  --network default --subnet default \
  --add-volume name=temp_files,type=cloud-storage,bucket=gcp-pathology-poc1-image-transformation-transformation-temp \
  --add-volume-mount volume=temp_files,mount-path=/temp_files \
  --set-env-vars="ITS_URL=https://dicom.poc1.gestaltcloud.com/public-proxy01/projects/gcp-pathology-poc1/locations/us-west2/datasets/dicom-pathology/dicomStores/slide-dicom-store-public/dicomWeb" \
  --set-env-vars="ITS_HANDLER=Inline" \
  --set-env-vars="ITS_KEEP_FILES_PATH=/temp_files" \
  --set-env-vars="ITS_SFTPFileInputPath=/temp_files/Input" \
  --set-env-vars="ITS_SFTPFileOutputPath=/temp_files/Output" \
  --set-env-vars="ITS_CELERY_BROKER_URL=redis://10.158.57.91:6379/9" \
  --set-env-vars="ITS_CELERY_RESULT_BACKEND=redis://10.158.57.91:6379/9" && \

Update the JOB with a new image

gcloud beta run jobs update imagetransformsvc-worker  --image us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1 --region=us-west2

Deploy to GCP Cloud Run

gcloud config set project gcp-pathology-poc1 && \
gcloud beta run deploy image-transform-svc --image us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1 \
--region=us-west2 --allow-unauthenticated \
--command=hypercorn \
--args=app:app,-w,8,-b,0.0.0.0:8080,--keep-alive,3600
--port 8080 --memory 8G --cpu 4 \
--network default --subnet default \
--add-volume name=temp_files,type=cloud-storage,bucket=gcp-pathology-poc1-image-transformation-transformation-temp \
--add-volume-mount volume=temp_files,mount-path=/temp_files \
--update-secrets=/secrets/slide-dicom-store-gcp-pathology-service.json=slide-dicom-store-gcp-pathology-service:latest \
--set-env-vars="ITS_SERVICE_ACCOUNT_KEY_LOCATION=/secrets/slide-dicom-store-gcp-pathology-service.json" \
--set-env-vars="ITS_URL=https://dicom.poc1.gestaltcloud.com/proxy01/projects/gcp-pathology-poc1/locations/us-west2/datasets/dicom-pathology/dicomStores/slide-dicom-store-public/dicomWeb" \
--set-env-vars="ITS_HANDLER=GCPJobs" \
--set-env-vars="ITS_KEEP_FILES_PATH=/temp_files" \
--set-env-vars="ITS_SFTPFileInputPath=/temp_files/Input" \
--set-env-vars="ITS_SFTPFileOutputPath=/temp_files/Output" \
--set-env-vars="ITS_MODE=default" \
--set-env-vars="ITS_CELERY_BROKER_URL=redis://10.158.57.91:6379/9" \
--set-env-vars="ITS_CELERY_RESULT_BACKEND=redis://10.158.57.91:6379/9" \
--set-env-vars="ITS_PROJECT_ID=gcp-pathology-poc1" \
--set-env-vars="ITS_REGION=us-west2" \
--set-env-vars="ITS_JOB_NAME=imagetransformsvc-worker" \

Update the service with a new image

gcloud beta run services update image-transform-svc --image us-west2-docker.pkg.dev/gcp-pathology-poc1/image-transform-svc/imagetransformsvc_worker:1.4.1 --region=us-west2 --command=hypercorn --args=app:app,-w,8,-b,0.0.0.0:8080,--keep-alive,3600