Skip to content

Commit

Permalink
Merge pull request #196 from kuzzleio/0.26.2-proposal
Browse files Browse the repository at this point in the history
Release 0.26.2
  • Loading branch information
rolljee committed Nov 20, 2023
2 parents 98f2cbb + af62126 commit 05e0832
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 167 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ npm install -g kourou
$ kourou COMMAND
running command...
$ kourou (-v|--version|version)
kourou/0.26.1 darwin-arm64 node-v18.17.1
kourou/0.26.2 darwin-arm64 node-v18.17.1
$ kourou --help [COMMAND]
USAGE
$ kourou COMMAND
Expand Down
2 changes: 1 addition & 1 deletion features/run-kuzzle-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mkdir -p /tmp/snapshots
chmod 777 -R /tmp/snapshots

# Launch the kuzzle stack
docker-compose -f features/docker/docker-compose.yml up -d
docker compose -f features/docker/docker-compose.yml up -d

echo "[$(date --rfc-3339 seconds)] - Starting Kuzzle..."
while ! curl -f -s -o /dev/null http://localhost:7512
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kourou",
"description": "The CLI that helps you manage your Kuzzle instances",
"version": "0.26.1",
"version": "0.26.2",
"author": "The Kuzzle Team <[email protected]>",
"bin": {
"kourou": "./bin/run"
Expand Down
23 changes: 8 additions & 15 deletions src/commands/app/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { kuzzleFlags } from "../../support/kuzzle";
import { Client } from "@elastic/elasticsearch";
import { execute } from "../../support/execute";
import _ from "lodash";
import { checkPrerequisites } from "../../support/docker/checkPrerequisites";

export default class AppDoctor extends Kommand {
static description = "Analyze a Kuzzle application";
Expand Down Expand Up @@ -50,7 +51,7 @@ export default class AppDoctor extends Kommand {
const suggestions = [];

const [nodeVersion, adminExists, anonymous] = await Promise.all([
this.sdk.query({ controller: "debug", action: "nodeVersion", }),
this.sdk.query({ controller: "debug", action: "nodeVersion", }),
this.sdk.server.adminExists({}),
this.sdk.security.getRole("anonymous")
]);
Expand All @@ -67,8 +68,7 @@ export default class AppDoctor extends Kommand {
} else {
this.logKo("No admin user exists");
suggestions.push(
`Create an admin user ${
anonymousNotRestricted ? "and restrict anonymous role " : ""
`Create an admin user ${anonymousNotRestricted ? "and restrict anonymous role " : ""
}with
kourou security:createFirstAdmin '{
credentials: {
Expand Down Expand Up @@ -216,20 +216,13 @@ export default class AppDoctor extends Kommand {
}

this.log("Docker checks");
try {
const docov = await execute("docker-compose", "-v");
const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
if (matches === null || matches.length === 0) {
this.logKo("Docker Version cannot be found");
} else {
this.logOk(`Docker Compose Version: ${matches[1]}`);
}
} catch (error: any) {
this.logKo("Docker Compose cannot be found");
suggestions.push("Install Docker Compose with 'npm run install:docker'");
const result = await checkPrerequisites(this);

if (!result) {
suggestions.push("Install Docker and the Compose plugin");
}

this.log(`----------------- DoKtor finish his job ! -----------------`);
this.log(`----------------- DoKtor finished its job ! -----------------`);
this.log(`He suggest you to check the following points:`);
for (const suggestion of suggestions) {
this.logInfo(" => " + suggestion);
Expand Down
68 changes: 8 additions & 60 deletions src/commands/app/start-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import path from "path";

import { flags } from "@oclif/command";
import chalk from "chalk";
import Listr from "listr";

import emoji from "node-emoji";

import { Kommand } from "../../common";
import { execute } from "../../support/execute";

const MIN_DOCO_VERSION = "1.12.0";
import { checkPrerequisites } from "../../support/docker/checkPrerequisites";

const kuzzleServicesFile = `
version: '3'
Expand Down Expand Up @@ -48,7 +47,7 @@ export default class AppStartServices extends Kommand {
const docoFilename = path.join(this.kourouDir, "kuzzle-services.yml");

const successfullCheck = this.flags.check
? await this.checkPrerequisites()
? await checkPrerequisites(this)
: true;

if (this.flags.check && successfullCheck) {
Expand All @@ -64,22 +63,22 @@ export default class AppStartServices extends Kommand {
}

this.log(
chalk.grey(`\nWriting docker-compose file to ${docoFilename}...\n`)
chalk.grey(`\nWriting the Docker Compose file to ${docoFilename}...\n`)
);

writeFileSync(docoFilename, kuzzleServicesFile);

// clean up
await execute("docker-compose", "-f", docoFilename, "down");
await execute("docker", "compose", "-f", docoFilename, "down");

try {
await execute("docker-compose", "-f", docoFilename, "up", "-d");
await execute("docker", "compose", "-f", docoFilename, "up", "-d");

this.logOk(
"Elasticsearch and Redis are booting in the background right now."
);
this.log(chalk.grey("\nTo watch the logs, run"));
this.log(chalk.blue.bold(` docker-compose -f ${docoFilename} logs -f\n`));
this.log(chalk.blue.bold(` docker compose -f ${docoFilename} logs -f\n`));
this.log(` Elasticsearch port: ${chalk.bold("9200")}`);
this.log(` Redis port: ${chalk.bold("6379")}`);
} catch (error: any) {
Expand All @@ -88,58 +87,7 @@ export default class AppStartServices extends Kommand {
chalk.grey("If you want to investigate the problem, try running")
);

this.log(chalk.grey(` docker-compose -f ${docoFilename} up\n`));
}
}

public async checkPrerequisites(): Promise<boolean> {
this.log(chalk.grey("Checking prerequisites..."));

const checks: Listr = new Listr([
{
title: `docker-compose exists and the version is at least ${MIN_DOCO_VERSION}`,
task: async () => {
try {
const docov = await execute("docker-compose", "-v");
const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
if (matches === null) {
throw new Error(
"Unable to read docker-compose verson. This is weird."
);
}
const docoVersion = matches.length > 0 ? matches[1] : null;

if (docoVersion === null) {
throw new Error(
"Unable to read docker-compose version. This is weird."
);
}
try {
if (docoVersion < MIN_DOCO_VERSION) {
throw new Error(
`The detected version of docker-compose (${docoVersion}) is not recent enough (${MIN_DOCO_VERSION})`
);
}
} catch (error: any) {
throw new Error(error);
}
} catch (error: any) {
throw new Error(
"No docker-compose found. Are you sure docker-compose is installed?"
);
}
},
},
]);

try {
await checks.run();

return true;
} catch (error: any) {
this.logKo(error.message);

return false;
this.log(chalk.grey(` docker compose -f ${docoFilename} up\n`));
}
}
}
3 changes: 2 additions & 1 deletion src/commands/instance/kill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export class InstanceLogs extends Kommand {
stdout: true,
}
);
const instanceKill: ChildProcess = spawn("docker-compose", [
const instanceKill: ChildProcess = spawn("docker", [
"compose",
"-f",
docoFilename,
"-p",
Expand Down
99 changes: 13 additions & 86 deletions src/commands/instance/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import emoji from "node-emoji";

import { Kommand } from "../../common";
import { execute } from "../../support/execute";
import { checkPrerequisites } from "../../support/docker/checkPrerequisites";

const MIN_MAX_MAP_COUNT = 262144;

Check warning on line 16 in src/commands/instance/spawn.ts

View workflow job for this annotation

GitHub Actions / Lint

'MIN_MAX_MAP_COUNT' is assigned a value but never used
const MIN_DOCO_VERSION = "1.12.0";
const MIN_DOCO_VERSION = "2.0.0";

Check warning on line 17 in src/commands/instance/spawn.ts

View workflow job for this annotation

GitHub Actions / Lint

'MIN_DOCO_VERSION' is assigned a value but never used

const kuzzleStackV1 = (increment: number): string => `
version: '3'
Expand Down Expand Up @@ -112,7 +113,7 @@ export default class InstanceSpawn extends Kommand {
);

const successfullCheck = this.flags.check
? await this.checkPrerequisites()
? await checkPrerequisites(this)
: true;

if (this.flags.check && successfullCheck) {
Expand All @@ -127,23 +128,25 @@ export default class InstanceSpawn extends Kommand {
);
}

this.log(chalk.grey(`\nWriting docker-compose file to ${docoFilename}...`));
this.log(chalk.grey(`\nWriting docker compose file to ${docoFilename}...`));
writeFileSync(
docoFilename,
this.generateDocoFile(this.flags.version, portIndex)
);

// clean up
await execute(
"docker-compose",
"docker",
"compose",
"-f",
docoFilename,
"-p",
`stack-${portIndex}`,
"down"
);

const doco: ChildProcess = spawn("docker-compose", [
const doco: ChildProcess = spawn("docker", [
"compose",
"-f",
docoFilename,
"-p",
Expand All @@ -153,8 +156,7 @@ export default class InstanceSpawn extends Kommand {
]);

cli.action.start(
` ${emoji.get("rocket")} Kuzzle version ${
this.flags.version
` ${emoji.get("rocket")} Kuzzle version ${this.flags.version
} is launching`,
undefined,
{
Expand All @@ -173,7 +175,7 @@ export default class InstanceSpawn extends Kommand {
this.log(chalk.grey("To watch the logs, run"));
this.log(
chalk.grey(
` docker-compose -f ${docoFilename} -p stack-${portIndex} logs -f\n`
` docker compose -f ${docoFilename} -p stack-${portIndex} logs -f\n`
)
);
this.log(` Kuzzle port: ${7512 + portIndex}`);
Expand All @@ -183,97 +185,22 @@ export default class InstanceSpawn extends Kommand {
} else {
cli.action.stop(
chalk.red(
` Something went wrong: docker-compose exited with ${docoCode}`
` Something went wrong: docker compose exited with ${docoCode}`
)
);
this.log(
chalk.grey("If you want to investigate the problem, try running")
);
this.log(
chalk.grey(
` docker-compose -f ${docoFilename} -p stack-${portIndex} up\n`
` docker compose -f ${docoFilename} -p stack-${portIndex} up\n`
)
);
throw new Error("docker-compose exited witn non-zero status");
throw new Error("docker compose exited with a non-zero status");
}
});
}

public async checkPrerequisites(): Promise<boolean> {
this.log(chalk.grey("Checking prerequisites..."));
const checks: Listr = new Listr([
{
title: `docker-compose exists and the version is at least ${MIN_DOCO_VERSION}`,
task: async () => {
try {
const docov = await execute("docker-compose", "-v");
const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
if (matches === null) {
throw new Error(
"Unable to read docker-compose verson. This is weird."
);
}
const docoVersion = matches.length > 0 ? matches[1] : null;

if (docoVersion === null) {
throw new Error(
"Unable to read docker-compose version. This is weird."
);
}
try {
if (docoVersion < MIN_DOCO_VERSION) {
throw new Error(
`The detected version of docker-compose (${docoVersion}) is not recent enough (${MIN_DOCO_VERSION})`
);
}
} catch (error: any) {
throw new Error(error);
}
} catch (error: any) {
throw new Error(
"No docker-compose found. Are you sure docker-compose is installed?"
);
}
},
},
{
title: `vm.max_map_count is greater than ${MIN_MAX_MAP_COUNT}`,
task: async () => {
try {
const sysctl = await execute(
"/sbin/sysctl",
"-n",
"vm.max_map_count"
);

if (sysctl.exitCode !== 0) {
throw new Error("Something went wrong checking vm.max_map_count");
}

const value: number = parseInt(sysctl.stdout, 10);
if (value < MIN_MAX_MAP_COUNT) {
throw new Error(
`vm.max_map_count must be at least ${MIN_MAX_MAP_COUNT} (found ${value})`
);
}
} catch (error: any) {
throw new Error(
`Something went wrong checking vm.max_map_count: ${error.message}`
);
}
},
},
]);

try {
await checks.run();
return true;
} catch (error: any) {
this.logKo(error.message);
return false;
}
}

private generateDocoFile(kuzzleMajor: string, portIndex: number): string {
if (kuzzleMajor === "1") {
return kuzzleStackV1(portIndex);
Expand Down
Loading

0 comments on commit 05e0832

Please sign in to comment.