-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (64 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"os"
"github.com/HugoSTorres/quasimodo/amazon"
"github.com/HugoSTorres/quasimodo/hugo"
)
func init() {
flag.Usage = func() {
fmt.Println("usage: quasimodo --bucket <s3 bucket> [--region <s3 region>]")
flag.PrintDefaults()
}
}
func main() {
var bucket, region, cache string
flag.StringVar(®ion, "region", "us-east-1", "the region containing the s3 bucket")
flag.StringVar(&bucket, "bucket", "", "the bucket hosting the site")
flag.StringVar(&cache, "cloudfront-id", "", "the id of the cloudfront distribution serving for the bucket")
flag.Parse()
if len(bucket) == 0 {
flag.Usage()
os.Exit(1)
}
fmt.Println("building site")
err := hugo.Build()
if err != nil {
fmt.Printf("error building site: %v\n", err)
os.Exit(1)
}
fmt.Println("getting aws credentials and opening session")
svc, err := amazon.NewService(region, bucket)
if err != nil {
fmt.Printf("error creating s3 session: %v\n", err)
os.Exit(1)
}
fmt.Println("checking bucket website configuration")
err = svc.CheckWWW()
if err != nil {
fmt.Printf("error creating s3 session: %v\n", err)
os.Exit(1)
}
fmt.Println("cleaning bucket")
err = svc.Clean()
if err != nil {
fmt.Printf("error cleaning bucket %v: %v\n", svc.Bucket, err)
os.Exit(1)
}
fmt.Println("uploading public folder")
err = svc.Publish()
if err != nil {
fmt.Printf("error publishing site: %v\n", err)
os.Exit(1)
}
if len(cache) != 0 {
fmt.Println("invalidating cloudfront")
err = svc.BustCache(cache)
if err != nil {
fmt.Printf("error invalidating cloudfront: %v\n", err)
os.Exit(1)
}
fmt.Println("cloudfront invalidation triggered (could take some time)")
}
}