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 all 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
2 changes: 1 addition & 1 deletion Model/Layout/LayoutPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function afterGenerateElements(\Magento\Framework\View\Layout $subject)
public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result) // @codingStandardsIgnoreLine - unused parameter
{
if ($this->config->getType() === Config::FASTLY) {
$this->response->setHeader("Fastly-Module-Enabled", "1.2.189", true);
$this->response->setHeader("Fastly-Module-Enabled", "1.2.190", true);
}

return $result;
Expand Down
5 changes: 5 additions & 0 deletions Release-Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Fastly_Cdn Release Notes

## 1.2.190

- Update WAF to WAF2020 https://github.com/fastly/fastly-magento2/pull/578
- Response Plugin fixes https://github.com/fastly/fastly-magento2/pull/577

## 1.2.189

- Additional fix for rate limiting enablement errors https://github.com/fastly/fastly-magento2/pull/575
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.189
1.2.190
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"zordius/lightncandy": "^1.2"
},
"type": "magento2-module",
"version": "1.2.189",
"version": "1.2.190",
"license": "BSD-3-Clause",
"autoload": {
"files": [ "registration.php" ],
Expand Down
12 changes: 11 additions & 1 deletion 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.Platformsh-Version && req.http.Platformsh-Version != table.lookup(magentomodule_config, "current_version", "DEFAULT") ) {
set beresp.http.Set-Cookie:deploy_version = req.http.Platformsh-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.Platformsh-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 Expand Up @@ -39,7 +49,7 @@

# Add an easy way to see whether custom Fastly VCL has been uploaded
if ( req.http.Fastly-Debug ) {
set resp.http.Fastly-Magento-VCL-Uploaded = "1.2.189";
set resp.http.Fastly-Magento-VCL-Uploaded = "1.2.190";
} else {
remove resp.http.Fastly-Module-Enabled;
remove resp.http.fastly-page-cacheable;
Expand Down
10 changes: 7 additions & 3 deletions etc/vcl_snippets/fetch.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
return (pass);
}

# We are extending the default Fastly behavior to include no-cache/no-store in addition to private
if (beresp.http.Cache-Control ~ "private|no-cache|no-store") {
set req.http.Fastly-Cachetype = "PRIVATE";
return (pass);
Expand All @@ -88,6 +89,9 @@

if (beresp.http.x-amz-request-id) {
# If assets are coming from Amazon they may have no Cache-Control headers which may make them uncacheable

# If the object is coming with no Expires, Surrogate-Control or Cache-Control headers we assume it's a misconfiguration
# and we will not cache it. This is to prevent inadventently caching private data
} else if (!beresp.http.Expires && !beresp.http.Surrogate-Control ~ "max-age" && !beresp.http.Cache-Control ~ "(s-maxage|max-age)") {
# Varnish sets default TTL if none of the headers above are present. If not set we want to make sure we don't cache it
set beresp.ttl = 0s;
Expand All @@ -101,14 +105,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.Platformsh-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
2 changes: 1 addition & 1 deletion etc/vcl_snippets/miss.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
unset bereq.http.Accept-Encoding;

# Send VCL version uploaded to the backend
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.189";
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.190";
2 changes: 1 addition & 1 deletion etc/vcl_snippets/pass.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
}

# Send VCL version uploaded to the backend
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.189";
set bereq.http.Fastly-Magento-VCL-Uploaded = "1.2.190";
34 changes: 23 additions & 11 deletions etc/vcl_snippets/recv.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Don't allow clients to force a pass, mess with rate limiting or admin path
if (req.restarts == 0) {
unset req.http.x-pass;
unset req.http.Rate-Limit;
unset req.http.magento-admin-path;
}
unset req.http.x-long-cache;

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.Platformsh-Version = table.lookup(magentomodule_config, "next_version");
}
}

# If request version has not been set by rollout percentage set to current version
if ( !req.http.Platformsh-Version ) {
set req.http.Platformsh-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 Expand Up @@ -44,8 +67,6 @@
}
}

unset req.http.x-long-cache;

# We want to force long cache times on any of the versioned assets
if (req.url.path ~ "^/static/version\d*/") {
set req.http.x-long-cache = "1";
Expand Down Expand Up @@ -129,15 +150,6 @@
set req.url = querystring.regfilter(req.url, "^(####QUERY_PARAMETERS####)$");
}

# Don't allow clients to force a pass
if (req.restarts == 0) {
if ( !req.http.bypass-secret ) {
unset req.http.x-pass;
}
unset req.http.Rate-Limit;
unset req.http.magento-admin-path;
}

# Pass on checkout URLs. Because it's a snippet we want to execute this after backend selection so we handle it
# in the request condition
if (!req.http.x-long-cache && req.url ~ "/(checkout|customer/section/load)") {
Expand Down