Blue / Green Deployments
Problem
You want to utilize a blue-green deployment method to safely deploy changes to production content.
Solution
Use Vanity URLs to switch traffic between deployments. In this example, we assume that blue Content has an assigned Vanity URL path. See Viewing Vanity URLs.
Get Vanity URL from the blue content using the unique identifier (guid) for the content.
from posit import connect
= "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
BLUE_CONTENT_GUID
= connect.Client()
client
= client.content.get(BLUE_CONTENT_GUID) blue
library(connectapi)
= "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
BLUE_CONTENT_GUID
<- connect()
client <- content_item(client, BLUE_CONTENT_GUID)
blue <- get_vanity_url(content) vanity
Then swap the Vanity URL to point to the green content using the unique identifier (guid) for the content.
= "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
GREEN_CONTENT_GUID
= client.content.get(GREEN_CONTENT_GUID)
green =True) green.create_vanity(blue.vanity, force
= "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
GREEN_CONTENT_GUID
<- content_item(client, BLUE_CONTENT_GUID)
green set_vanity_url(content, vanity, TRUE)
Full example
from posit import connect
= "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
BLUE_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
GREEN_CONTENT_GUID
= connect.Client()
client = client.content.get(BLUE_CONTENT_GUID)
blue = client.content.get(GREEN_CONTENT_GUID)
green =True) green.create_vanity(blue.vanity, force
library(connectapi)
= "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
BLUE_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
GREEN_CONTENT_GUID
<- connect()
client <- content_item(client, BLUE_CONTENT_GUID)
blue <- get_vanity_url(content)
vanity <- content_item(client, BLUE_CONTENT_GUID)
green set_vanity_url(content, vanity, TRUE)
Discussion
A blue-green deployment strategy ensures that production content does not incur downtime during upgrades.