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
BLUE_CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
client = connect.Client()
blue = client.content.get(BLUE_CONTENT_GUID)library(connectapi)
BLUE_CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
client <- connect()
blue <- content_item(client, BLUE_CONTENT_GUID)
vanity <- get_vanity_url(blue)Then swap the Vanity URL to point to the green content using the unique identifier (guid) for the content.
GREEN_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
green = client.content.get(GREEN_CONTENT_GUID)
green.create_vanity(blue.vanity, force=True)GREEN_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
green <- content_item(client, GREEN_CONTENT_GUID)
set_vanity_url(green, vanity, TRUE)Full example
from posit import connect
BLUE_CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
GREEN_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
client = connect.Client()
blue = client.content.get(BLUE_CONTENT_GUID)
green = client.content.get(GREEN_CONTENT_GUID)
green.create_vanity(blue.vanity, force=True)library(connectapi)
BLUE_CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
GREEN_CONTENT_GUID = "2d178c46-4dca-40b0-bf22-a21e1cfb5b46"
client <- connect()
blue <- content_item(client, BLUE_CONTENT_GUID)
vanity <- get_vanity_url(blue)
green <- content_item(client, GREEN_CONTENT_GUID)
set_vanity_url(green, vanity, TRUE)Discussion
A blue-green deployment strategy ensures that production content does not incur downtime during upgrades.