@dotcom-tool-kit/upload-assets-to-s3 2.0.11 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -0
- package/lib/tasks/upload-assets-to-s3.js +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @dotcom-tool-kit/upload-assets-to-s3
|
|
2
|
+
|
|
3
|
+
Upload files to a configured AWS S3 bucket.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install `@dotcom-tool-kit/upload-assets-to-s3` as a `devDependency` in your app:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @dotcom-tool-kit/upload-assets-to-s3
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add the plugin to your [Tool Kit configuration](https://github.com/financial-times/dotcom-tool-kit/blob/main/readme.md#configuration):
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
plugins:
|
|
17
|
+
- '@dotcom-tool-kit/upload-assets-to-s3'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
| Key | Description | Default value |
|
|
23
|
+
|-|-|-|
|
|
24
|
+
| `accessKeyIdEnvVar` | variable name of the project's aws access key id | no default value - for backwards compatability the plugin falls back to the default value for `accessKeyId` |
|
|
25
|
+
| `secretAccessKeyEnvVar` | variable name of the project's aws secret access key | no default value - for backwards compatability the plugin falls back to the default value for `secretAccessKey` |
|
|
26
|
+
| `accessKeyId` | **DEPRECATED** variable name of the project's aws access key id | 'aws_access_hashed_assets' |
|
|
27
|
+
| `secretAccessKey` | **DEPRECATED** variable name of the project's aws secret access key | 'aws_secret_hashed_assets' |
|
|
28
|
+
| `directory` | the folder in the project whose contents will be uploaded to S3 | 'public' |
|
|
29
|
+
| `reviewBucket` | the development or test S3 bucket | ['ft-next-hashed-assets-preview'] |
|
|
30
|
+
| `prodBucket` | production S3 bucket/s; an array of strings. The same files will be uploaded to each | ['ft-next-hashed-assets-prod', 'ft-next-hashed-assets-prod-us'] |
|
|
31
|
+
| `destination` | the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket | 'hashed-assets/page-kit' |
|
|
32
|
+
| `extensions` | file extensions to be uploaded to S3 | 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json' |
|
|
33
|
+
| `cacheControl` | header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin | 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600' |
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
```yml
|
|
37
|
+
'@dotcom-tool-kit/upload-assets-to-s3':
|
|
38
|
+
'@dotcom-tool-kit/upload-assets-to-s3':
|
|
39
|
+
accessKeyId: AWS_ACCESS
|
|
40
|
+
secretAccessKey: AWS_KEY
|
|
41
|
+
prodBucket: ['ft-next-service-registry-prod', 'ft-next-service-registry-prod-us']
|
|
42
|
+
reviewBucket: ['ft-next-service-registry-dev']
|
|
43
|
+
destination: ''
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Testing uploads using the review bucket
|
|
47
|
+
|
|
48
|
+
You can test uploads to S3 locally on your review bucket to check that you are happy with the configuration. To do this set your `NODE_ENV` to `branch`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
$ export NODE_ENV=branch
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
If the AWS key names for accessing the review bucket are different to the prod bucket then update those in the `.toolkitrc.yml`.
|
|
55
|
+
|
|
56
|
+
The `UploadAssetsToS3` task can run on any hook so you can configure it to run on a local hook to test deployment from the command line. For example, it could be added to your `build:local` hook as follows:
|
|
57
|
+
|
|
58
|
+
```yml
|
|
59
|
+
plugins:
|
|
60
|
+
- '@dotcom-tool-kit/webpack'
|
|
61
|
+
- '@dotcom-tool-kit/upload-assets-to-s3'
|
|
62
|
+
hooks:
|
|
63
|
+
'build:local':
|
|
64
|
+
- WebpackDevelopment
|
|
65
|
+
- UploadAssetsToS3
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then running `npm run build` will run the `UploadAssetsToS3` task on your review bucket.
|
|
69
|
+
|
|
70
|
+
## Tasks
|
|
71
|
+
|
|
72
|
+
| Name | Description | Preconfigured Hook|
|
|
73
|
+
|-|-|-|
|
|
74
|
+
| `UploadAssetsTos3` | Uploads provided files to a given S3 bucket | `release:remote` |
|
|
@@ -66,7 +66,7 @@ class UploadAssetsToS3 extends types_1.Task {
|
|
|
66
66
|
// Wrap extensions in braces if there are multiple
|
|
67
67
|
const extensions = options.extensions.includes(',') ? `{${options.extensions}}` : options.extensions;
|
|
68
68
|
const globFile = `**/*${extensions}`;
|
|
69
|
-
const files = glob_1.glob.sync(globFile, { cwd: options.directory });
|
|
69
|
+
const files = glob_1.glob.sync(globFile, { cwd: options.directory, nodir: true });
|
|
70
70
|
const s3 = new aws_sdk_1.default.S3({
|
|
71
71
|
// fallback to default value for accessKeyId if neither accessKeyIdEnvVar or accessKeyId have been provided as options
|
|
72
72
|
accessKeyId:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcom-tool-kit/upload-assets-to-s3",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@dotcom-tool-kit/error": "^2.0.1",
|
|
14
|
-
"@dotcom-tool-kit/logger": "^2.
|
|
15
|
-
"@dotcom-tool-kit/types": "^2.7.
|
|
14
|
+
"@dotcom-tool-kit/logger": "^2.2.0",
|
|
15
|
+
"@dotcom-tool-kit/types": "^2.7.1",
|
|
16
16
|
"aws-sdk": "^2.901.0",
|
|
17
17
|
"glob": "^7.1.6",
|
|
18
18
|
"mime": "^2.5.2",
|