Giter Site home page Giter Site logo

productlabs / cloudflare-workers-kv-canary-releases Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stuartsan/cloudflare-workers-kv-canary-releases

0.0 0.0 0.0 107 KB

Demo of deploying a static site to Workers KV and doing canary releases at the edge

Home Page: https://stuartsandine.com/canary-releases-cloudflare-workers-kv/

CSS 1.08% HTML 5.91% Go 65.65% JavaScript 27.36%

cloudflare-workers-kv-canary-releases's Introduction

Canary releases at the edge with Cloudflare workers

This project demonstrates A) how to continuously deploy a static site directly to Cloudflare Workers KV store at edge locations and B) how to do canary releases (AKA staged rollouts AKA phased rollouts) at the edge.

The worker script defines the stages: whether they're based on ip address, geolocation, user segments, random samples / increasing percentages and cookie setting to make it sticky, whatever.

Requirements

  • serverless framework
  • CloudFlare account
  • golang

Setup

The first step is to go into your Cloudflare account, visit the dashboard for the site on which you want to deploy the worker, enable workers, and enable workers KV.

Locate each of the following items and set environment variables for them on your local machine:

  • API key => CLOUDFLARE_AUTH_KEY
  • Email => CLOUDFLARE_AUTH_EMAIL
  • Account ID => CLOUDFLARE_ACCOUNT
  • Zone => CLOUDFLARE_ZONE

Deploy the worker, create the KV namespaces, and bind them to the worker: serverless deploy

Deploy app

Deploy both the current and next versions so we have a "new" thing to release:

go run deploy.go -dir app/current/ -deploy-id current

go run deploy.go -dir app/next/ -deploy-id next

current and next are ids for demonstration purposes. Probably use a git commit SHA instead for deploy ids!

Doing canary releases

To send all production traffic to the "current" version of the app:

go run release.go -deploy-id current

And then do a canary release for next version, releasing it to stage 1:

go run release.go -deploy-id next -stage 1

And then releasing it to stage 2:

go run release.go -deploy-id next -stage 2

And then all production traffic to "next":

go run release.go -deploy-id next

cloudflare-workers-kv-canary-releases's People

Contributors

stuartsan 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.