Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/deploy
diff options
context:
space:
mode:
authorGarret Kelly <gdk@google.com>2019-10-03 15:46:27 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-10-03 17:53:45 +0300
commit674e81ae8700bdd00d3e5e47ff930d42d25bc68b (patch)
tree5e88e28df459e99dc77a4ab5845c8be12db38fa7 /deploy
parent298092d516f623cc20051f506d460fb7625cdc84 (diff)
deploy: Add ability to invalidate Google Cloud CDN
Diffstat (limited to 'deploy')
-rw-r--r--deploy/deploy.go19
-rw-r--r--deploy/deployConfig.go4
-rw-r--r--deploy/google.go37
3 files changed, 55 insertions, 5 deletions
diff --git a/deploy/deploy.go b/deploy/deploy.go
index 9092431a5..1d911f29b 100644
--- a/deploy/deploy.go
+++ b/deploy/deploy.go
@@ -249,11 +249,20 @@ func (d *Deployer) Deploy(ctx context.Context) error {
jww.FEEDBACK.Println("Success!")
}
- if d.invalidateCDN && d.target.CloudFrontDistributionID != "" {
- jww.FEEDBACK.Println("Invalidating CloudFront CDN...")
- if err := InvalidateCloudFront(ctx, d.target.CloudFrontDistributionID); err != nil {
- jww.FEEDBACK.Printf("Failed to invalidate CloudFront CDN: %v\n", err)
- return err
+ if d.invalidateCDN {
+ if d.target.CloudFrontDistributionID != "" {
+ jww.FEEDBACK.Println("Invalidating CloudFront CDN...")
+ if err := InvalidateCloudFront(ctx, d.target.CloudFrontDistributionID); err != nil {
+ jww.FEEDBACK.Printf("Failed to invalidate CloudFront CDN: %v\n", err)
+ return err
+ }
+ }
+ if d.target.GoogleCloudCDNOrigin != "" {
+ jww.FEEDBACK.Println("Invalidating Google Cloud CDN...")
+ if err := InvalidateGoogleCloudCDN(ctx, d.target.GoogleCloudCDNOrigin); err != nil {
+ jww.FEEDBACK.Printf("Failed to invalidate Google Cloud CDN: %v\n", err)
+ return err
+ }
}
jww.FEEDBACK.Println("Success!")
}
diff --git a/deploy/deployConfig.go b/deploy/deployConfig.go
index 0ea675b82..3bc51294d 100644
--- a/deploy/deployConfig.go
+++ b/deploy/deployConfig.go
@@ -37,6 +37,10 @@ type target struct {
URL string
CloudFrontDistributionID string
+
+ // GoogleCloudCDNOrigin specifies the Google Cloud project and CDN origin to
+ // invalidate when deploying this target. It is specified as <project>/<origin>.
+ GoogleCloudCDNOrigin string
}
// matcher represents configuration to be applied to files whose paths match
diff --git a/deploy/google.go b/deploy/google.go
new file mode 100644
index 000000000..be3ce52f0
--- /dev/null
+++ b/deploy/google.go
@@ -0,0 +1,37 @@
+// Copyright 2019 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package deploy
+
+import (
+ "context"
+ "fmt"
+ "strings"
+
+ "google.golang.org/api/compute/v1"
+)
+
+// Invalidate all of the content in a Google Cloud CDN distribution.
+func InvalidateGoogleCloudCDN(ctx context.Context, origin string) error {
+ parts := strings.Split(origin, "/")
+ if len(parts) != 2 {
+ return fmt.Errorf("origin must be <project>/<origin>")
+ }
+ service, err := compute.NewService(ctx)
+ if err != nil {
+ return err
+ }
+ rule := &compute.CacheInvalidationRule{Path: "/*"}
+ _, err = service.UrlMaps.InvalidateCache(parts[0], parts[1], rule).Context(ctx).Do()
+ return err
+}