Skip to content

Commit

Permalink
Merge branch 'develop' into bandhan-majumder/issue-2538-version-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bandhan-majumder authored Dec 20, 2024
2 parents 45685b6 + 0ca595e commit 5ed433b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
51 changes: 41 additions & 10 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from "fs";
import inquirer from "inquirer";
import path from "path";
import type { ExecException } from "child_process";
import { exec, spawn } from "child_process";
import { exec, spawn, execSync } from "child_process";
import { MongoClient } from "mongodb";
import { MAXIMUM_IMAGE_SIZE_LIMIT_KB } from "./src/constants";
import {
Expand Down Expand Up @@ -466,6 +466,25 @@ export async function mongoDB(): Promise<void> {
For Docker setup
*/

function getDockerComposeCommand(): { command: string; args: string[] } {
let dockerComposeCmd = "docker-compose"; // Default to v1
let args = ["-f", "docker-compose.dev.yaml", "up", "--build", "-d"];

try {
// Test if 'docker compose' works (v2)
execSync("docker compose version", { stdio: "ignore" });
dockerComposeCmd = "docker";
args = ["compose", ...args]; // Prefix 'compose' for v2
} catch (error) {
console.log(error);
dockerComposeCmd =
process.platform === "win32" ? "docker-compose.exe" : "docker-compose";
}

return { command: dockerComposeCmd, args };
}

const DOCKER_COMPOSE_TIMEOUT_MS = 300000;
async function runDockerComposeWithLogs(): Promise<void> {
// Check if Docker daemon is running
try {
Expand All @@ -479,35 +498,47 @@ async function runDockerComposeWithLogs(): Promise<void> {
dockerCheck.on("close", (code) =>
code === 0
? resolve(null)
: reject(new Error("Docker daemon not running")),
: reject(
new Error(
"Docker daemon not running. Please ensure Docker Desktop is running and try again.",
),
),
);
});
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(
`Docker daemon is not running. Please start Docker and try again. Details: ${errorMessage}`,
`Docker daemon check failed. Please ensure:
1. Docker Desktop is installed and running
2. You have necessary permissions
3. Docker service is healthy
Details: ${errorMessage}`,
);
}

return new Promise((resolve, reject) => {
const { command, args } = getDockerComposeCommand();
let isCompleted = false;

const dockerCompose = spawn(command, args, { stdio: "inherit" });

const timeout = setTimeout(() => {
if (isCompleted) return;
dockerCompose.kill();
reject(new Error("Docker compose operation timed out after 5 minutes"));
}, 300000);

const dockerCompose = spawn(
process.platform === "win32" ? "docker-compose.exe" : "docker-compose",
["-f", "docker-compose.dev.yaml", "up", "--build", "-d"],
{ stdio: "inherit" },
);
}, DOCKER_COMPOSE_TIMEOUT_MS);

dockerCompose.on("error", (error) => {
if (isCompleted) return;
isCompleted = true;
clearTimeout(timeout);
console.error("Error running docker-compose:", error);
reject(error);
});

dockerCompose.on("close", (code) => {
if (isCompleted) return;
isCompleted = true;
clearTimeout(timeout);
if (code === 0) {
console.log("Docker Compose completed successfully.");
Expand Down
4 changes: 2 additions & 2 deletions src/typeDefs/unions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "graphql-tag";
// import { gql } from "graphql-tag";

// Place fields alphabetically to ensure easier lookup and navigation.
export const unions = gql``;
// export const unions = gql``;
3 changes: 2 additions & 1 deletion tests/resolvers/Query/getVolunteerRanks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ describe("resolvers -> Query -> getVolunteerRanks", () => {
},
{},
)) as unknown as VolunteerRank[];
expect(volunteerRanks[0].hoursVolunteered).toEqual(2);

expect(volunteerRanks[0].hoursVolunteered).toEqual(6);
expect(volunteerRanks[0].user._id).toEqual(testUser1?._id);
expect(volunteerRanks[0].rank).toEqual(1);
});
Expand Down

0 comments on commit 5ed433b

Please sign in to comment.