Skip to content

Support for Blue/Green Deployment #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions etc/vcl_snippets/deliver.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
return(deliver);
}

if ( fastly.ff.visits_this_service == 0 ) {
if ( req.http.Cookie:deploy_version != req.http.request_version && req.http.request_version != table.lookup(magentomodule_config, "current_version", "DEFAULT") ) {
set beresp.http.Set-Cookie:deploy_version = req.http.request_version;
}
# Tell the browser to delete the deploy_version cookie if the requested_version is current version
if ( req.http.Cookie:deploy_version != "" && req.http.request_version == table.lookup(magentomodule_config, "current_version", DEFAULT ) ) {
add beresp.http.Set-Cookie = "deploy_version=DEFAULT; Expires=Wed Jun 01 2022 00:00:00 GMT";
}
}

# Send no cache headers to end users for non-static content created by Magento
if (resp.http.X-Magento-Tags && fastly.ff.visits_this_service == 0 ) {
set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
Expand Down
6 changes: 3 additions & 3 deletions etc/vcl_snippets/fetch.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@

# init surrogate keys
if (beresp.http.X-Magento-Tags) {
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags " text";
set beresp.http.Surrogate-Key = beresp.http.X-Magento-Tags + " text text-" + table.lookup(magentomodule_config, "current_version", "DEFAULT") ;
} else {
set beresp.http.Surrogate-Key = "text";
set beresp.http.Surrogate-Key = "text text-" + table.lookup(magentomodule_config, "current_version", "DEFAULT");
}

# set surrogate keys by content type if they are image/script or CSS
if (beresp.http.Content-Type ~ "(image|script|css)") {
set beresp.http.Surrogate-Key = re.group.1;
set beresp.http.Surrogate-Key = re.group + " " + re.group.1 + "-" + table.lookup(magentomodule_config, "current_version", "DEFAULT");
}
}

Expand Down
3 changes: 3 additions & 0 deletions etc/vcl_snippets/hash.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Add support for versions of the cache depending on the blue/green model. If not specified default to DEFAULT
set req.hash += req.http.request_version;

if (req.http.graphql) {
# GraphQL should cache on X-Magento-Cache-Id if available, which has a bunch of variations so it should be part of the key and not a Vary factor
if (req.http.X-Magento-Cache-Id) {
Expand Down
15 changes: 15 additions & 0 deletions etc/vcl_snippets/recv.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
if ( table.lookup(magentomodule_config, "current_version", "DEFAULT") != table.lookup(magentomodule_config, "next_version", "DEFAULT") ) {
# Check if user has the deploy version
if ( req.http.Cookie:deploy_version != table.lookup(magentomodule_config, "current_version", "DEFAULT")
&& req.http.Cookie:deploy_version != table.lookup(magentomodule_config, "next_version", "DEFAULT") ) {
# Next Version differs from Current Version. Let's roll out a percentage of traffic
if (randombool(std.atoi(table.lookup(magentomodule_config, "rollout_percentage", "0")), 100)) {
set req.http.request_version = table.lookup(magentomodule_config, "next_version");
}
}

# If request version has not been set by rollout percentage set to current version
if ( !req.http.request_version ) {
set req.http.request_version = table.lookup(magentomodule_config, "current_version", "DEFAULT");
}

# When using Magento tester to test whether your site is configured properly
# this uses a bypass secret. By default we will use service ID as the bypass secret
# however user can override this by defining a bypass_secret key in the
Expand Down