You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libraries/rush-lib/src/schemas/build-cache.schema.json
+71-1
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,56 @@
85
85
"description": "If set to true, allow writing to the cache. Defaults to false."
86
86
}
87
87
}
88
+
},
89
+
"httpConfiguration": {
90
+
"type": "object",
91
+
"additionalProperties": false,
92
+
"properties": {
93
+
"url": {
94
+
"type": "string",
95
+
"description": "(Required) The URL of the server that stores the caches (e.g. \"https://build-caches.example.com\").",
96
+
"format": "uri"
97
+
},
98
+
"uploadMethod": {
99
+
"type": "string",
100
+
"description": "(Optional) The HTTP method to use when writing to the cache (defaults to PUT).",
101
+
"enum": ["PUT", "POST", "PATCH"],
102
+
"default": "PUT"
103
+
},
104
+
"headers": {
105
+
"type": "object",
106
+
"description": "(Optional) HTTP headers to pass to the cache server",
107
+
"properties": {},
108
+
"additionalProperties": {
109
+
"type": "string"
110
+
}
111
+
},
112
+
"tokenHandler": {
113
+
"type": "object",
114
+
"description": "(Optional) Shell command that prints the authorization token needed to communicate with the HTTPS server and exits with code 0. This command will be executed from the root of the monorepo.",
115
+
"properties": {
116
+
"exec": {
117
+
"type": "string",
118
+
"description": "(Required) The command or script to execute."
119
+
},
120
+
"args": {
121
+
"type": "array",
122
+
"description": "(Optional) Arguments to pass to the command or script.",
123
+
"items": {
124
+
"type": "string"
125
+
}
126
+
}
127
+
}
128
+
},
129
+
"cacheKeyPrefix": {
130
+
"type": "string",
131
+
"description": "(Optional) prefix for cache keys."
132
+
},
133
+
"isCacheWriteAllowed": {
134
+
"type": "boolean",
135
+
"description": "(Optional) If set to true, allow writing to the cache. Defaults to false."
Copy file name to clipboardExpand all lines: rush-plugins/rush-http-build-cache-plugin/README.md
+33-11
Original file line number
Diff line number
Diff line change
@@ -16,27 +16,49 @@ To use the HTTP build cache plugin, enable it in `common/config/rush/build-cache
16
16
}
17
17
```
18
18
19
-
Once enabled, configure the HTTP build cache in config file `common/config/rush-plugins/rush-http-build-cache-plugin.json`:
19
+
Then customize the `httpConfiguration` block. For typical use cases, where you'll use a remote HTTP URL with authentication, you'll need to provide at least the `url` and `tokenHandler` options:
-`tokenHandler`: A script that can print the Authorization header expected by the server. The value printed to `stdout` by this command should be an exact header, for example, `Bearer ab98d8c878d937290d979a9097c90dfffff` or `Basic 098abc7dff==`.
31
-
-`isCacheWriteAllowed`: A flag that determines if the plugin should write to the cache.
34
+
(For more detail on the above properties and additional optional properties, consult the default `build-cache.json` file.)
35
+
36
+
## Authorization Details
37
+
38
+
The HTTP build cache plugin offloads authorization to an external executable script that you define. A typical use case would be to create a simple script, for example `common/scripts/cache-auth.js`, that prints an Authorization header value when executed.
39
+
40
+
For example:
41
+
42
+
```console
43
+
node common/scripts/cache-auth.js
44
+
# => Bearer 0284357923592790DDb979dBcd2zz
45
+
```
46
+
47
+
How the script generates authorization values is up to you, and depends on the configuration of your remote cache server.
48
+
49
+
Possible implementations:
50
+
51
+
- The script could read simple environment variables (`CACHE_USER` and `CACHE_TOKEN`) defined by the developer
52
+
- It could reuse existing credentials your developers have, like NPM tokens, GitHub credentials, or jFrog API tokens
53
+
- It could make an HTTP call to another server accessible by your developers that returns temporary credentials
32
54
33
55
## HTTP Cache Server Requirements
34
56
35
57
The HTTP build cache plugin can use almost any HTTP/HTTPS backend for remote caching, as long as it honors the following rules:
36
58
37
59
- Uses `Authorization: Bearer xxx` or `Authorization: Basic xxx` headers for authentication.
38
60
- Accepts GET requests for cache reads.
39
-
- Accepts PUT requests for cache writes (with a raw request body -- no `form/multipart`).
61
+
- Accepts PUT requests for cache writes (with a raw request body -- no `form/multipart` MIME types).
40
62
- Cache hits return HTTP 200 with the file in the response body.
@@ -56,13 +78,13 @@ First, start up and configure your build cache node locally:
56
78
- Enter the temporary username/password credentials printed in the startup banner
57
79
- Click Build Cache > Settings > Cache Access Control and grant "Read & write" access to Anonymous
58
80
59
-
Second, create your `rush-http-build-cache-plugin.json` file as described in the Configuration section:
81
+
Second, configure your `build-cache.json` file as described in the Configuration section:
60
82
61
-
- Note that your `url`should end with `/cache/`, for example, `http://localhost:5071/cache/`
83
+
- Note that your `url`must end with `/cache/`, for example, `http://localhost:5071/cache/`.
62
84
- To test reading and writing, set `isCacheWriteAllowed: true`.
63
85
- Configure `tokenHandler` to point to a script that prints a Basic or Bearer Authorization value (this can be a dummy string if you granted Read and Write to Anonymous in your build cache node configuration).
64
86
65
-
Note that the Gradle Build Cache Server has a stricter format for its cache keys (they should be a simple hexadecimal hash with no non-alphanumeric characters). Configure this setting in your `common/config/rush/build-cache.json` file:
87
+
Note that the Gradle Build Cache Server has a stricter format for its cache keys (they should be a simple hexadecimal hash with no non-alphanumeric characters). Configure this setting in your `build-cache.json` file:
0 commit comments