Deployment Manager scripts to create an end to end Thumbor image resizing and cropping stack on the Google Cloud Platform
This script creates a HTTP Cloud Load Balancer, pointing at a cluster of Thumbor services distributed across one or more zones. The Thumbor servers are configured to process images from a storage bucket and the whole stack is front-ended by a Cloud CDN for speed and scalability.
In your Cloud Shell, run the following commands to turn on the APIs needed to run these deployment manager scripts and the stack:
gcloud services enable iam.googleapis.com
gcloud services enable compute.googleapis.com
gcloud services enable storage-api.googleapis.com
gcloud services enable deploymentmanager.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable logging.googleapis.com
gcloud services enable monitoring.googleapis.com
Run the following command to get you project number
gcloud projects describe $DEVSHELL_PROJECT_ID
Finally, give the default cloud services service account owner rights so that the deployment manager scripts can assign IAM roles. Replace [PROJECT_NUMBER] with your project number:
gcloud projects add-iam-policy-binding $DEVSHELL_PROJECT_ID --member serviceAccount:[PROJECT_NUMBER]@cloudservices.gserviceaccount.com --role roles/owner
Again in your Cloud Shell, run the following commands. You can run replace thumbor-test
with your own name. All resources created by the deployment manager scripts are pre-fixed with this name.
git clone https://github.com/rabidgremlin/gcp-thumbor-stack.git
cd gcp-thumbor-stack
gcloud deployment-manager deployments create thumbor-test --config deploy.yaml
Add an example image to your bucket. You will need to replace [BUCKET_NAME] with the name of storage bucket output by the deployment manager:
wget https://images.pexels.com/photos/2216727/pexels-photo-2216727.jpeg?fm=jpg -O smiling-man-and-woman-sitting-on-pavement-2216727.jpg
gsutil cp smiling-man-and-woman-sitting-on-pavement-2216727.jpg gs://[BUCKET_NAME]
Determine public IP address of CDN/Load balancer
gcloud compute forwarding-rules list
In a browser retrieve a resized image. Replace [IP_ADDRESS] with the IP address of your load balancer
http://[IP_ADDRESS]/unsafe/200x200/smart/smiling-man-and-woman-sitting-on-pavement-2216727.jpg
Note: You may have to wait several minutes after your stack has been created for this image retrieve to work
You can also simulate load on the stack by:
sudo apt-get -y install apache2-utils
ab -n 100 -c 2 http://[IP_ADDRESS]/unsafe/500x200/smart/smiling-man-and-woman-sitting-on-pavement-2216727.jpg
If you change the parameters in the URL and rerun multiple times you can see the speed improvements as the resized image is cached by Cloud CDN.
You can also force your cluster to scale by deliberate forcing cache misses:
ab -n 100 -c 5 http://[IP_ADDRESS]/unsafe/`date +%N | cut -c 7-`x200/smart/smiling-man-and-woman-sitting-on-pavement-2216727.jpg
First remove any images from your storage bucket, then run:
gcloud deployment-manager deployments delete thumbor-test
For production:
- Adjust the
zones
andstorageLocation
values as needed - You need to set the
securityKey
to a unique value - You will also most likely want to set
allowUnsafe
tofalse
to require signed URLs - You will need to configure DNS to point a domain at the IP address of the load balancer
- If you want to set up SSL you will need configure a HTTPS front-end and a SSL certificate