Blue / Green Deployments
Problem
You want to utilize a blue-green deployment method to safely deploy changes to production content.
Solution
Use Vanity URLs API to switch traffic between deployments. In this example, we assume that blue content has an assigned vanity URL. See Viewing a Content Items Vanity URL.
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.get(f"/v1/content/{BLUE_CONTENT_GUID}/vanity").json()
response = response.json()['path'] path
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
f'v1/content/{GREEN_CONTENT_GUID}/vanity', json={
client.put('force': True,
'path': path
})
= "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.get(f"/v1/content/{BLUE_CONTENT_GUID}/vanity").json()
response = response.json()['path']
path f'v1/content/{GREEN_CONTENT_GUID}/vanity', json={
client.put('force': True,
'path': path
})
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.