react-cheminfo 0.26.0 → 0.27.0
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/bin/check-deploy.mjs +14 -4
- package/lib/deploy/core/checkDeploy.d.ts +3 -1
- package/lib/deploy/core/checkDeploy.d.ts.map +1 -1
- package/lib/deploy/core/checkDeploy.js +7 -1
- package/lib/deploy/core/checkDeploy.js.map +1 -1
- package/lib/deploy/core/index.d.ts +1 -0
- package/lib/deploy/core/index.d.ts.map +1 -1
- package/lib/deploy/core/index.js +1 -0
- package/lib/deploy/core/index.js.map +1 -1
- package/lib/deploy/core/pageCache.d.ts +24 -0
- package/lib/deploy/core/pageCache.d.ts.map +1 -0
- package/lib/deploy/core/pageCache.js +91 -0
- package/lib/deploy/core/pageCache.js.map +1 -0
- package/lib/deploy/core/types.d.ts +1 -1
- package/lib/deploy/core/types.d.ts.map +1 -1
- package/lib/deploy/core/types.js.map +1 -1
- package/package.json +1 -1
- package/src/deploy/core/checkDeploy.ts +7 -1
- package/src/deploy/core/index.ts +1 -0
- package/src/deploy/core/pageCache.ts +120 -0
- package/src/deploy/core/types.ts +2 -1
package/bin/check-deploy.mjs
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/*
|
|
3
3
|
* Report every way a repository would break, or silently mis-deploy, under the
|
|
4
4
|
* server's global deploy script: a compose file it would not find, an image with
|
|
5
|
-
* no selectable tag,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* no selectable tag, a page the browser keeps across a deploy and then cannot
|
|
6
|
+
* run, an `IMAGE_NAME` naming a package this repository never publishes, an
|
|
7
|
+
* `env_file` that fails on a checkout with no `.env` yet, a service with no
|
|
8
|
+
* health probe to read, an `.env.example` that hides a mode.
|
|
8
9
|
*
|
|
9
10
|
* Wire it as an npm script, next to check-tokens:
|
|
10
11
|
* "check-deploy": "cheminfo-check-deploy"
|
|
@@ -25,6 +26,8 @@ import process from 'node:process';
|
|
|
25
26
|
|
|
26
27
|
import {
|
|
27
28
|
DEPLOY_COMPOSE_FILES,
|
|
29
|
+
NGINX_CONFIG,
|
|
30
|
+
PAGE_CACHE_CONFIG,
|
|
28
31
|
findDeployProblems,
|
|
29
32
|
} from '../lib/deploy/core/index.js';
|
|
30
33
|
|
|
@@ -67,7 +70,14 @@ if (imageName === undefined) {
|
|
|
67
70
|
// Every mode is read, present or not: a missing one is itself a problem.
|
|
68
71
|
const expected = composeFiles ?? DEPLOY_COMPOSE_FILES;
|
|
69
72
|
const files = [];
|
|
70
|
-
for (const path of [
|
|
73
|
+
for (const path of [
|
|
74
|
+
...expected,
|
|
75
|
+
'.env.example',
|
|
76
|
+
'.gitignore',
|
|
77
|
+
'Dockerfile',
|
|
78
|
+
PAGE_CACHE_CONFIG,
|
|
79
|
+
NGINX_CONFIG,
|
|
80
|
+
]) {
|
|
71
81
|
const text = read(path);
|
|
72
82
|
if (text !== undefined) files.push({ path, text });
|
|
73
83
|
}
|
|
@@ -8,7 +8,9 @@ import type { CheckDeployOptions, DeployFile, DeployProblem } from './types.ts';
|
|
|
8
8
|
* reports it healthy. So a repository has to hand it a selectable tag on every
|
|
9
9
|
* image we build, an `IMAGE_NAME` that names the package our own workflow
|
|
10
10
|
* publishes, a compose file that parses on a checkout with no `.env` yet, and a
|
|
11
|
-
* health probe to read.
|
|
11
|
+
* health probe to read. It also has to hand the browser a page the browser will
|
|
12
|
+
* not keep, or the next deploy leaves returning visitors on a blank one. Each
|
|
13
|
+
* of those is invisible until a deploy, which is the
|
|
12
14
|
* worst moment to discover it — an `env_file` without `required: false` fails
|
|
13
15
|
* before a container starts, and an `IMAGE_NAME` off by a suffix pulls a
|
|
14
16
|
* package that was never published.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkDeploy.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/checkDeploy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkDeploy.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/checkDeploy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,GAAE,kBAAuB,GAC/B,aAAa,EAAE,CA6DjB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readComposeFile } from "./composeFile.js";
|
|
2
2
|
import { readEnvExample } from "./envExample.js";
|
|
3
|
+
import { readPageCache } from "./pageCache.js";
|
|
3
4
|
import { DEPLOY_COMPOSE_FILES } from "./types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Every way a repository would break, or silently mis-deploy, under the
|
|
@@ -10,7 +11,9 @@ import { DEPLOY_COMPOSE_FILES } from "./types.js";
|
|
|
10
11
|
* reports it healthy. So a repository has to hand it a selectable tag on every
|
|
11
12
|
* image we build, an `IMAGE_NAME` that names the package our own workflow
|
|
12
13
|
* publishes, a compose file that parses on a checkout with no `.env` yet, and a
|
|
13
|
-
* health probe to read.
|
|
14
|
+
* health probe to read. It also has to hand the browser a page the browser will
|
|
15
|
+
* not keep, or the next deploy leaves returning visitors on a blank one. Each
|
|
16
|
+
* of those is invisible until a deploy, which is the
|
|
14
17
|
* worst moment to discover it — an `env_file` without `required: false` fails
|
|
15
18
|
* before a container starts, and an `IMAGE_NAME` off by a suffix pulls a
|
|
16
19
|
* package that was never published.
|
|
@@ -59,6 +62,9 @@ export function findDeployProblems(files, options = {}) {
|
|
|
59
62
|
else {
|
|
60
63
|
readEnvExample(envExample, expected, problems);
|
|
61
64
|
}
|
|
65
|
+
const dockerfile = byPath.get('Dockerfile');
|
|
66
|
+
if (dockerfile !== undefined)
|
|
67
|
+
readPageCache(dockerfile, byPath, problems);
|
|
62
68
|
const gitignore = byPath.get('.gitignore');
|
|
63
69
|
if (gitignore === undefined || !/^\s*\/?\.deploy\/?\s*$/m.test(gitignore)) {
|
|
64
70
|
problems.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkDeploy.js","sourceRoot":"","sources":["../../../src/deploy/core/checkDeploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"checkDeploy.js","sourceRoot":"","sources":["../../../src/deploy/core/checkDeploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA4B,EAC5B,UAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,IAAI,oBAAoB,CAAC;IAC9D,MAAM,KAAK,GAAG;QACZ,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,EAAE;QAC1C,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,IAAI;QACtD,iBAAiB,EAAE,CACjB,OAAO,CAAC,iBAAiB,IAAI,gBAAgB,CAC9C,CAAC,WAAW,EAAE;QACf,SAAS,EAAE,CAAC,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE;KACzD,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IA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IAAI,CAAC;YACZ,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EACL,8EAA8E;YAChF,IAAI,EAAE,kCAAkC;SACzC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { findDeployProblems } from './checkDeploy.ts';
|
|
2
2
|
export type { CheckDeployOptions, DeployFile, DeployProblem, DeployProblemKind, } from './types.ts';
|
|
3
|
+
export { NGINX_CONFIG, PAGE_CACHE_CONFIG } from './pageCache.ts';
|
|
3
4
|
export { DEPLOY_COMPOSE_FILES } from './types.ts';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/lib/deploy/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deploy/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deploy/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DeployProblem } from './types.ts';
|
|
2
|
+
/** The page cache policy of a static-web-server site, at the repository root. */
|
|
3
|
+
export declare const PAGE_CACHE_CONFIG = "sws.toml";
|
|
4
|
+
/** The nginx configuration of a site served by nginx. */
|
|
5
|
+
export declare const NGINX_CONFIG = "nginx.conf";
|
|
6
|
+
/**
|
|
7
|
+
* Report a server that lets a browser keep the page itself.
|
|
8
|
+
*
|
|
9
|
+
* A page names the hashed bundles of the build that wrote it, so a browser
|
|
10
|
+
* still holding a copy from an earlier deploy asks the new image for files it
|
|
11
|
+
* does not have; the request falls through to the page, the browser refuses to
|
|
12
|
+
* run HTML as a module, and the site comes up blank until the copy expires.
|
|
13
|
+
* Nothing on the server can see it and no test can either, because a test
|
|
14
|
+
* always loads a page and its bundles from the same build. So it is read off
|
|
15
|
+
* the server's configuration instead: static-web-server hands pages out with
|
|
16
|
+
* `max-age=86400` of its own, and nginx says nothing and lets the browser
|
|
17
|
+
* guess, so both have to be told. The bundles, named by their content, are the
|
|
18
|
+
* one thing worth keeping.
|
|
19
|
+
* @param dockerfile - The Dockerfile, which says what serves the build.
|
|
20
|
+
* @param byPath - Every file that was read, by repository path.
|
|
21
|
+
* @param problems - Where each problem found is appended.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readPageCache(dockerfile: string, byPath: ReadonlyMap<string, string>, problems: DeployProblem[]): void;
|
|
24
|
+
//# sourceMappingURL=pageCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageCache.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/pageCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,yDAAyD;AACzD,eAAO,MAAM,YAAY,eAAe,CAAC;AAKzC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,QAAQ,EAAE,aAAa,EAAE,GACxB,IAAI,CAMN"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** The page cache policy of a static-web-server site, at the repository root. */
|
|
2
|
+
export const PAGE_CACHE_CONFIG = 'sws.toml';
|
|
3
|
+
/** The nginx configuration of a site served by nginx. */
|
|
4
|
+
export const NGINX_CONFIG = 'nginx.conf';
|
|
5
|
+
const NO_CACHE = /cache-control[\s:=]+["']?[^"'\n]*(?:no-cache|no-store|max-age=0)/i;
|
|
6
|
+
/**
|
|
7
|
+
* Report a server that lets a browser keep the page itself.
|
|
8
|
+
*
|
|
9
|
+
* A page names the hashed bundles of the build that wrote it, so a browser
|
|
10
|
+
* still holding a copy from an earlier deploy asks the new image for files it
|
|
11
|
+
* does not have; the request falls through to the page, the browser refuses to
|
|
12
|
+
* run HTML as a module, and the site comes up blank until the copy expires.
|
|
13
|
+
* Nothing on the server can see it and no test can either, because a test
|
|
14
|
+
* always loads a page and its bundles from the same build. So it is read off
|
|
15
|
+
* the server's configuration instead: static-web-server hands pages out with
|
|
16
|
+
* `max-age=86400` of its own, and nginx says nothing and lets the browser
|
|
17
|
+
* guess, so both have to be told. The bundles, named by their content, are the
|
|
18
|
+
* one thing worth keeping.
|
|
19
|
+
* @param dockerfile - The Dockerfile, which says what serves the build.
|
|
20
|
+
* @param byPath - Every file that was read, by repository path.
|
|
21
|
+
* @param problems - Where each problem found is appended.
|
|
22
|
+
*/
|
|
23
|
+
export function readPageCache(dockerfile, byPath, problems) {
|
|
24
|
+
if (dockerfile.includes('static-web-server')) {
|
|
25
|
+
readStaticWebServer(dockerfile, byPath, problems);
|
|
26
|
+
}
|
|
27
|
+
else if (/^FROM\s+\S*nginx/im.test(dockerfile)) {
|
|
28
|
+
readNginx(byPath, problems);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function readStaticWebServer(dockerfile, byPath, problems) {
|
|
32
|
+
const named = /^\s*ENV\s+SERVER_CONFIG_FILE=(?<path>\S+)/m.exec(dockerfile);
|
|
33
|
+
const destination = named?.groups?.path;
|
|
34
|
+
if (destination === undefined) {
|
|
35
|
+
problems.push({
|
|
36
|
+
file: 'Dockerfile',
|
|
37
|
+
line: lineOf(dockerfile, /static-web-server/),
|
|
38
|
+
kind: 'cacheable-page',
|
|
39
|
+
message: 'static-web-server keeps every page in the browser for a day, so each deploy blanks the site for anyone who came by before it',
|
|
40
|
+
hint: `COPY ${PAGE_CACHE_CONFIG} /etc/sws.toml and set SERVER_CONFIG_FILE to it`,
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const copied = new RegExp(String.raw `^\s*COPY\s+(?:--\S+\s+)*${escapeRegExp(PAGE_CACHE_CONFIG)}\s+${escapeRegExp(destination)}\s*$`, 'm');
|
|
45
|
+
if (!copied.test(dockerfile)) {
|
|
46
|
+
problems.push({
|
|
47
|
+
file: 'Dockerfile',
|
|
48
|
+
line: lineOf(dockerfile, /^\s*ENV\s+SERVER_CONFIG_FILE=/m),
|
|
49
|
+
kind: 'cacheable-page',
|
|
50
|
+
message: `SERVER_CONFIG_FILE names ${destination}, which nothing puts there`,
|
|
51
|
+
hint: `COPY ${PAGE_CACHE_CONFIG} ${destination}`,
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
readNoCacheRule(PAGE_CACHE_CONFIG, byPath, problems);
|
|
56
|
+
}
|
|
57
|
+
function readNginx(byPath, problems) {
|
|
58
|
+
readNoCacheRule(NGINX_CONFIG, byPath, problems);
|
|
59
|
+
}
|
|
60
|
+
function readNoCacheRule(path, byPath, problems) {
|
|
61
|
+
const text = byPath.get(path);
|
|
62
|
+
if (text === undefined) {
|
|
63
|
+
problems.push({
|
|
64
|
+
file: path,
|
|
65
|
+
line: 0,
|
|
66
|
+
kind: 'cacheable-page',
|
|
67
|
+
message: 'the server has no page cache policy to read',
|
|
68
|
+
hint: `commit ${path} at the repository root, telling the browser to check the page on every visit`,
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!NO_CACHE.test(text)) {
|
|
73
|
+
problems.push({
|
|
74
|
+
file: path,
|
|
75
|
+
line: 0,
|
|
76
|
+
kind: 'cacheable-page',
|
|
77
|
+
message: 'no rule stops a browser from keeping the page between deploys',
|
|
78
|
+
hint: 'give the page Cache-Control: no-cache, and keep the long life for the hashed bundles alone',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function lineOf(text, pattern) {
|
|
83
|
+
const match = pattern.exec(text);
|
|
84
|
+
if (match === null)
|
|
85
|
+
return 0;
|
|
86
|
+
return text.slice(0, match.index).split('\n').length;
|
|
87
|
+
}
|
|
88
|
+
function escapeRegExp(value) {
|
|
89
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw `\$&`);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=pageCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageCache.js","sourceRoot":"","sources":["../../../src/deploy/core/pageCache.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAE5C,yDAAyD;AACzD,M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,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACvD,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,UAAU,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,CAAA,KAAK,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** What a repository got wrong against the deployment contract. */
|
|
2
|
-
export type DeployProblemKind = 'missing-compose' | 'invalid-compose' | 'unpinned-image' | 'missing-build' | 'wrong-image-name' | 'required-env-file' | 'floating-sidecar' | 'missing-healthcheck' | 'missing-env-example' | 'missing-deploy-ignore';
|
|
2
|
+
export type DeployProblemKind = 'missing-compose' | 'invalid-compose' | 'unpinned-image' | 'missing-build' | 'wrong-image-name' | 'required-env-file' | 'floating-sidecar' | 'missing-healthcheck' | 'missing-env-example' | 'missing-deploy-ignore' | 'cacheable-page';
|
|
3
3
|
/** One way a repository would fail, or silently mis-deploy, on the server. */
|
|
4
4
|
export interface DeployProblem {
|
|
5
5
|
/** The file it was found in, named as the caller named it. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/types.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,qBAAqB,GACrB,qBAAqB,GACrB,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/deploy/core/types.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,GACf,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,qBAAqB,GACrB,qBAAqB,GACrB,uBAAuB,GACvB,gBAAgB,CAAC;AAErB,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,IAAI,EAAE,iBAAiB,CAAC;IACxB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sEAAsE;AACtE,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,4CAA4C;AAC5C,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAIjD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/deploy/core/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/deploy/core/types.ts"],"names":[],"mappings":"AA+EA;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsB;IACrD,cAAc;IACd,sBAAsB;IACtB,0BAA0B;CAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cheminfo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
|
|
6
6
|
"author": "Luc Patiny",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readComposeFile } from './composeFile.ts';
|
|
2
2
|
import { readEnvExample } from './envExample.ts';
|
|
3
|
+
import { readPageCache } from './pageCache.ts';
|
|
3
4
|
import type { CheckDeployOptions, DeployFile, DeployProblem } from './types.ts';
|
|
4
5
|
import { DEPLOY_COMPOSE_FILES } from './types.ts';
|
|
5
6
|
|
|
@@ -12,7 +13,9 @@ import { DEPLOY_COMPOSE_FILES } from './types.ts';
|
|
|
12
13
|
* reports it healthy. So a repository has to hand it a selectable tag on every
|
|
13
14
|
* image we build, an `IMAGE_NAME` that names the package our own workflow
|
|
14
15
|
* publishes, a compose file that parses on a checkout with no `.env` yet, and a
|
|
15
|
-
* health probe to read.
|
|
16
|
+
* health probe to read. It also has to hand the browser a page the browser will
|
|
17
|
+
* not keep, or the next deploy leaves returning visitors on a blank one. Each
|
|
18
|
+
* of those is invisible until a deploy, which is the
|
|
16
19
|
* worst moment to discover it — an `env_file` without `required: false` fails
|
|
17
20
|
* before a container starts, and an `IMAGE_NAME` off by a suffix pulls a
|
|
18
21
|
* package that was never published.
|
|
@@ -68,6 +71,9 @@ export function findDeployProblems(
|
|
|
68
71
|
readEnvExample(envExample, expected, problems);
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
const dockerfile = byPath.get('Dockerfile');
|
|
75
|
+
if (dockerfile !== undefined) readPageCache(dockerfile, byPath, problems);
|
|
76
|
+
|
|
71
77
|
const gitignore = byPath.get('.gitignore');
|
|
72
78
|
if (gitignore === undefined || !/^\s*\/?\.deploy\/?\s*$/m.test(gitignore)) {
|
|
73
79
|
problems.push({
|
package/src/deploy/core/index.ts
CHANGED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { DeployProblem } from './types.ts';
|
|
2
|
+
|
|
3
|
+
/** The page cache policy of a static-web-server site, at the repository root. */
|
|
4
|
+
export const PAGE_CACHE_CONFIG = 'sws.toml';
|
|
5
|
+
|
|
6
|
+
/** The nginx configuration of a site served by nginx. */
|
|
7
|
+
export const NGINX_CONFIG = 'nginx.conf';
|
|
8
|
+
|
|
9
|
+
const NO_CACHE =
|
|
10
|
+
/cache-control[\s:=]+["']?[^"'\n]*(?:no-cache|no-store|max-age=0)/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Report a server that lets a browser keep the page itself.
|
|
14
|
+
*
|
|
15
|
+
* A page names the hashed bundles of the build that wrote it, so a browser
|
|
16
|
+
* still holding a copy from an earlier deploy asks the new image for files it
|
|
17
|
+
* does not have; the request falls through to the page, the browser refuses to
|
|
18
|
+
* run HTML as a module, and the site comes up blank until the copy expires.
|
|
19
|
+
* Nothing on the server can see it and no test can either, because a test
|
|
20
|
+
* always loads a page and its bundles from the same build. So it is read off
|
|
21
|
+
* the server's configuration instead: static-web-server hands pages out with
|
|
22
|
+
* `max-age=86400` of its own, and nginx says nothing and lets the browser
|
|
23
|
+
* guess, so both have to be told. The bundles, named by their content, are the
|
|
24
|
+
* one thing worth keeping.
|
|
25
|
+
* @param dockerfile - The Dockerfile, which says what serves the build.
|
|
26
|
+
* @param byPath - Every file that was read, by repository path.
|
|
27
|
+
* @param problems - Where each problem found is appended.
|
|
28
|
+
*/
|
|
29
|
+
export function readPageCache(
|
|
30
|
+
dockerfile: string,
|
|
31
|
+
byPath: ReadonlyMap<string, string>,
|
|
32
|
+
problems: DeployProblem[],
|
|
33
|
+
): void {
|
|
34
|
+
if (dockerfile.includes('static-web-server')) {
|
|
35
|
+
readStaticWebServer(dockerfile, byPath, problems);
|
|
36
|
+
} else if (/^FROM\s+\S*nginx/im.test(dockerfile)) {
|
|
37
|
+
readNginx(byPath, problems);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readStaticWebServer(
|
|
42
|
+
dockerfile: string,
|
|
43
|
+
byPath: ReadonlyMap<string, string>,
|
|
44
|
+
problems: DeployProblem[],
|
|
45
|
+
): void {
|
|
46
|
+
const named = /^\s*ENV\s+SERVER_CONFIG_FILE=(?<path>\S+)/m.exec(dockerfile);
|
|
47
|
+
const destination = named?.groups?.path;
|
|
48
|
+
if (destination === undefined) {
|
|
49
|
+
problems.push({
|
|
50
|
+
file: 'Dockerfile',
|
|
51
|
+
line: lineOf(dockerfile, /static-web-server/),
|
|
52
|
+
kind: 'cacheable-page',
|
|
53
|
+
message:
|
|
54
|
+
'static-web-server keeps every page in the browser for a day, so each deploy blanks the site for anyone who came by before it',
|
|
55
|
+
hint: `COPY ${PAGE_CACHE_CONFIG} /etc/sws.toml and set SERVER_CONFIG_FILE to it`,
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const copied = new RegExp(
|
|
61
|
+
String.raw`^\s*COPY\s+(?:--\S+\s+)*${escapeRegExp(PAGE_CACHE_CONFIG)}\s+${escapeRegExp(destination)}\s*$`,
|
|
62
|
+
'm',
|
|
63
|
+
);
|
|
64
|
+
if (!copied.test(dockerfile)) {
|
|
65
|
+
problems.push({
|
|
66
|
+
file: 'Dockerfile',
|
|
67
|
+
line: lineOf(dockerfile, /^\s*ENV\s+SERVER_CONFIG_FILE=/m),
|
|
68
|
+
kind: 'cacheable-page',
|
|
69
|
+
message: `SERVER_CONFIG_FILE names ${destination}, which nothing puts there`,
|
|
70
|
+
hint: `COPY ${PAGE_CACHE_CONFIG} ${destination}`,
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
readNoCacheRule(PAGE_CACHE_CONFIG, byPath, problems);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readNginx(
|
|
79
|
+
byPath: ReadonlyMap<string, string>,
|
|
80
|
+
problems: DeployProblem[],
|
|
81
|
+
): void {
|
|
82
|
+
readNoCacheRule(NGINX_CONFIG, byPath, problems);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function readNoCacheRule(
|
|
86
|
+
path: string,
|
|
87
|
+
byPath: ReadonlyMap<string, string>,
|
|
88
|
+
problems: DeployProblem[],
|
|
89
|
+
): void {
|
|
90
|
+
const text = byPath.get(path);
|
|
91
|
+
if (text === undefined) {
|
|
92
|
+
problems.push({
|
|
93
|
+
file: path,
|
|
94
|
+
line: 0,
|
|
95
|
+
kind: 'cacheable-page',
|
|
96
|
+
message: 'the server has no page cache policy to read',
|
|
97
|
+
hint: `commit ${path} at the repository root, telling the browser to check the page on every visit`,
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!NO_CACHE.test(text)) {
|
|
102
|
+
problems.push({
|
|
103
|
+
file: path,
|
|
104
|
+
line: 0,
|
|
105
|
+
kind: 'cacheable-page',
|
|
106
|
+
message: 'no rule stops a browser from keeping the page between deploys',
|
|
107
|
+
hint: 'give the page Cache-Control: no-cache, and keep the long life for the hashed bundles alone',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function lineOf(text: string, pattern: RegExp): number {
|
|
113
|
+
const match = pattern.exec(text);
|
|
114
|
+
if (match === null) return 0;
|
|
115
|
+
return text.slice(0, match.index).split('\n').length;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function escapeRegExp(value: string): string {
|
|
119
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`);
|
|
120
|
+
}
|
package/src/deploy/core/types.ts
CHANGED
|
@@ -9,7 +9,8 @@ export type DeployProblemKind =
|
|
|
9
9
|
| 'floating-sidecar'
|
|
10
10
|
| 'missing-healthcheck'
|
|
11
11
|
| 'missing-env-example'
|
|
12
|
-
| 'missing-deploy-ignore'
|
|
12
|
+
| 'missing-deploy-ignore'
|
|
13
|
+
| 'cacheable-page';
|
|
13
14
|
|
|
14
15
|
/** One way a repository would fail, or silently mis-deploy, on the server. */
|
|
15
16
|
export interface DeployProblem {
|