Skip to content

Commit

Permalink
fix: docker and docker compose error in doctor sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
omidasadpour authored and endersonmaia committed Apr 30, 2024
1 parent 3b75308 commit 9ebc7a4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-llamas-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sunodo/cli": patch
---

fixed checking docker and docker compose in sunodo doctor
74 changes: 51 additions & 23 deletions apps/cli/src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ export default class DoctorCommand extends BaseCommand<typeof DoctorCommand> {
private static MINIMUM_DOCKER_VERSION = "23.0.0"; // Replace with our minimum required Docker version
private static MINIMUM_DOCKER_COMPOSE_VERSION = "2.21.0"; // Replace with our minimum required Docker Compose version

private static async checkDockerVersion(): Promise<string> {
const { stdout } = await execa("docker", [
"version",
"--format",
"{{json .Client.Version}}",
]);
return JSON.parse(stdout);
}

private static async checkDockerComposeVersion(): Promise<string> {
const { stdout } = await execa("docker", [
"compose",
"version",
"--short",
]);
return stdout;
}

private static isDockerVersionValid(version: string): boolean {
return semver.gte(version, DoctorCommand.MINIMUM_DOCKER_VERSION);
}
Expand All @@ -28,33 +46,43 @@ export default class DoctorCommand extends BaseCommand<typeof DoctorCommand> {

public async run() {
try {
// Check Docker version
const { stdout: dockerVersionOutput } = await execa("docker", [
"version",
"--format",
"{{json .Client.Version}}",
]);
const dockerVersion = JSON.parse(dockerVersionOutput);
try {
const dockerVersion = await DoctorCommand.checkDockerVersion();

if (!DoctorCommand.isDockerVersionValid(dockerVersion)) {
throw new Error(
`Unsupported Docker version. Minimum required version is ${DoctorCommand.MINIMUM_DOCKER_VERSION}. Installed version is ${dockerVersion}.`,
);
// Check Docker version
if (!DoctorCommand.isDockerVersionValid(dockerVersion)) {
throw new Error(
`Unsupported Docker version. Minimum required version is ${DoctorCommand.MINIMUM_DOCKER_VERSION}. Installed version is ${dockerVersion}.`,
);
}
} catch (error: unknown) {
if (error instanceof Error) {
this.error(
"Docker is required but not installed or the command execution failed. Please refer to the Docker documentation for installation instructions: https://docs.docker.com/get-docker/",
);
}
}

// Check Docker Compose version
const { stdout: dockerComposeVersionOutput } = await execa(
"docker",
["compose", "version", "--short"],
);
const dockerComposeVersion = dockerComposeVersionOutput.trim();
try {
const dockerComposeVersion =
await DoctorCommand.checkDockerComposeVersion();

if (
!DoctorCommand.isDockerComposeVersionValid(dockerComposeVersion)
) {
throw new Error(
`Unsupported Docker Compose version. Minimum required version is ${DoctorCommand.MINIMUM_DOCKER_COMPOSE_VERSION}. Installed version is ${dockerComposeVersion}.`,
);
// Check if the Docker Compose version is valid
if (
!DoctorCommand.isDockerComposeVersionValid(
dockerComposeVersion,
)
) {
throw new Error(
`Unsupported Docker Compose version. Minimum required version is ${DoctorCommand.MINIMUM_DOCKER_COMPOSE_VERSION}. Installed version is ${dockerComposeVersion}.`,
);
}
} catch (error: unknown) {
if (error instanceof Error) {
this.error(
"Docker Compose is required but not installed or the command execution failed. Please refer to the Docker Compose documentation for installation instructions: https://docs.docker.com/compose/install/",
);
}
}

// Check Docker Buildx version and riscv64 support
Expand Down

0 comments on commit 9ebc7a4

Please sign in to comment.