If you have a website that hosts versioned copies of files such as software packages, documents or save games, which vary only slightly between versions, it makes sense to download only the difference between the version the client already has and the new one that they want. Using Fastly, we can compute the diff and generate a patch without having to add that feature to your origin server.
Fastly is a CDN, but with our Edge Cloud tools and technologies it's possible to do far more than you might think. This repo is an idea I had to demonstrate how cloud compute tools can be combined with Fastly to do very clever things at the edge.
- Install prerequisites:
- Google Cloud Platform SDK, to push cloud functions to Google's platform.
- Create a Cloud Storage bucket on Google Cloud Platform and put the name of it into the
deploy.sh
file - Deploy the cloud function with
npm run deploy
and note the HTTPS URL of the deployed function - Create a Fastly service with two origin servers:
- File server hosting your static, versioned files
- Diff service using the URL that you got from deploying the cloud function
- Update
fastly-service.vcl
with the hostname of your Cloud function - Upload the VCL to your Fastly service
If you don't want to deploy the function to GCF to test it, you can also run a local server that makes it accessible on your machine with npm start
- Install Docker, to run the Google cloud platform docker instance
- Copy the contents of the Google Cloud platform dockerfile to an empty folder
- Build the container with
docker build .
- Find the container ID with
docker images
- Run the container with
docker run -v $(pwd):/hostos -it 97bea97cfbbd /bin/bash
(replace the ID with the one from thedocker images
output) - Inside the container:
- Use the home directory:
cd /home
- Download bsdiff:
curl http://www.daemonology.net/bsdiff/bsdiff-4.3.tar.gz -o bsdiff.tgz
- Unpack:
tar zxvf bsdiff.tgz
- Install an editor:
apt-get update; apt-get install nano
(or whatever editor you want to use for the next step) - Apply these changes to the downloaded files:
- Insert a tab at the start of lines 13 and 15 of Makefile
- Add the line
#include <sys/types.h>
at the top ofbspatch.c
- Install required library:
apt-get install libbz2-dev
- Make!
make
- Copy the resulting binaries to your host OS:
cp bsdiff bspatch /hostos/
- Quit:
exit
- Use the home directory: