|
1 | 1 | # s3deploy |
2 | 2 |
|
| 3 | +[](https://www.repostatus.org/#active) |
3 | 4 | [](https://godoc.org/github.com/bep/s3deploy) |
4 | | -[](https://travis-ci.org/bep/s3deploy) |
5 | | -[](https://ci.appveyor.com/project/bep/s3deploy) |
| 5 | +[](https://github.com/bep/s3deploy/actions/workflows/test.yml) |
6 | 6 | [](https://goreportcard.com/report/github.com/bep/s3deploy) |
7 | 7 | [](https://codecov.io/gh/bep/s3deploy) |
8 | 8 | [](https://github.com/bep/s3deploy/releases/latest) |
9 | 9 |
|
10 | 10 | A simple tool to deploy static websites to Amazon S3 and CloudFront with Gzip and custom headers support (e.g. "Cache-Control"). It uses ETag hashes to check if a file has changed, which makes it optimal in combination with static site generators like [Hugo](https://github.com/gohugoio/hugo). |
11 | 11 |
|
| 12 | + * [Install](#install) |
| 13 | + * [Configuration](#configuration) |
| 14 | + * [Flags](#flags) |
| 15 | + * [Routes](#routes) |
| 16 | + * [Global AWS Configuration](#global-aws-configuration) |
| 17 | + * [Example IAM Policy](#example-iam-policy) |
| 18 | + * [CloudFront CDN Cache Invalidation](#cloudfront-cdn-cache-invalidation) |
| 19 | + * [Example IAM Policy With CloudFront Config](#example-iam-policy-with-cloudfront-config) |
| 20 | + * [Background Information](#background-information) |
| 21 | + * [Alternatives](#alternatives) |
| 22 | + * [Stargazers over time](#stargazers-over-time) |
| 23 | + |
12 | 24 | ## Install |
13 | 25 |
|
14 | 26 | Pre-built binaries can be found [here](https://github.com/bep/s3deploy/releases/latest). |
15 | 27 |
|
16 | | -**s3deploy** is a [Go application](https://golang.org/doc/install), so you can also get and build it yourself via `go get`: |
| 28 | +**s3deploy** is a [Go application](https://golang.org/doc/install), so you can also install the latest version with: |
17 | 29 |
|
18 | 30 | ```bash |
19 | | - go get -u -v github.com/bep/s3deploy |
| 31 | + go install github.com/bep/s3deploy/v2@latest |
20 | 32 | ``` |
21 | 33 |
|
22 | 34 | To install on MacOS using Homebrew: |
23 | 35 |
|
24 | 36 | ```bash |
25 | 37 | brew install bep/tap/s3deploy |
26 | 38 | ``` |
| 39 | + |
| 40 | +**Note** The brew tap above currently stops at v2.8.1; see [this issue](https://github.com/bep/s3deploy/issues/312) for more info. |
27 | 41 |
|
28 | 42 | Note that `s3deploy` is a perfect tool to use with a continuous integration tool such as [CircleCI](https://circleci.com/). See [this](https://mostlygeek.com/posts/hugo-circle-s3-hosting/) for a tutorial that uses s3deploy with CircleCI. |
29 | 43 |
|
30 | | -## Use |
| 44 | +## Configuration |
31 | 45 |
|
32 | | -```bash |
33 | | -Usage of s3deploy: |
34 | | - -V print version and exit |
35 | | - -bucket string |
36 | | - destination bucket name on AWS |
37 | | - -config string |
38 | | - optional config file (default ".s3deploy.yml") |
39 | | - -distribution-id string |
40 | | - optional CDN distribution ID for cache invalidation |
41 | | - -force |
42 | | - upload even if the etags match |
43 | | - -h help |
44 | | - -key string |
45 | | - access key ID for AWS |
46 | | - -max-delete int |
47 | | - maximum number of files to delete per deploy (default 256) |
48 | | - -public-access |
49 | | - set public ACL on uploaded objects, defaults to private if not set. |
50 | | - -path string |
51 | | - optional bucket sub path |
52 | | - -quiet |
53 | | - enable silent mode |
54 | | - -region string |
55 | | - name of AWS region |
56 | | - -secret string |
57 | | - secret access key for AWS |
58 | | - -source string |
59 | | - path of files to upload (default ".") |
60 | | - -try |
61 | | - trial run, no remote updates |
62 | | - -v enable verbose logging |
63 | | - -workers int |
64 | | - number of workers to upload files (default -1) |
| 46 | +### Flags |
| 47 | + |
| 48 | +The list of flags from running `s3deploy -h`: |
| 49 | + |
| 50 | +``` |
| 51 | +-V print version and exit |
| 52 | +-acl string |
| 53 | + provide an ACL for uploaded objects. to make objects public, set to 'public-read'. all possible values are listed here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl (default "private") |
| 54 | +-bucket string |
| 55 | + destination bucket name on AWS |
| 56 | +-config string |
| 57 | + optional config file (default ".s3deploy.yml") |
| 58 | +-distribution-id value |
| 59 | + optional CDN distribution ID for cache invalidation, repeat flag for multiple distributions |
| 60 | +-endpoint-url url |
| 61 | + optional AWS endpoint URL override |
| 62 | +-force |
| 63 | + upload even if the etags match |
| 64 | +-h help |
| 65 | +-ignore string |
| 66 | + regexp pattern for ignoring files |
| 67 | +-key string |
| 68 | + access key ID for AWS |
| 69 | +-max-delete int |
| 70 | + maximum number of files to delete per deploy (default 256) |
| 71 | +-path string |
| 72 | + optional bucket sub path |
| 73 | +-public-access |
| 74 | + DEPRECATED: please set -acl='public-read' |
| 75 | +-quiet |
| 76 | + enable silent mode |
| 77 | +-region string |
| 78 | + name of AWS region |
| 79 | +-secret string |
| 80 | + secret access key for AWS |
| 81 | +-source string |
| 82 | + path of files to upload (default ".") |
| 83 | +-try |
| 84 | + trial run, no remote updates |
| 85 | +-v enable verbose logging |
| 86 | +-workers int |
| 87 | + number of workers to upload files (default -1) |
65 | 88 | ``` |
66 | 89 |
|
67 | | -### Notes |
| 90 | +The flags can be set in one of (in priority order): |
68 | 91 |
|
69 | | -- The `key` and `secret` command flags can also be set with environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. |
70 | | -- The `region` flag is the AWS API name for the region where your bucket resides. See the table below or the [AWS Regions](https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region) documentation file for an up-to-date version. |
| 92 | +1. As a flag, e.g. `s3deploy -path public/` |
| 93 | +1. As an OS environment variable prefixed with `S3DEPLOY_`, e.g. `S3DEPLOY_PATH="public/"`. |
| 94 | +1. As a key/value in `.s3deploy.yml`, e.g. `path: "public/"` |
| 95 | +1. For `key` and `secret` resolution, the OS environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` (and `AWS_SESSION_TOKEN`) will also be checked. This way you don't need to do any special to make it work with [AWS Vault](https://github.com/99designs/aws-vault) and similar tools. |
| 96 | + |
71 | 97 |
|
72 | | -Bucket region | API value | Bucket region | API value |
73 | | -------------- | --------- | ------------- | ---------- |
74 | | -Canada (Central) | `ca-central-1` | Asia Pacific (Mumbai) | `ap-south-1` |
75 | | -US East (Ohio) | `us-east-2` | Asia Pacific (Seoul) | `ap-northeast-2` |
76 | | -US East (N. Virginia) | `us-east-1` | Asia Pacific (Singapore) | `ap-southeast-1` |
77 | | -US West (N. California) | `us-west-1` | Asia Pacific (Sydney) | `ap-southeast-2` |
78 | | -US West (Oregon) | `us-west-2` | Asia Pacific (Tokyo) | `ap-northeast-1` |
79 | | -EU (Frankfurt) | `eu-central-1` | China (Beijing) | `cn-north-1` |
80 | | -EU (Ireland) | `eu-west-1` | China (Ningxia) | `cn-northwest-1` |
81 | | -EU (London) | `eu-west-2` |
82 | | -EU (Paris) | `eu-west-3` |
83 | | -South America (São Paulo) | `sa-east-1` |
| 98 | +Environment variable expressions in `.s3deploy.yml` on the form `${VAR}` will be expanded before it's parsed: |
84 | 99 |
|
85 | | -## Global AWS Configuration |
| 100 | +```yaml |
| 101 | +path: "${MYVARS_PATH}" |
| 102 | +max-delete: "${MYVARS_MAX_DELETE@U}" |
| 103 | +``` |
86 | 104 |
|
87 | | -See https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#hdr-Sessions_from_Shared_Config |
| 105 | +Note the special `@U` (_Unquoute_) syntax for the int field. |
88 | 106 |
|
89 | | -The `AWS SDK` will fall back to credentials from `~/.aws/credentials`. |
| 107 | +### Routes |
| 108 | + |
| 109 | +The `.s3deploy.yml` configuration file can also contain one or more routes. A route matches files given a regexp. Each route can apply: |
90 | 110 |
|
91 | | -If you set the `AWS_SDK_LOAD_CONFIG` enviroment variable, it will also load shared config from `~/.aws/config` where you can set the global `region` to use if not provided etc. |
| 111 | +`header` |
| 112 | +: Header values, the most notable is probably `Cache-Control`. Note that the list of [system-defined metadata](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html#object-metadata) that S3 currently supports and returns as HTTP headers when hosting a static site is very short. If you have more advanced requirements (e.g. security headers), see [this comment](https://github.com/bep/s3deploy/issues/57#issuecomment-991782098). |
92 | 113 |
|
93 | | -## Advanced Configuration |
| 114 | +`gzip` |
| 115 | +: Set to true to gzip the content when stored in S3. This will also set the correct `Content-Encoding` when fetching the object from S3. |
94 | 116 |
|
95 | | -Add a `.s3deploy.yml` configuration file in the root of your site. Example configuration: |
| 117 | +Example: |
96 | 118 |
|
97 | 119 | ```yaml |
98 | 120 | routes: |
99 | 121 | - route: "^.+\\.(js|css|svg|ttf)$" |
100 | | - # cache static assets for 20 years |
| 122 | + # cache static assets for 1 year. |
101 | 123 | headers: |
102 | | - Cache-Control: "max-age=630720000, no-transform, public" |
| 124 | + Cache-Control: "max-age=31536000, no-transform, public" |
103 | 125 | gzip: true |
104 | 126 | - route: "^.+\\.(png|jpg)$" |
105 | 127 | headers: |
106 | | - Cache-Control: "max-age=630720000, no-transform, public" |
| 128 | + Cache-Control: "max-age=31536000, no-transform, public" |
107 | 129 | gzip: false |
108 | 130 | - route: "^.+\\.(html|xml|json)$" |
109 | 131 | gzip: true |
110 | 132 | ``` |
111 | 133 |
|
112 | 134 |
|
| 135 | + |
| 136 | + |
| 137 | +## Global AWS Configuration |
| 138 | + |
| 139 | +See https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#hdr-Sessions_from_Shared_Config |
| 140 | + |
| 141 | +The `AWS SDK` will fall back to credentials from `~/.aws/credentials`. |
| 142 | + |
| 143 | +If you set the `AWS_SDK_LOAD_CONFIG` environment variable, it will also load shared config from `~/.aws/config` where you can set the global `region` to use if not provided etc. |
| 144 | + |
113 | 145 | ## Example IAM Policy |
114 | 146 |
|
115 | 147 | ```json |
@@ -182,11 +214,15 @@ Note that CloudFront allows [1,000 paths per month at no charge](https://aws.ama |
182 | 214 |
|
183 | 215 | ## Background Information |
184 | 216 |
|
185 | | -If you're looking at `s3deploy` then you've probably already seen the [`aws s3 sync` command](http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) - this command has a sync-strategy that is not optimised for static sites, it compares the **timestamp** and **size** of your files to decide whether to upload the file. |
| 217 | +If you're looking at `s3deploy` then you've probably already seen the [`aws s3 sync` command](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) - this command has a sync-strategy that is not optimised for static sites, it compares the **timestamp** and **size** of your files to decide whether to upload the file. |
186 | 218 |
|
187 | 219 | Because static-site generators can recreate **every** file (even if identical) the timestamp is updated and thus `aws s3 sync` will needlessly upload every single file. `s3deploy` on the other hand checks the etag hash to check for actual changes, and uses that instead. |
188 | 220 |
|
189 | 221 | ## Alternatives |
190 | 222 |
|
191 | 223 | * [go3up](https://github.com/alexaandru/go3up) by Alexandru Ungur |
192 | 224 | * [s3up](https://github.com/nathany/s3up) by Nathan Youngman (the starting-point of this project) |
| 225 | + |
| 226 | +## Stargazers over time |
| 227 | + |
| 228 | + [](https://starchart.cc/bep/s3deploy) |
0 commit comments