Skip to content

Commit

Permalink
refactor: optimize docker healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Mar 18, 2024
1 parent a810890 commit 77f7506
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
10 changes: 2 additions & 8 deletions src/env/env.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const { spawn, exec } = require("promisify-child-process");

const {
print,
printError,
ensureNodeAndCompilerAvailable,
} = require("../utils/utils");
const { print, printError } = require("../utils/utils");

let dockerComposeCmd = "docker compose";

Expand Down Expand Up @@ -104,9 +100,7 @@ async function startEnv(option) {

await getDockerCompose();
await exec(`${versionTags} ${dockerComposeCmd} pull`);
await exec(`${versionTags} ${dockerComposeCmd} up -d`);

await ensureNodeAndCompilerAvailable();
await exec(`${versionTags} ${dockerComposeCmd} up -d --wait`);

const isRunning = await isEnvRunning();
await printInfo(isRunning, true);
Expand Down
6 changes: 6 additions & 0 deletions src/init/next-artifacts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ services:
aeproject_node:
image: aeternity/aeternity:${NODE_TAG:-latest}-bundle
hostname: node
# TODO: remove after releasing https://github.com/aeternity/aeternity/pull/4292
healthcheck:
interval: 2s
environment:
AETERNITY_CONFIG: /home/aeternity/aeternity.yaml
AE__SYSTEM__CUSTOM_PREFUNDED_ACCS_FILE: "/home/aeternity/node/data/aecore/.genesis/accounts_test.json"
Expand All @@ -13,6 +16,9 @@ services:
aeproject_compiler:
image: aeternity/aesophia_http:${COMPILER_TAG:-latest}
hostname: compiler
# TODO: remove after releasing https://github.com/aeternity/aesophia_http/pull/133
healthcheck:
interval: 2s
ports:
- "3080:3080"

Expand Down
6 changes: 6 additions & 0 deletions src/init/update-artifacts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ services:
aeproject_node:
image: aeternity/aeternity:${NODE_TAG:-v6.12.0}-bundle
hostname: node
# TODO: remove after releasing https://github.com/aeternity/aeternity/pull/4292
healthcheck:
interval: 2s
environment:
AETERNITY_CONFIG: /home/aeternity/aeternity.yaml
AE__SYSTEM__CUSTOM_PREFUNDED_ACCS_FILE: "/home/aeternity/node/data/aecore/.genesis/accounts_test.json"
Expand All @@ -13,6 +16,9 @@ services:
aeproject_compiler:
image: aeternity/aesophia_http:${COMPILER_TAG:-v7.6.1}
hostname: compiler
# TODO: remove after releasing https://github.com/aeternity/aesophia_http/pull/133
healthcheck:
interval: 2s
ports:
- "3080:3080"

Expand Down
35 changes: 0 additions & 35 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
const http = require("http");
const config = require("../config/config.json");

// eslint-disable-next-line no-promise-executor-return
const pause = async (duration) =>
new Promise((resolve) => setTimeout(resolve, duration));

const ensureNodeAndCompilerAvailable = async (
interval = 100,
attempts = 1200,
) => {
// eslint-disable-next-line no-plusplus
for (let i = 0; i < attempts; i++) {
// eslint-disable-next-line no-await-in-loop
if (i !== 0) await pause(interval);
// eslint-disable-next-line no-await-in-loop
const nodeAvailable = await get("http://localhost:3001/v3/status")
.then(() => true)
.catch(() => false);
// eslint-disable-next-line no-await-in-loop
const compilerAvailable = await get("http://localhost:3080/version")
.then(() => true)
.catch(() => false);
if (nodeAvailable && compilerAvailable) return;
// eslint-disable-next-line no-console
if (i !== 0 && i % 50 === 0)
console.log(
"waiting for node and compiler to come up, node:",
nodeAvailable,
"compiler:",
compilerAvailable,
);
}

throw new Error("timed out waiting for node to come up");
};

const get = async (url) =>
new Promise((resolve, reject) => {
// eslint-disable-next-line consistent-return
Expand Down Expand Up @@ -84,6 +50,5 @@ module.exports = {
printError: console.error,
config,
getNetwork,
ensureNodeAndCompilerAvailable,
get,
};

0 comments on commit 77f7506

Please sign in to comment.