[verified] Fix Stage readiness against paginated public blogs contract
Deploy Canina / deploy (push) Successful in 39s
Deploy Canina / deploy (push) Successful in 39s
This commit is contained in:
1 parent
0fa6abc53d
commit
9ae839138c
2 files changed
+113
-2
No files matched your search
@@ -169,14 +169,34 @@ for name in canino_backend_stage canino_frontend_stage; do
|
||||
image=$(timeout --foreground --kill-after=2s 10 docker inspect -f '{{.Image}}' "$name")
|
||||
[[ $(timeout --foreground --kill-after=2s 10 docker image inspect -f '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$image") == "$DEPLOY_SHA" ]]
|
||||
path=/
|
||||
[[ $name != canino_backend_stage ]] || path=/api
|
||||
[[ $name != canino_backend_stage ]] || path='/api/blogs?page=1&limit=1'
|
||||
ready=false
|
||||
for attempt in {1..12}; do
|
||||
[[ $(timeout --foreground --kill-after=2s 10 docker inspect -f '{{.State.Running}} {{.RestartCount}}' "$name") == 'true 0' ]] || { printf 'Container stopped or restarted: %s\n' "$name" >&2; exit 1; }
|
||||
if timeout --foreground --kill-after=2s 10 docker exec "$name" node -e '
|
||||
const http = require("http");
|
||||
const req = http.get({host: "127.0.0.1", port: 3000, path: process.argv[1]}, res => {
|
||||
res.resume(); process.exit(res.statusCode === 200 ? 0 : 1);
|
||||
if (res.statusCode !== 200) { res.resume(); process.exit(1); }
|
||||
if (process.argv[1] === "/") { res.resume(); process.exit(0); }
|
||||
// Existing public DB-backed contract; one row, no new health endpoint.
|
||||
if (!(res.headers["content-type"] || "").includes("application/json")) process.exit(1);
|
||||
let body = "";
|
||||
res.setEncoding("utf8");
|
||||
res.on("data", chunk => {
|
||||
body += chunk;
|
||||
if (Buffer.byteLength(body) > 2 * 1024 * 1024) process.exit(1);
|
||||
});
|
||||
res.on("error", () => process.exit(1));
|
||||
res.on("end", () => {
|
||||
try {
|
||||
const {data, meta} = JSON.parse(body);
|
||||
const valid = Array.isArray(data) && data.length <= 1 && meta &&
|
||||
meta.page === 1 && meta.limit === 1 &&
|
||||
Number.isInteger(meta.total) && meta.total >= data.length &&
|
||||
Number.isInteger(meta.lastPage) && meta.lastPage >= 1;
|
||||
process.exit(valid ? 0 : 1);
|
||||
} catch { process.exit(1); }
|
||||
});
|
||||
});
|
||||
req.setTimeout(5000, () => req.destroy(new Error("readiness timeout")));
|
||||
req.on("error", () => process.exit(1));
|
||||
|
||||
Reference in new issue
Block a user