Giter Club home page Giter Club logo

gcp-thumbor-stack's Introduction

GCP Thumbor Stack

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.

Create and test the stack

Set up your project APIs and permissions

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

Build the stack

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

Test the stack

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

Deleting the stack

First remove any images from your storage bucket, then run:

gcloud deployment-manager deployments delete thumbor-test

Make production ready

For production:

  • Adjust the zones and storageLocation values as needed
  • You need to set the securityKey to a unique value
  • You will also most likely want to set allowUnsafe to false 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

gcp-thumbor-stack's People

Contributors

rabidgremlin avatar

Stargazers

Rahmat Nugraha avatar Srđan (Serge) Đukić avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.