Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated setup.ts to support docker compose v2 and pass npm run typecheck #2770

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added minio.deb
Binary file not shown.
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``;
4 changes: 3 additions & 1 deletion tests/resolvers/Query/getVolunteerRanks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ describe("resolvers -> Query -> getVolunteerRanks", () => {
},
{},
)) as unknown as VolunteerRank[];
expect(volunteerRanks[0].hoursVolunteered).toEqual(2);

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